初学LNMP--LNMP手动搭建

LNMP

LNMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写LNMP==Linux+Nginx+Mysql+PHP的结构体系。

实验环境准备:
机器软件版本系统
nginxnginx/1.15.0Centos7
mysql8.0.15 MySQL Community Server - GPLCentos7
phpphp-7.4.8Centos7
实验前环境处理
  1. 同步时间
ntpdate
  1. 关闭防火墙
[root@lnmp-nginx nginx]# systemctl stop firewalld
[root@lnmp-nginx nginx]# systemctl disable firewalld

#使用sed替换,永久修改,当前不生效
[root@lnmp-nginx nginx]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/'  /etc/selinux/config         
[root@lnmp-nginx nginx]# cat /etc/selinux/config 

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

[root@lnmp-nginx ~]# setenforce 0        #临时生效1打开0关闭
[root@lnmp-nginx ~]# getenforce           #查看当前selinux状态
Permissive

实验开始:

  1. php配置: 配置php-fpm模块
配置  /usr/local/php7/etc/php-fpm.conf
(将之前默认文件备份)
[root@father ~]# cd /usr/local/php7/etc/
[root@father etc]# ls
pear.conf  php-fpm.conf.default  php-fpm.d  php.ini
[root@father etc]# cd php-fpm.d/
[root@father php-fpm.d]# ls
www.conf.default

[root@father etc]# cp php-fpm.conf.default php-fpm.conf
[root@father etc]# cd php-fpm.d/
[root@father php-fpm.d]# cp www.conf.default www.conf

[root@lnmp-php etc]# pwd
/usr/local/php7/etc
[root@lnmp-php etc]# vim p
pear.conf             php-fpm.conf          php-fpm.conf.default  php-fpm.d/            php.ini
#修改配置文件
[root@lnmp-php etc]# vim php-fpm.conf          
pm.max_children = 50             #最多同时提供50个进程提供50个并发服务
pm.start_servers = 5              #启动时启动5个进程
pm.min_spare_servers = 2          #最小空闲进程数
pm.max_spare_servers = 8          #最大空闲进程数

[root@lnmp-php php-fpm.d]# cat www.conf |grep -iv "^\;"
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic

pm.max_children = 5

pm.start_servers = 2

pm.min_spare_servers = 1

pm.max_spare_servers = 3
#php启动
[root@lnmp-php sbin]# pwd
/usr/local/php7/sbin

[root@lnmp-php sbin]# ./php-fpm 
[root@lnmp-php sbin]# ps -ef |grep php
root      15142      1 16 17:36 ?        00:00:00 php-fpm: master process (/usr/local/php7/etc/php-fpm.conf)
nginx     15143  15142  5 17:36 ?        00:00:00 php-fpm: pool www
nginx     15144  15142  9 17:36 ?        00:00:00 php-fpm: pool www
nginx     15145  15142  5 17:36 ?        00:00:00 php-fpm: pool www
nginx     15146  15142 15 17:36 ?        00:00:00 php-fpm: pool www
nginx     15147  15142 16 17:36 ?        00:00:00 php-fpm: pool www
root      15149  15000  0 17:36 pts/1    00:00:00 grep --color=auto php
  1. nginx配置:
  • 修改配置文件
[root@lnmp-nginx nginx]# cat /etc/nginx/nginx.conf
user nginx;
pid /var/run/nginx.pid;
error_log  logs/error.log;
events {
    worker_connections 1024;
    }

