搭建过程如下
解决相关依赖关系
[root@LNMP ~]# yum install gcc gcc-c++ automake pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2-devel libpng-devel curl-devel numactl
关闭防火墙以及selinux
[root@LNMP ~]# systemctl stop firewalld
[root@LNMP ~]# systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@LNMP ~]# setenforce 0 //临时关闭selinux 永久关闭需修改配置文件
Nginx的安装
http://nginx.org/download/ Nginx各版本下载地址
[root@LNMP ~]# mkdir /lnmp //创建一个目录,用于存放LNMP环境所需的源码包
[root@LNMP ~]# cd /lnmp/
[root@LNMP lnmp]# wget http://nginx.org/download/nginx-1.16.0.tar.gz //根据自己的需求来进行下载
[root@LNMP lnmp]# tar -xf nginx-1.16.0.tar.gz //解压我们下载的源码包
[root@LNMP lnmp]# cd nginx-1.16.0/
[root@LNMP nginx-1.16.0]# useradd -s /sbin/nologin -M nginx //创建一个Nginx用户
[root@LNMP nginx-1.16.0]# ./configure --prefix=/usr/local/nginx --with-http_ssl_module
[root@LNMP nginx-1.16.0]# make && make install
修改配置文件使Nginx能够识别PHP文件
[root@LNMP ~]# vim /usr/local/nginx/conf/nginx.conf
3 user nginx nginx;
42 location / {
43 root html;
44 index index.php index.html index.htm;
45 }
64 location ~ \.php$ {
65 root html;
66 fastcgi_pass 127.0.0.1:9000;
67 fastcgi_index index.php;
68 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
69 include fastcgi_params;
70 }
#取消前面的注释并添加Nginx网站发布目录的路径即可
启动测试
[root@LNMP ~]# /usr/local/nginx/sbin/nginx
[root@LNMP ~]# ss -tan | grep 80
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
mysql的安装
https://dev.mysql.com/downloads/mysql/ 数据库版本的下载地址
[root@LNMP lnmp]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.18-linux-glibc2.12-x86_64.tar.xz //下载对应版本的数据库
[root@LNMP lnmp]# tar -xf mysql-8.0.13-linux-glibc2.12-x86_64.tar.xz -C /usr/local/mysql //解压到指定的目录中
[root@LNMP lnmp]# cd /usr/local/mysql/ //进入mysql目录中
[root@LNMP mysql]# mkdir data //创建一个用于存放mysql数据的目录
[root@LNMP mysql]# useradd -s /sbin/nologin -M mysql //创建mysql用户
[root@LNMP mysql]# chown -R mysql:mysql /usr/local/mysql/ //进行赋权操作
[root@LNMP mysql]# bin/mysqld --initialize --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data //初始化数据库
2020-09-23T01:46:54.902101Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.13) initializing of server in progress as process 24144
2020-09-23T01:47:02.724606Z 5 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: **OI5k:4eGA;py**初始化生成的密码
[root@LNMP support-files]# cp -a mysql.server /etc/init.d/ //复制数据库启动脚本到/etc/init.d/目录下
[root@LNMP support-files]# chmod a+x /etc/init.d/mysql.server //赋予它执行的权限
[root@LNMP ~]# /etc/init.d/mysql.server start //启动数据库
Starting MySQL.Logging to '/usr/local/mysql/data/LNMP.err'.
... SUCCESS!
[root@LNMP ~]# ss -tan | grep 3306 //查看3306端口
LISTEN 0 70 *:33060 *:*
LISTEN 0 128 *:3306 *:*
编辑环境变量配置文件
[root@LNMP ~]# vim .bash_profile //这个文件存在家目录之下
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin
[root@LNMP ~]# source .bash_profile //生效配置文件
[root@LNMP ~]# mysql -uroot -p //初次启动如果遇到如下问题请执行 ln -s /usr/lib64/libtinfo.so.6.1 /usr/lib64/libtinfo.so.5 然后在启动即可
mysql: error while loading shared libraries: libtinfo.so.5: cannot open shared object file: No such file or directory
登录测试
[root@LNMP ~]# mysql -uroot -p
Enter password: 初始密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.13
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by 'jw123'; //初次登录需要修改密码
Query OK, 0 rows affected (0.02 sec)
PHP的安装
https://www.php.net/distributions php各版本的下载地址
[root@LNMP lnmp]# wget https://www.php.net/distributions/php-7.3.5.tar.gz //下载PHP的源码包
[root@LNMP lnmp]# tar -xf php-7.3.5.tar.gz //解压源码包
[root@LNMP lnmp]# cd php-7.3.5/
[root@LNMP php-7.3.5]# ./configure --prefix=/usr/local/php --enable-fpm --with-mysqli --with-curl --with-pdo_mysql --with-pdo_sqlite --enable-mysqlnd --enable-mbstring --with-gd //执行编译操作
[root@LNMP php-7.3.5]# make && make install //时间可能会有点久
[root@LNMP php-7.3.5]# cp php.ini-development /usr/local/php/lib/php.ini //复制当前目录中的这个到php安装目录中作为PHP的主配置文件
[root@LNMP php-7.3.5]# cd /usr/local/php/etc/
[root@LNMP etc]# mv php-fpm.conf.default php-fpm.conf
[root@LNMP etc]# mv php-fpm.d/www.conf.default php-fpm.d/www.conf
[root@LNMP etc]# vim /usr/local/php/lib/php.ini //修改这个文件
790 ;cgi.fix_pathinfo=0 //参数修改为0即可
然后启动php 即可
[root@LNMP php-7.3.5]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //复制PHP的启动脚本
[root@LNMP php-7.3.5]# chmod a+x /etc/init.d/php-fpm //赋予执行权限
[root@LNMP php-7.3.5]# chkconfig php-fpm on //启动
[root@LNMP php-7.3.5]# /etc/init.d/php-fpm start //执行启动即可
Starting php-fpm done
[root@LNMP php-7.3.5]# ss -tan | grep 9000
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
最后再次查看各个服务对应的端口是否正常运行
[root@LNMP ~]# ss -tan | grep 80
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
[root@LNMP ~]# ss -tan | grep 3306
LISTEN 0 70 *:33060 *:*
LISTEN 0 128 *:3306 *:*
[root@LNMP ~]# ps -ef | grep php-fpm
root 20228 1 0 11:22 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
测试Nginx能否识别PHP文件
[root@LNMP ~]# echo "<?php phpinfo(); ?>" >> /usr/local/nginx/html/index.php
浏览器访问测试