如果你沒有安裝nginx,請參照centos 通過yum安裝nginx
1. 安裝php
yum install php php-mysql php-fpm
安裝過程中經(jīng)常會見到如下問題:
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
即執(zhí)行
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
前提是已經(jīng)創(chuàng)建了nginx用戶和nginx組。
如果沒有創(chuàng)建马昙,請參考:
# 添加nginx用戶和用戶組
groupadd -r nginx
useradd -r -g nginx nginx
4. 起動php-fpm
systemctl start php-fpm
5. 設(shè)置php-fpm開機啟動
systemctl enable php-fpm
6. 配置nginx
打開/etc/nginx/conf.d/default.conf兴喂,如果不存在則創(chuàng)建 粘貼
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
創(chuàng)建/usr/share/nginx/html/index.php
vim /usr/share/nginx/html/info.php
輸入以下內(nèi)容:
<?php phpinfo(); ?>
訪問http://yourhost/index.php,正常情況下會出現(xiàn):