Centos7安装PHP7+mysql5.7+nginx1.12.2

安装PHP7 安装mysql5.7 安装nginx1.12.2 Centos7安装LNMP

服务器:阿里云ECS

系统:centos7.4 64位

先更新yum源:

rpm -Uvh https://dl.Fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm


34/e81115d16afb4ef38c41454f163cc8.png

然后安装Nginx:

yum -y install nginx

ae/90a9c2ec52675ab87f7cbe8a8889ae.png

b4/81ba25d1e04d282f950bf516cf50a4.png

c3/65a69cab76123425e6971ad4dea2d5.png

f9/b7844f93868e21c53f2bad195de9f3.png

e9/28d1072679c3c92dc1511710b2e4dd.png


Nginx安装成功后,安装MySQL:

yum -y install mysql-community-server

19/7be6153804dd10d9715b3085bd1c19.png

15/484a0d04ea5d9c4f8b00ab6827e39e.png

MySQL安装好后,安装PHP7:

yum -y install php70w-devel php70w.x86_64 php70w-cli.x86_64 php70w-common.x86_64 php70w-gd.x86_64 php70w-ldap.x86_64 php70w-mbstring.x86_64 php70w-mcrypt.x86_64  php70w-pdo.x86_64   php70w-mysqlnd  php70w-fpm php70w-opcache

f0/d914247f2901a5c2b0e10930e132d2.png

bb/a5e0c1ed1245f0bab730b7b6c0e32e.png

bd/4f5d877026262d1fe1c09c00c6652a.png

6e/921259eb51f17f4adda3d4ebdb8847.png

04/3d126858c607583ebc279efdaf9dd3.png

这样,环境基本安装完毕。接下来是配置:

启动MySQL

systemctl start mysqld

设置开机启动:

systemctl enable mysqld

MySQL安装的时候会生成一个默认的密码,查看默认密码:

grep 'temporary password' /var/log/mysqld.log 

b3/b83fce3d33452ddab2fd8d746e99d3.png

用这个默认密码登录MySQL,修改root密码为自己的密码:

mysql -uroot -p


mysql> set password for 'root'@'localhost'=password('123abc'); 

d4/253f309a98f637c604636881003d34.png

修改完成后重启MySQL。

25/949f46c974a181e44ebad25ae98257.png

默认配置文件路径:

配置文件:/etc/my.cnf

日志文件:/var/log/mysqld.log

服务启动脚本:/usr/lib/systemd/system/mysqld.service

socket 文件:/var/run/mysqld/mysqld.pid


接下来是Nginx的配置,先查看防火墙:

systemctl status firewalld

如果显示 active (running),则需要调整防火墙规则的配置(请自行百度[嘻嘻])。

然后在/etc/nginx/conf.d/里面创建自己的站点解析配置:

server {

    listen       80;

    server_name www.abc.com;

    root /home/www/abc;

    index index.php index.html index.htm;

    location / {

             if (!-e $request_filename) {

                rewrite ^/(.*)$ /index.php?$1 last;#去除url中的index.php

             }

     }

     location ~ \.php$ {

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;

        include        fastcgi_params;

      }

}

如果担心写的不对,可以用

 /usr/sbin/nginx -t

来检查Nginx配置是否正确。

保存后重启Nginx,然后启动PHP-FPM,设置PHP-FPM、Nginx开机启动:

systemctl enable nginx

2d/c95633c59c4d80e87db6ff38084aa1.png

访问自己的网址,如果出现一下页面,说明环境搭建成功:

ba/c3aaff8e52d936fab26b6a4245f70e.png

然后在网址根目录里新建一个info.php,里面写phpinfo();,之后再访问:域名/info.php如果出现一下页面,说明PHP-FPM没有问题:

30/1d99ce7f04c879784f9cc01e19370c.png

至此,简单的LNMP环境搭建成功!


参考:

https://blog.csdn.net/lovemyself196221/article/details/79491602

https://www.cnblogs.com/phpshen/p/6222935.html




评论