作為一個的勤雜工,近期因公司內(nèi)部信息化的需求省咨,給新進員工提供基礎的知識培訓和介紹肃弟,也為了給公司內(nèi)部建立一個溝通交流的平臺,百度找了開源的百科系統(tǒng)HDwiki和開源的問答系統(tǒng)Tipask問答系統(tǒng)零蓉,蛋痛的這兩套系統(tǒng)均是php+mysql開發(fā)笤受,作為一個有多年.net開發(fā)經(jīng)驗的老鳥,面對著這些無法下一步解決的系統(tǒng)部署敌蜂,心里一遍又一遍地感嘆微軟的好箩兽。
在windows server + IIS + php 7環(huán)境內(nèi)部署Tipask時出現(xiàn)了各種問題,面對著php.ini的配置一時也不知道如何入手章喉,然后切換到centos 7 + nginx + php5.6上汗贫。
在centos上安裝php身坐,我這邊采用的是Webtatic源,Webtatic上最新php版本為7.2芳绩,因HDwiki不支持最新的php 7.2,所以選擇了5.6版撞反。使用webtatic提供的源進行php的安裝非常簡單妥色,可參見官方安裝步驟。
#安裝Webtati的yum倉庫
yum install epel-release
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
#安裝php及插件
yum install php56w php56w-fpm php56w-opcache
#查詢php插件并安裝
yum search php56w
yum install 插件名稱
php安裝完成后遏片,配置nginx進行測試嘹害。
[root@localhost conf.d]# vi /etc/nginx/conf.d/default.conf
server {
listen 80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
# 默認頁增加index.php
index index.php index.html index.htm;
}
#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 html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;
# include fastcgi_params;
#}
#去掉location ~ \.php$配置節(jié)前面的#
location ~ \.php$ {
root html;
#php-fpm默認的監(jiān)聽端口為9000
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# 文件位置修改為/usr/share/nginx/html
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html$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;
#}
}
在/usr/share/nginx/html
文件夾下增加index.php
文件。文件內(nèi)容如下:
<?php
phpinfo()
?>
重啟nginx服務吮便,啟動php-fpm服務笔呀。
#重新載入nginx
nginx -s reload
#將php-fpm設置為開啟啟動
systemctl enable php-fpm.service
#啟動php-fpm服務
systemctl start php-fpm.service
在瀏覽器中訪問index.php頁面,出現(xiàn)下圖界面說明配置成功髓需。php-fpm默認監(jiān)聽的端口號為9000许师,如果我們想修改端口號或部署多個系統(tǒng)在不同的端口號時應該如何做呢?
1. 修改監(jiān)聽的端口
通過查看php-fpm的配置文件/etc/php-fpm.conf
可以看到include=/etc/php-fpm.d/*.conf
的配置僚匆,在/etc/php-fpm.d/
文件夾中存在www.conf
配置文件微渠,打開文件編輯listen=127.0.0.1:9000
,將端口號改為其他端口號咧擂,然后重啟php-fpm.service服務逞盆。重啟完后,修改nginx配置并重啟松申,即可生效云芦。
2. 部署多個系統(tǒng)在不同的端口號
經(jīng)檢查php-fpm的相關配置文件有:
/etc/php-fpm.conf
/etc/php-fpm.d/www.conf
/var/run/php-fpm/php-fpm.pid
/usr/lib/systemd/system/php-fpm.service
當需要部署多個系統(tǒng)在不同的端口時,可以復制上述4個文件贸桶,修改2中的監(jiān)聽端口號舅逸,修改4中的啟動項,使用-y 制定php-fpm啟動的配置文件即可皇筛。