在CentOS7上使用yum安装nginx(附带php)

创建Nginx存储库。

目前看来,这似乎只有在mainlaine中出现。1.7.3 是截至到2014年7月15日的最新版本。

[root@centos7 ~]# vi /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
#baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=0
enabled=0

安装、运行和注册nginx。

[root@centos7 ~]# yum --enablerepo=nginx install nginx
[root@centos7 ~]# systemctl start nginx
[root@centos7 ~]# systemctl enable nginx

安装php-fpm

[root@centos7 ~]# yum install php-fpm php-mbstring

将nginx配置文件更改为使php-fpm运行的设置

[root@centos7 ~]# vi /etc/nginx/conf.d/default.conf
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;
    }
[root@centos7 ~]# systemctl restart nginx
[root@centos7 ~]# echo '<?php phpinfo();' > /usr/share/nginx/html/info.php
[root@centos7 ~]# systemctl start php-fpm
[root@centos7 ~]# systemctl enable php-fpm
[root@centos7 ~]# curl 'http://localhost/info.php'

CentOS7改用firewalld后,外部访问时的额外设置

[root@centos7 ~]# systemctl stop firewalld