基於UDS模式的php-fpm的LAMP

環境

linux、apache、php-fpm linux、mariadb linux client
192.168.43.17 192.168.43.7 192.168.43.6
apache_php-fpm mariadb ab工具測試

配置 httpd 服務器

編譯安裝 httpd-2.4.41

創建用戶
[apache_php-fpm]#

useradd -r -s /sbin/login apache

配置文件
[apache_php-fpm]#

mkdir /app/httpd24/conf.d/
echo "IncludeOptional conf.d/*.conf" >> /app/httpd24/conf/httpd.conf
cat <<EOF > /app/httpd24/conf.d/httpd_php.conf
User apache
Group apache
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>
AddType application/x-httpd-php .php
AddType application/x-httpd-source .phps
proxyrequests off
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php5-fpm.sock|fcgi://localhost/app/httpd24/htdocs/"
EOF

httpd服務的啓動腳本
[apache_php-fpm]#

vim /usr/lib/systemd/system/httpd24.service
[Unit]
Description=The Apache HTTP Server
After=network.target remote-fs.target nss-lookup.target
Documentation=man:httpd(8)
Documentation=man:apachectl(8)

[Service]
Type=forking
#EnvironmentFile=/etc/sysconfig/httpd
ExecStart=/app/httpd24/bin/httpd $OPTIONS -k start
ExecReload=/app/httpd24/bin/httpd $OPTIONS -k graceful
ExecStop=/bin/kill -WINCH ${MAINPID}
# We want systemd to give httpd some time to finish gracefully, but still want
# it to kill httpd after TimeoutStopSec if something went wrong during the
# graceful stop. Normally, Systemd sends SIGTERM signal right after the
# ExecStop, which would kill httpd. We are sending useless SIGCONT here to give
# httpd time to finish.
KillSignal=SIGCONT
PrivateTmp=true

[Install]
WantedBy=multi-user.target

安裝相關軟件
[apache_php-fpm]#

yum install php-fpm php-mysql -y

配置php-fpm

[apache_php-fpm]#

cat <<EOF > /etc/php-fpm.d/optimization.conf
pm.start_servers = 30
pm.min_spare_servers = 20
pm.max_spare_servers = 60
pm.max_children = 500
pm = dynamic
pm.max_requests = 500
pm.status_path = /status
ping.path = /ping
ping.response = pong
EOF
cat <<EOF > /etc/php-fpm.d/httpd_php.conf
listen.owner = apache
listen.group = apache
listen = /var/run/php5-fpm.sock
listen.mode = 0666
EOF

啓動服務

[apache_php-fpm]#

systemctl start httpd24
systemctl start php-fpm

安裝 mariadb,配置授權

[mariadb]#

yum install mariadb-server -y
systemctl start mariadb
mysql -e "create database discuz;grant all on discuz.* to discuz@'192.168.43.%'  identified by 'discuz';flush privileges;"

將 discuz 程序掛載到網站的根目錄

[apache_php-fpm]#

cd /app/httpd24/htdocs/
unzip Discuz_X3.2_SC_UTF8.zip
ls
Discuz_X3.2_SC_UTF8.zip  index.html  readme  upload  utility
mv upload/ forum
setfacl -Rm u:apache:rwx forum/

windows中的瀏覽器訪問

http://192.168.43.17/forum/install/
在這裏插入圖片描述
在這裏插入圖片描述

linux客戶端訪問

[client]#

ab -c1000 -n 1000 http://192.168.43.17/forum/

基於端口httpd支持php-fpm的配置

vim /etc/httpd/conf.d/fcgi.conf
directoryindex index.php
proxyrequests off
proxypassmatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/var/www/html/$1

官方文檔

Apache Module mod_proxy_fcgi

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章