centos nginx整合php

如果你没有安装nginx,请参照centos 通过yum安装nginx

1. 安装php

yum install php php-mysql php-fpm

安装过程中经常会见到如下问题:
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18()(64bit)
2:postfix-2.10.1-6.el7.x86_64 有缺少的需求 libmysqlclient.so.18(libmysqlclient_18)(64bit)
解决方法:
把php-mysql换成php-mysqlnd
即执行

yum install php php-mysqlnd php-fpm

2. 配置php处理器

vim /etc/php.ini

查找cgi.fix_pathinfo
将 ;cgi.fix_pathinfo=1改为cgi.fix_pathinfo=0

3. 配置www.conf

vim /etc/php-fpm.d/www.conf
将
user = nobody
group = nobody
改为
user = nginx
group = nginx

前提是已经创建了nginx用户和nginx组。
如果没有创建,请参考:

# 添加nginx用户和用户组
groupadd -r nginx
useradd -r -g nginx nginx

4. 起动php-fpm

systemctl start php-fpm

5. 设置php-fpm开机启动

systemctl enable php-fpm

6. 配置nginx

打开/etc/nginx/conf.d/default.conf,如果不存在则创建 粘贴

server {
    listen 80;
    server_name www.twogether.cn;

    # note that these lines are originally from the "location /" block
    root /usr/share/nginx/html;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ =404;
    }
    error_page 404 /404.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
        root /usr/share/nginx/html;
    }

    location ~ .php$ {
        try_files $uri =404;
        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.conf;
    }
}

7. 重起nginx

systemctl restart nginx

8. 测试php

创建/usr/share/nginx/html/index.php

vim /usr/share/nginx/html/info.php

输入以下内容:


访问http://yourhost/index.php,正常情况下会出现:

centos nginx整合php_第1张图片
访问

你可能感兴趣的:(centos nginx整合php)