源碼編譯LAMP的FCGI模式的多虛擬主機

一、環境準備

Centos7.6最小化安裝

關閉防火牆、selinux

需要用到的安裝包:

apr-1.7.0.tar.bz2     apr-util-1.6.1.tar.bz2    httpd-2.4.39.tar.bz2     mariadb-10.2.25-linux-x86_64.tar.gz

php-7.3.7.tar.xz             wordpress-5.2.2.tar.gz      Discuz_X3.3_SC_UTF8.zip    

二、安裝

1、解壓安裝包

image.png

for i in *.bz2 ;do tar xvf $i ;done

如果解壓報錯安裝bzip2包

tar xvf php-7.3.7.tar.xz
tar xvf wordpress-5.2.2.tar.gz
unzip  Discuz_X3.3_SC_UTF8.zip  
tar xvf mariadb-10.2.25-linux-x86_64.tar.gz -C /usr/local

2、編譯安裝apache

有2種方法一種是分別編譯安裝apr、apr-util、httpd,第二種就是三個軟件放在一起編譯安裝,這裏使用第二種方法

(1)合併文件、安裝依賴包、

mv  apr-1.7.0 httpd-2.4.39/srclib/apr

mv apr-util-1.6.1 httpd-2.4.39/srclib/apr-util

yum install gcc prce-devel openssl-devel expat-devel -y

useradd -s /sbin/nologin apache    #創建用戶

(2)編譯安裝

[root@swh httpd-2.4.39]#./configure \
--prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-included-apr \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
[root@swh httpd-2.4.39]#make -j 2 && make install   #安裝部分截圖

image.png

(2)設置環境變量

[root@swh httpd-2.4.39]#echo 'PATH=/app/httpd24/bin:$PATH' > /etc/profile.d/httpd24.sh

[root@swh httpd-2.4.39]#. /etc/profile.d/httpd24.sh

(3)編寫systemctl啓動腳本或者直接複製啓動腳本用service管理也行

[root@swh httpd-2.4.39]#vi /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
#ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND
ExecReload=/usr/sbin/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

[root@swh httpd-2.4.39]#systemctl start httpd24      #啓動服務測試

image.png

(4)修改配置文件

[root@swh httpd-2.4.39]#cp /app/httpd24/conf/httpd.conf /app/httpd24/conf/httpd.conf.bak

[root@swh httpd-2.4.39]#vi /app/httpd24/conf/httpd.conf

LoadModule proxy_module modules/mod_proxy.so    #120行代理模塊
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so    #124行
User apache   #修改173、174行的用戶和組
Group apache   
DirectoryIndex index.php index.html     # 261行默認首頁
#以下內容添加到最後面 
AddType application/x-httpd-php .php    #讓apache能夠識別php文件
AddType application/x-httpd-php-source .phps
ProxyRequests Off
<Virtualhost *:80>
servername wp.swh.com
documentroot /data/wordpress
<Directory /data/wordpress>
require all granted
</Directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/wordpress/$1
</Virtualhost>
<Virtualhost *:80>
servername dz.swh.com
documentroot /data/discuz
<Directory /data/discuz>
require all granted
</Directory>
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/data/discuz/$1
</Virtualhost>

[root@swh mysql]#mkdir /data/wordpress   創建網站目錄

[root@swh mysql]#mkdir /data/discuz    

[root@swh mysql]#mv upload/* discuz/

[root@swh data]#setfacl -Rm u:apache:rwx /data/{wordpress,discuz}

重啓httpd24服務

3、編譯安裝mysql

(1)安裝參考

https://blog.51cto.com/14322729/2418319

(2)創建數據庫和用戶

MariaDB [(none)]> create database wordpress;

MariaDB [(none)]> create database discuz;

MariaDB [(none)]> grant all on wordpress.* to wpuser@'192.168.12.%' identified by '123456';

MariaDB [(none)]> grant all on discuz.* to dzuser@'192.168.12.%' identified by '123456';

4、編譯安裝php

(1)安裝依賴包

yum install libxml2-devel bzip2-devel libmcrypt-devel  openssl-devel  gcc

(2)編譯安裝

[root@swh php-7.3.7]#./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-openssl \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-mbstring \
--enable-xml \
--enable-sockets \
--enable-fpm \
--enable-maintainer-zts \
--disable-fileinfo
make && make install

注意:php-7.0以上版本使用--enable-mysqlnd --with-mysqli=mysqlnd ,原--with-mysql不再支持

[root@swh php-7.3.7]#make && make install

cp php.ini-production /etc/php.ini

cp  sapi/fpm/init.d.php-fpm  /etc/init.d/php-fpm 

chmod +x /etc/init.d/php-fpm

cd /app/php/etc

cp php-fpm.conf.default php-fpm.conf

cd php-fpm.d/

cp www.conf.default www.conf

vim www.conf

user = apache   #修改23、24行
group = apache

service php-fpm start

5、安裝程序

修改windows的hosts文件C:\Windows\System32\drivers\etc\hosts

192.168.12.27   wp.swh.com   dz.swh.com

注意之前數據庫地址要填寫192.168.12.27

image.png


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