centos搭建LNMP环境

2017-08-06  本文已影响38人  IT教程

欢迎访问我的个人博客网站:http://www.yanmin99.com/

一、LNMP介绍

二、Nginx安装

sudo yum install nginx
service nginx start
```
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0 0.0.0.0:8989                0.0.0.0:*                   LISTEN      1415/python
tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      11295/nginx
```
sudo chkconfig nginx on
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# nginx -v
nginx version: nginx/1.12.1

三、MySQL安装

sudo yum install mysql-server
sudo /usr/bin/mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]
Remove anonymous users? [Y/n]
Remove test database and access to it? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]
mysql -uroot -p
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlp
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8989 0.0.0.0:* LISTEN 1415/python
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 11532/mysqld
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# mysql -V
mysql  Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline 5.1

四、PHP安装

sudo yum install php php-fpm php-mysql
sudo service php-fpm start
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# netstat -ntlp
 Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
 tcp        0      0 0.0.0.0:8989                0.0.0.0:*                   LISTEN      1415/python
 tcp        0      0 127.0.0.1:9000              0.0.0.0:*                   LISTEN      11642/php-fpm
sudo chkconfig php-fpm on

五、验证LNMP

server {
    listen 8000;
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/php;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

Nginx修改配置,需要重启sudo service nginx reload或者service nginx restart

<?php echo phpinfo(); ?>
//测试可以直接关闭防火墙
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# service iptables stop
iptables: Setting chains to policy ACCEPT: filter nat      [  OK  ]
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Unloading modules:                               [  OK  ]

//查看防火墙状态
[root@iZrj98p4hhys0y9fdxmcy4Z yanmin]# service iptables status
iptables: Firewall is not running.
上一篇下一篇

猜你喜欢

热点阅读