快速从LAMP 迁移 到 LNMP教程

前提

已经安装 LAMP 环境 

安装 nginx:

yum install -y nginx

安装 php-fpm:

yum install -y php-fpm

启动php-fpm

# centos 6.x
/etc/init.d/php-fpm start   
chkconfig --level 2345 php-fpm on  # 开机自启动

# centos 7.x
systemctl start php-fpm.service 

systemctl enable php-fpm.service  # 开机自启动
  

关闭httpd

# 关闭80端口
# centos 6.x
service httpd stop
systemctl stop httpd.service  

# 关闭开机自启动
# centos 6.x
chkconfig --level 2345 httpd off
# centos 7.x
systemctl disable httpd.service  

配置 nginx虚拟主机:

#vi /etc/nginx/conf.d/virtual.conf

server {
    listen 80; #监听端口号
    server_name www.nginxtest.com; #主机名称
    access_log /tmp/logs/bbb.entoscn.com_access.log combined;
    location / {
        index index.php index.html index.htm; #默认首页文件
        root /var/www/html/; #网站目录
    }

    location ~ .*\.php$ {
        fastcgi_pass 127.0.0.1:9000;# 9000是php-fpm的端口, 可以通过 netstat -tlnp 查看
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME /var/www/html$fastcgi_script_name; #解析php
        include fastcgi_params;#解析php
    }
}

nginx 启动

# centos 6.x
/etc/init.d/nginx start   

chkconfig --level 2345 nginx on

# centos 7.x
systemctl start nginx.service   

systemctl enable nginx.service   

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章