Linux 第78天 編譯安裝lamp
時間: 20181020
目錄
在centos6編譯安裝httpd-2.4
CentOS7編譯安裝LAMP
CentOS7 php編譯成httpd模塊的方式工作
CentOS7 php-fpm編譯成獨立運行的方式工作
總結
在centos6編譯安裝httpd-2.4
安裝httpd-2.4
依賴於apr-1.4+, apr-util-1.4+, [apr-iconv]
apr: apache portable runtime,解決跨平臺實現
CentOS 6:默認:apr-1.3.9, apr-util-1.3.9
安裝前準備開發包:
開發環境包:
包組:Development Tools
相關包:pcre-devel,openssl-devel expat-devel
下載源代碼並解壓縮:
httpd-2.4.27.tar.bz2
apr-1.6.2.tar.bz2
apr-util-1.6.0.tar.bz2
安裝apr和apr-util
安裝apr-1.4+
cd apr-1.6.2
./configure --prefix=/app/apr
make && make install
安裝apr-util-1.4+
cd ../apr-util-1.6.0
./configure --prefix=/app/apr-util --with-apr=/app/apr/
make -j 2 && make install
編譯安裝httpd-2.4
cd ../httpd-2.4.27
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/app/apr/ \
--with-apr-util=/app/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork
make -j 4 && make install
CentOS7編譯安裝LAMP
編譯安裝httpd-2.4
yum install pcre-develapr-develapr-util-developenssl-devel
./configure --prefix=/app/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork \
--with-included-apr
make -j 4 && make install
CentOS7 php編譯爲httpd的模塊方式工作編譯php5.6
相關包:
libxml2-devel bzip2-devel libmcrypt-devel(epel)
./configure --prefix=/app/php \
--with-mysql=/usr/local/mysql \
--with-openssl \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--enable-mbstring --with-png-dir \
--with-jpeg-dir \
--with-freetype-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/app/httpd24/bin/apxs \
--with-mcrypt \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d--with-bz2
make -j 4 && make install
CentOS7 php模塊方式編譯安裝
需要額外的安裝包
libjpeg-devel libpng-devel freetype-devel
./configure --prefix=/app/php72 \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--with-apxs2=/app/httpd24/bin/apxs \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo \
--enable-fpm \
--with-gd
爲php提供配置文件
cp php.ini-production /etc/php.ini
編輯apache配置文件httpd.conf,以使apache支持php
vim /etc/httpd24/conf/httpd.conf
1加二行
AddTypeapplication/x-httpd-php.php
AddTypeapplication/x-httpd-php-source.phps
2 定位至DirectoryIndexindex.html
修改爲DirectoryIndexindex.phpindex.html
apachectl restart
CentOS7 php-fpm編譯成獨立運行的方式編譯安裝LAMP
編譯爲模塊和編譯爲獨立運行區別就在於如何編譯php,配置php的配置
tar xvfphp-7.2.11.tar.bz2
cd php-7.2.11/
./configure --prefix=/app/php \
--enable-mysqlnd \
--with-mysqli=mysqlnd \
--with-openssl \
--with-pdo-mysql=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib \
--with-libxml-dir=/usr \
--enable-xml \
--enable-sockets \
--enable-fpm \
--with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--disable-fileinfo \
--with-gd
cp php.ini-production /etc/php.ini
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system
cd /app/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default php-fpm.d/www.conf
systemctl start php-fpm
配置httpd支持php
vim /app/httpd24/conf/httpd.conf
取消下面兩行的註釋
LoadModuleproxy_modulemodules/mod_proxy.so
LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so
修改下面行
<IfModuledir_module>
DirectoryIndexindex.phpindex.html
</IfModule>
加下面四行
AddTypeapplication/x-httpd-php.php
AddTypeapplication/x-httpd-php-source .phps
ProxyRequestsOff
ProxyPassMatch^/(.*\.php)$ fcgi://127.0.0.1:9000/app/httpd24/htdocs/$1
總結:
1. LAMP 分開機器安裝時所有.php文件需要放在php的服務器上
2. 編譯安裝只在rpm方式所安裝的軟件不滿足現實需求的場景時纔去編譯安裝
編譯安裝對後續的升級維護成本相對會比較高