蒼天家 本家
nginx + php-fpm安裝步驟 2015-10-05
利用rpm -Uvh抓到nginx的檔案
# rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安裝nginx
# yum install nginx

啟動nginx
# systemctl start nginx
# systemctl eable nginx

安裝php-fpm
# yum install php-fpm

啟動php-fpm
# systemctl start php-fpm
# systemctl eable php-fpm

修改nginx的default.conf
# vi /etc/nginx/conf.d/default.conf

=== default.conf ===
server {
listen 80;
server_name localhost;

#charset koi8-r;
#access_log /var/log/nginx/log/host.access.log main;

location / {
root /var/www/html/;
index default.html default.php;
try_files $uri $uri/ =404;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root /var/www/html/;
try_files $uri =404;
fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_index default.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
=== default.conf ===


修改php.ini
# vi /etc/php.ini
cgi.fix_pathinfo = 1 → cgi.fix_pathinfo = 0

修改www.conf
# vi /etc/php-fpm.d/www.conf
listen = 127.0.0.1:9000 → listen = /var/run/php-fpm/php-fpm.sock
user = apache → user = nginx
group = apache → group = nginx

建立php-fpm.sock 並將所有者改為nginx
# touch /var/run/php-fpm/php-fpm.sock
# chown nginx:nginx php-fpm.sock

重新啟動php-fpm與nginx
# systemctl restart php-fpm
# systemctl restart nginx
關於我

隨手用部落格

紀錄平時學習用到的東西

考慮想重改版

Github 自學倉庫

我的 Github 帳號

PHP開發

公司: 原生PHP

個人: Slim -> Flight