LNMP环境的安装

1、 使用官方仓库安装Nginx

[root@web01 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=0
enabled=1

安装Nginx

[root@web01 ~]# yum install nginx -y

2.安装php7.1

[root@web01 ~]# yum remove php-mysql-5.4 php php-fpm php-common
[root@web01 ~]# vim /etc/yum.repos.d/php.repo
[php]
name = php Repository
baseurl = http://us-east.repo.webtatic.com/yum/el7/x86_64/
gpgcheck = 0

[root@web01 ~]# yum -y install php71w php71w-cli php71w-common
php71w-devel php71w-embedded php71w-gd php71w-mcrypt
php71w-mbstring php71w-pdo php71w-xml php71w-fpm
php71w-mysqlnd php71w-opcache php71w-pecl-memcached
php71w-pecl-redis php71w-pecl-mongodb

3.安装Mariadb数据库

[root@web01 ~]# yum install mariadb-server mariadb -y

4.配置nginx与php集成,修改配置文件

[root@web01 conf.d]# cat php.conf
server {
listen 80;
server_name php.ljp.com;
root /code;

location / {
index index.php index.html;
}

location ~ .php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

5.重载NGINX并加入开机自启

[root@nginx conf.d]# systemctl start nginx
[root@nginx conf.d]# systemctl enable nginx

6.启动php-fpm,并加入开机自启

[root@web01 conf.d]# systemctl start php-fpm
[root@web01 conf.d]# systemctl enable php-fpm

7.准备一个php文件,测试nginx与php是否集成成功

[root@web01 conf.d]# cat /code/page.php

8.启动数据库并加入开机自启

[root@web01 conf.d]# systemctl start mariadb
[root@web01 conf.d]# systemctl enable mariadb

给数据库设置一个密码

[root@web01 conf.d]# mysqladmin password '123'

原文地址:https://www.cnblogs.com/longren/p/10991652.html