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方式所安装的软件不满足现实需求的场景时才去编译安装
编译安装对后续的升级维护成本相对会比较高