centos7 lnmp搭建

第一步:安装nginx

添加centos yum源

sudo rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装nginx

sudo yum install nginx

启动nginx服务

sudo systemctl start nginx

浏览器输入localhost,如出现Nginx欢迎页面,nginx已经安装并正常运行

设置开机自动启动Nginx

sudo systemctl enable nginx.service

第二步:安装mysql

查看 

第三步:安装php

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

查看

yum search php71w

安装php及扩展

yum install php71w php71w-fpm php71w-cli php71w-common php71w-devel php71w-gd php71w-pdo php71w-mysql php71w-mbstring php71w-bcmath

开启服务

service php-fpm start

修改nginx配置

 vi /etc/nginx/conf.d/default.conf

内容为

server {
    listen       80;
    server_name  localhost;
    root   /www;
    index  index.html index.php;
    error_page   500 502 503 504  /50x.html;
 location ~ \.php$ {
        root /www;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
}

重启

sudo systemctl restart nginx

在www下新建个php文件测试

<?php
echo "aa";
phpinfo();

能够正常输出信息就配置好了

补充:

如果出现 403 forbidden,可能是SELinux设置为开启状态

查看selinux状态

/usr/sbin/sestatus

修改/etc/selinux/config的SELINUX

SELINUX=disabled

重启

reboot
posted @ 2016-05-11 18:08  慕尘  阅读(119)  评论(0编辑  收藏  举报