LAMP組合編譯安裝(使用的是Centos6)
httpd+php
modules:把php便以成 httpd的DSO模塊;
prefork:libphp5
event、worker :libphp5-zts
cgi
fpm(fastcgi):php做爲獨立的服務,監聽在某個套接字上向外提供服務;
httpd對fastcgi協議的支持:
httpd-2.2:須要額外安裝fcgi模塊:
httpd-2.4:自帶fcgi模塊;
安裝順序:httpd→ MariaDB→ php 其實只要保證php最後安裝便可;
1.首先須要安裝編譯環境以及依賴關係處理;
yum groupinstall 「Development Tools」 「Server Platform Development」 -y
yum install pcre pcre-devel → httpd依賴這兩個包
yun install bzip2-devel libmcrypt-devel libxml2-devel.x86_64 -y → PHP用到這三個包
注:libmcrypt-devel是在epel源中的,因此須要事安裝epel源;
2.下載待編譯的源碼包;
apr:http://archive.apache.org/dist/apr/apr-1.5.0.tar.bz2
apr-util:http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.bz2
httpd:http://archive.apache.org/dist/httpd/httpd-2.4.10.tar.gz
MariaDB:https://downloads.mariadb.org/mariadb/5.5.62/mariadb-5.5.62-linux-x86_64.tar.gz
PHP:http://php.net/releases/
3.解壓及編譯;
apr:
tar -xf apr-1.5.0.tar.bz2
cd apr-1.5.0/
./configure –prefix=/usr/local/apr
make && make install
apr-until:
tar -xf apr-util-1.5.3.tar.bz2
cd apr-util-1.5.3/
./configure --prefix=/usr/local/apr-until –with-apr=/usr/local/apr
由於apr-until是針對於apr編譯的因此後面要指明apr的位置;
make && make install
注:由於個人手誤將apr-util寫成了apr-until,你們作的時候注意更正過來;
httpd:httpd在編譯的時候咱們儘可能讓它對每個模塊都支持;
編譯安裝前注意各個相關的軟件爲新版本,我在編譯的時候就報一個ssl版本過舊的錯誤,若是你也碰到了使用yum install openssl-devel.x86_64 -y 以及yum update openssl便可;
tar -xf httpd-2.4.10.tar.bz2
cd httpd-2.4.10/
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-until --enable-modules=most --enable-mpms-shared=all –with-mpm=event
make && make install
cd /etc/rc.d/init.d
cp httpd httpd24
vim httpd24
apachectl=/usr/localapache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd24}
RETVAL=0
STOP_TIMEOUT=${STOP_TIMEOUT-10}
chkconfig --add httpd24
chkconfig --list httod24
hash -r
httpd -t
vim /etc/profile.d/httpd24.sh
export PATH=/usr/local/apache/bin:$PATH
. /etc/profile.d/httpd24.sh
hash
httpd -M
mpm_event_module (shared)
vim /etc/httpd24/httpd.conf
查找LoadModule → 啓用須要的模塊
MariaDB:
請查看:https://blog.csdn.net/qq_32501535/article/details/85102155
PHP(模塊方式):
tar -xf php-5.4.40.tar.bz2
cd php-5.4.40/
./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-bz2 --enable-maintainer-zts
--prefix=/usr/local/php 指定安裝路徑
--with-mysql=/usr/local/mysql 指定php是指定針對哪一個mysql安裝的
--with-openssl 指定openssl
--with-mysqli=/usr/local/mysql/bin/mysql_config 對mysql中數據庫的另一種接口
--enable-mbstring 啓用對多字節字符串的支持,使用中文的話就須要啓動
--with-freetype-dir 指定使用多種字體格式
--with-jpeg-dir 支持處理jpeg格式的圖片
--with-png-dir 支持處理png格式的圖片
--with-zlib 支持壓縮庫
--with-libxml-dir=/usr 支持處理xml格式的文檔
--enable-xml 啓用xml功能
--enable-sockets 支持基於socket通訊
--with-apxs2=/usr/local/apache/bin/apxs 把php編譯成apache的模塊
--with-mcrypt 支持加解密庫
--with-config-file-path=/etc php配置文件路徑
--with-config-file-scan-dir=/etc/php.d .d目錄 → 你懂的:跟php有關的配置均可以放在這個目錄中,php會自動加載其中的文件
--with-bz2 支持bz2格式
--enable-maintainer-zts httpd使用的是event或worker的話,就須要這個選項,不然就不用加;咱們前面使用的就是event,因此。。。
make && make install
編譯成功之後咱們還要回去配置httpd,由於httpd默認是不支持php的
cd /etc/httpd24/
cp httpd.conf{,.bak}
vim httpd.conf
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
安裝xcache,爲php加速
下載源碼包:http://xcache.lighttpd.net/wiki/Release-3.2.0
tar -xf xcache-3.2.0.tar.bz2
cd xcache-3.2.0/
/usr/local/php/bin/phpize xcache的configure時須要藉助php的phpize這個工具程序來讀取模塊文件而生成的;
./configure --enable-xcache--with-php-config=/usr/local/php/bin/php-config
--enable-xcache 啓用xcache模塊
--with-php-config=/usr/local/php/bin/php-config 將xcache編譯成php的模塊,xcache從本質上講是php的一個擴展;=右邊的就是php的一個擴展接口;
make && make install
cp xcache.ini /etc/php.d/
vim /etc/php.d/xcache.ini
extension =/usr/local/php/lib/php/extensions/no-debug-zts-20100525/xcache.so
PHP(以fpm方式):
tar -xf php-5.4.40.tar.bz2
cd php-5.4.40/
./configure --prefix=/usr/local/php5 --with-mysql=/usr/local/mysql --with-openssl --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --enable-fpm --with-mcrypt --with-config-file-path=/etc/php5 --with-config-file-scan-dir=/etc/php5.d --with-bz2
make && make install
在apache httpd2.4之後已經專門有一個模塊用於針對FastCGI的實現,此模塊爲mod_proxy_fcgi.so ,它實際上是做爲mod_proxy.so模塊的擴展,所以兩個模塊都須要加載;
一樣須要在httpd的配置文件中添加
vim /etc/httpd2-4/httpd.conf 使httpd支持php格式文件,而且加載相關模塊
注:這個httpd的配置文件不是接上文中編譯的那個,而是從新安裝的,由於上文使用的是event模塊模式的,其中的一些模塊是fpm不須要的,因此建議另外從新找到一個httpd的配置文件來使用;
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
配置虛擬主機支持使用fcgi
在相應的虛擬主機中添加相似如下兩行:
ProxyRequests Off 關閉正向代理
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
/PATH/TO/DOCUMENT_ROOT:存放.php資源的目錄;
$1:正則表達式的後向引用;
做用:在虛擬主機中以反向代理的方式告訴用戶全部對.php格式結尾的URL的請求都基於fcgi協議送給某個服務器(127.0.0.1)上的9000端口,以請求資源;
例子:
<VirtualHost *:80>
DocumentRoot 「/var/www/html」
ServerName guowei.com
ServerAlias www.guowei.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/PATH/TO/DOCUMENT_ROOT/$1
<Directory 「/var/www/html」>
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
mkdir /etc/php5{,.d}
cp php.ini-production /etc/php5/php.ini php的配置文件
cp sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm 服務啓動腳本
chmod +x /etc/rc.d/init.d/php-fpm
chkconfig --add php-fpm
cd /usr/local/php5/etc/
cp php-fpm.conf.default php-fpm.conf php-fpm的配置文件
vim php-fpm.conf
pm.max_children = 50 最多啓動多少個進程
pm.start_servers = 5 服務啓動時就啓動多少個進程
pm.min_spare_servers = 2 最小空閒進程
pm.max_spare_servers = 5 最大空閒進程
pid = /usr/local/php5/var/run/php-fpm.pid pid的位置
service php-fpm start
ps -aux | grep fpm
php
注:根據馬哥視頻作的學習筆記,若有錯誤,歡迎指正:侵刪
html