http {
    access_log off;
    client_max_body_size 128M;
    include /etc/nginx/conf.d/*.conf;
    default_type application/octet-stream;
    log_format main '$remote_addr - $remote_user [$time_local] "$request"';
 

server {
    listen 80;
    server_name 192.168.126.137;
    
    location / {
		root html;
		index index.php index.html index.htm ;
               }

    location ~ \.php$ {
		root /www;
		fastcgi_pass 127.0.0.1:9000;
		fastcgi_index index.php;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
		include fastcgi_params;
		}
    }
}
  • 启动查看进程
[root@lnmp-nginx nginx]# ps -ef |grep nginx
root       8294      1  0 16:31 ?        00:00:00 nginx: master process /opt/data/nginx/sbin/nginx -c /opt/data/nginx/conf/nginx.conf
nginx      8295   8294  0 16:31 ?        00:00:00 nginx: worker process
root       8342   8154  0 17:39 pts/1    00:00:00 grep --color=auto nginx
  • 测试nginx和php是否相同(网页访问nginx结点,是否会访问到到php上文件)

    162.168.126.137/index.php

3. 配置mysql:
  • 创建一个测试账号
mysql> create user "superadmin"@"%" identified with mysql_native_password by "WLF13@me"
    -> ;          #由于使用mysql8版本,为了避免兼容问题,将密码认证插件改为mysql_native_password 
Query OK, 0 rows affected (0.09 sec)

mysql> select user,host,plugin from mysql.user;
+------------------+-----------+-----------------------+
| user             | host      | plugin                |
+------------------+-----------+-----------------------+
| superadmin       | %         | mysql_native_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session    | localhost | caching_sha2_password |
| mysql.sys        | localhost | caching_sha2_password |
| root             | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
  • 创建一个数据库
mysql> create database memcacher;
Query OK, 1 row affected (0.09 sec)

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| memcacher          |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
  1. 在php机器上安装配置PHP-mysql链接模块
  • 安装PHP-mysql链接模块
[root@lnmp-php ext]# pwd
/usr/local/src/php-7.2.0/ext
[root@lnmp-php ext]# cd mysqli/
[root@lnmp-php mysqli]# /usr/local/php7/bin/phpize 
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
[root@lnmp-php mysqli]# ./configure \   #开始安装mysqlli

[root@lnmp-php mysqli]# echo $?
0
[root@lnmp-php mysqli]# make

[root@lnmp-php mysqli]# echo $?
0
[root@lnmp-php mysqli]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20170718/
Installing header files:          /usr/local/php7/include/php/

[root@lnmp-php mysqli]# echo $?
0
[root@lnmp-php ~]# cd /usr/local/php7/lib/php/extensions/no-debug-zts-20170718/
[root@lnmp-php no-debug-zts-20170718]# ls
mysqli.a  mysqli.so  opcache.a  opcache.so  pdo_mysql.a  pdo_mysql.so
[root@lnmp-php no-debug-zts-20170718]# cd /usr/local/src/php-7.2.0/ext/pdo  
[root@lnmp-php pdo]# cd /usr/local/src/php-7.2.0/ext/pdo_mysql/
[root@lnmp-php pdo_mysql]# /usr/local/php7/bin/phpize 
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718

#编译安装pdo_mysql
[root@lnmp-php pdo_mysql]# ./configure --with-php-config=/usr/local/php7/bin/php-config --with-pdo-mysql=mysqlnd
[root@lnmp-php pdo_mysql]# echo $?
0
[root@lnmp-php pdo_mysql]# make
[root@lnmp-php pdo_mysql]# echo $?
0
[root@lnmp-php pdo_mysql]# make install
Installing shared extensions:     /usr/local/php7/lib/php/extensions/no-debug-zts-20170718/
[root@lnmp-php pdo_mysql]# echo $
$
[root@lnmp-php pdo_mysql]# echo $?
0
  • 添加模块
  root@lnmp-php pdo_mysql]# cd /usr/local/src/php-7.2.0/
  [root@lnmp-php php-7.2.0]# cp php.ini-production /usr/local/php7/etc/php.ini
  cp:是否覆盖"/usr/local/php7/etc/php.ini"? y
  
  #去修改php.ini,指定模块
  [root@lnmp-php php-7.2.0]# cd /usr/local/php7/etc/
  [root@lnmp-php etc]# ls
  pear.conf  php-fpm.conf  php-fpm.conf.default  php-fpm.d  php.ini
  [root@lnmp-php etc]# 
  [root@lnmp-php etc]# vim php.ini 
  extension_dir = "/usr/local/php7/lib/php/extensions/no-debug-zts-20170718"
  extension = mysqli.so
  extension = pdo_mysql.so
  
  #重启php
  service php-fpm restart
  1. 写一个测试文件进行测试,mysql结点是否正常连接。
[root@lnmp-php www]# cat index1.php 
<?php
$con = new mysqli('192.168.126.134','superadmin','WLF13@me','memcacher');
if(!$con)
 echo "faling...";
else
 echo "success connect mysql\n";
?>

在这里插入图片描述

到此LNMP实验手动搭建结束。

评论 5 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:游动-白 设计师:我叫白小胖 返回首页

打赏作者

小萝卜112

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值