首页 LAMP教程编译安装php

实战案例:yum安装php7.3+wordpress5.2+opcache+event模式

实战案例:实现CentOS 7编译安装基于httpd 模块方式的LAMP

运维派隶属马哥教育旗下专业运维社区,是国内成立最早的IT运维技术社区,欢迎关注公众号:yunweipai
领取学习更多免费Linux云计算、Python、Docker、K8s教程关注公众号:马哥linux运维

编译安装php

编译安装 httpd 模块方式的php5.6

#安装相关包,依赖epel源
yum install gcc make libxml2-devel  bzip2-devel libmcrypt-devel

#编译安装php
tar xvf php-5.6.30.tar.bz2
cd php-5.6.30
./configure --prefix=/apps/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

#准备php的配置文件
cd php-5.6.30
cp php.ini-production /etc/php.ini

#修改httpd配置文件支持php
vim /etc/httpd24/conf/httpd.conf
#下面加二行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps

#定位至DirectoryIndex index.html, 修改为
DirectoryIndex index.php index.html

apachectl restart

编译安装 httpd 模块方式的 php 7.3

#安装相关包, 依赖epel源
yum install gcc make libxml2-devel bzip2-devel libmcrypt-devel

#编译安装php 7.3
tar xvf php-7.3.10.tar.xz 
cd php-7.3.10/
./configure \
--prefix=/apps/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 \
--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-maintainer-zts 仅针对mpm为event和worker的情况,编译成zts模块,如果是prefork则不需要
#php-7.0 以上版本使用--enable-mysqlnd --with-mysqli=mysqlnd ,原--with-mysql不再支持

make -j 4 && make install

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

vim /etc/httpd24/httpd.conf
在文件尾部加两行
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
修改下面行
<IfModule dir_module>
    DirectoryIndex index.php index.html
</IfModule>

编译安装 fastcgi 方式的php 7.3

#安装相关包,依赖EPEL源
yum install gcc make  libxml2-devel  bzip2-devel libmcrypt-devel 

#编译安装 php 7.3
tar xvf php-7.3.10.tar.bz2 
cd php-7.3.10/
./configure --prefix=/apps/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的配置文件
cd php-7.3.10/
cp php.ini-production  /etc/php.ini
cd /apps/php/etc
cp php-fpm.conf.default php-fpm.conf
cp php-fpm.d/www.conf.default  php-fpm.d/www.conf

#准备php-fpm启动脚本或service unit文件
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm 
chkconfig --add php-fpm 
chkconfig php-fpm on
service php-fpm start

#或者
cp sapi/fpm/php-fpm.service /usr/lib/systemd/system/
systemctl daemon-reload
systemctl start php-fpm

#配置httpd支持php-fpm
vim /apps/httpd24/conf/httpd.conf 
#取消下面两行的注释
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-php-source .phps
ProxyRequests Off
ProxyPassMatch  ^/(.*.php) fcgi://127.0.0.1:9000/var/www/html/$1

#支持opcache加速
vim /etc/php.ini
[opcache]
zend_extension=opcache.so                                                                  opcache.enable=1

本文链接:https://www.yunweipai.com/36109.html

实战案例:yum安装php7.3+wordpress5.2+opcache+event模式

实战案例:实现CentOS 7编译安装基于httpd 模块方式的LAMP

网友评论comments

发表回复

您的电子邮箱地址不会被公开。

暂无评论

Copyright © 2012-2022 YUNWEIPAI.COM - 运维派 京ICP备16064699号-6
扫二维码
扫二维码
返回顶部