php编译安装与配置.docx
- 文档编号:27757925
- 上传时间:2023-07-04
- 格式:DOCX
- 页数:15
- 大小:18.87KB
php编译安装与配置.docx
《php编译安装与配置.docx》由会员分享,可在线阅读,更多相关《php编译安装与配置.docx(15页珍藏版)》请在冰豆网上搜索。
php编译安装与配置
php编译安装与配置
一:
了解与准备
1.1:
Apache(httpd)nginx与php连接方式:
httpd与php:
1:
php作为httpd模块
2:
fastcgi(php-fpm)
3:
cgi(此处不讲解)
nginx与php:
1:
fastcgi(php-fpm)
1.2:
PHP安装与依赖:
~]#yum-yinstallgccgcc-c++libxml2libxml2-develbzip2bzip2-devellibmcryptlibmcrypt-developensslopenssl-devellibcurl-devellibjpeg-devellibpng-develfreetype-develreadlinereadline-devellibxslt-develperlperl-develpsmisc.x86_64recoderecode-devellibtidylibtidy-devel
1.3:
备注:
1:
上面的依赖基本解决所需要的依赖。
2:
编译安装完成后可以增减所支持的php模块,此处所编译的模块已经非常完备。
3:
需要编译单个模块,查看php模块编译方式:
php模块编译
4:
下面编译安装的配置选项:
--prefix=/usr/local/php7主程序文件路径
--sysconfdir=/etc/php7配置文件路径
--with-config-file-path=/etc/php7php.ini文件路径
--with-apxs2=/usr/local/httpd/bin/apxs以httpd模块编译时需要指定httpd的apxs文件路径。
其他的配置可以按自己需求指定,这几个选项也可以使用默认配置。
5:
php7移除了mysql扩展,php7仅能是用mysqli和pdo_mysql。
php5可以使用。
php5编译时加入选项:
--with-mysql。
详情查看下面的PHP与MariaDB(mysql)连接
6:
此处以CentOs7编译php7为示例,配合讲解php5安装的要点。
7:
php.ini文件是在包目录下的php.ini-development(开发),php.ini-production(生产)
编译完成后选择自己需要的php.ini文件复制到--with-config-file-path指定的目录。
如果编译时为指定此选项,编译完成配置并启动nginx和php查看phpinfo()函数所指定的php.ini文件路径:
ConfigurationFile(php.ini)Path
默认为php目录下的lib目录。
8:
PHP安装与依赖中psmisc.x86_64是killall命令的包名,以便最小化安装时终止进程。
二:
php编译与配置:
2.1:
httpd模块
备注:
需要事先存在httpd,编译指定apxs文件位置。
此处以--with-apxs2=/usr/local/httpd/bin/apxs作为演示。
php7:
~]#./configure--prefix=/usr/local/php7--sysconfdir=/etc/php7--with-config-file-path=/etc/php7--with-apxs2=/usr/local/httpd/bin/apxs--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-mhash--with-openssl--with-zlib--with-bz2--with-curl--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-zlib--enable-mbstring--with-mcrypt--enable-sockets--with-iconv-dir--with-xsl--enable-zip--with-pcre-dir--with-pear--enable-session--enable-gd-native-ttf--enable-xml--with-freetype-dir--enable-gd-jis-conv--enable-inline-optimization--enable-shared--enable-bcmath--enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-mbregex--enable-pcntl--with-xmlrpc--with-gettext--enable-exif--with-readline--with-recode--with-tidy
php5.6:
(仅增加了选项--with-mysql=mysqlnd)
~]#./configure--prefix=/usr/local/php5--sysconfdir=/etc/php5--with-config-file-path=/etc/php5--with-apxs2=/usr/local/httpd/bin/apxs--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-mhash--with-openssl--with-zlib--with-bz2--with-curl--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-zlib--enable-mbstring--with-mcrypt--enable-sockets--with-iconv-dir--with-xsl--enable-zip--with-pcre-dir--with-pear--enable-session--enable-gd-native-ttf--enable-xml--with-freetype-dir--enable-gd-jis-conv--enable-inline-optimization--enable-shared--enable-bcmath--enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-mbregex--enable-pcntl--with-xmlrpc--with-gettext--enable-exif--with-readline--with-recode--with-tidy
2.2:
fastcgiphp-fpm模式
php7:
~]#./configure--prefix=/usr/local/php7--sysconfdir=/etc/php7--with-config-file-path=/etc/php7--enable-fpm--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-mhash--with-openssl--with-zlib--with-bz2--with-curl--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-zlib--enable-mbstring--with-mcrypt--enable-sockets--with-iconv-dir--with-xsl--enable-zip--with-pcre-dir--with-pear--enable-session--enable-gd-native-ttf--enable-xml--with-freetype-dir--enable-gd-jis-conv--enable-inline-optimization--enable-shared--enable-bcmath--enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-mbregex--enable-pcntl--with-xmlrpc--with-gettext--enable-exif--with-readline--with-recode--with-tidy
php5.6:
(仅增加了选项--with-mysql=mysqlnd)
~]#./configure--prefix=/usr/local/php5--sysconfdir=/etc/php5--with-config-file-path=/etc/php5--enable-fpm--with-mysql=mysqlnd--with-mysqli=mysqlnd--with-pdo-mysql=mysqlnd--with-mhash--with-openssl--with-zlib--with-bz2--with-curl--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir--with-zlib--enable-mbstring--with-mcrypt--enable-sockets--with-iconv-dir--with-xsl--enable-zip--with-pcre-dir--with-pear--enable-session--enable-gd-native-ttf--enable-xml--with-freetype-dir--enable-gd-jis-conv--enable-inline-optimization--enable-shared--enable-bcmath--enable-sysvmsg--enable-sysvsem--enable-sysvshm--enable-mbregex--enable-pcntl--with-xmlrpc--with-gettext--enable-exif--with-readline--with-recode--with-tidy
2.3:
php.ini配置文件(在源码包目录下)
~]#cpphp.ini-production/etc/php7/php.ini
2.4:
php作为httpd模块
不需要修改php配置,
2.5:
fastcgiphp-fpm
~]#cp/etc/php7/php-fpm.conf.default/etc/php7/php-fpm.conf
~]#cp/etc/php7/php-fpm.d/www.conf.default/etc/php7/php-fpm.d/www.conf
#默认即可是本机127.0.0.1不必修改。
~]#vi/etc/php7/php-fpm.d/www.conf
#监听地址
listen=127.0.0.1:
9000
#允许的客户端
listen.allowed_clients=127.0.0.1
备注:
php5需要复制php-fpm.conf.default为php-fpm.conf即可。
查看php-fpm.conf监听地址和允许的客户端。
2.6:
启动与停止
httpd模块:
重新加载httpd。
fastcgi:
~]#vi/etc/php7/php-fpm.conf
打开注释:
(不打开注释仅能使用killallphp-fpm关闭php)
pid=run/php-fpm.pid
启动:
/usr/local/php7/sbin/php-fpm
立刻终止
kill-INT`cat/usr/local/php7/var/run/php-fpm.pid`
kill-TERM`cat/usr/local/php7/var/run/php-fpm.pid`
killallphp-fpm
平滑终止
kill-QUIT`cat/usr/local/php7/var/run/php-fpm.pid`
平滑重启
kill-USR2`cat/usr/local/php7/var/run/php-fpm.pid`
2.7:
加入环境变量
~]#vi/etc/profile.d/web.sh
exportPATH=$PATH:
/usr/local/php7/sbin:
/usr/local/php7/bin
2.8:
CentOS系统服务(/etc/php7/php-fpm.conf文件pid=run/php-fpm.pid注释需要打开:
2.6)
CentOS6:
~]#vi/etc/rc.d/init.d/php-fpm
~]#chmod+x/etc/rc.d/init.d/php-fpm
--------------------------filestart---------------------------------
#!
/bin/sh
#chkconfig:
-8416
#description:
PHPFastCGIProcessManager
#Sourcefunctionlibrary.
./etc/init.d/functions
#Checkthatnetworkingisup.
./etc/sysconfig/network
#Additionalenvironmentfile
if[-f/etc/sysconfig/php-fpm];then
./etc/sysconfig/php-fpm
fi
if["$NETWORKING"="no"]
then
exit0
fi
RETVAL=0
prog="php-fpm"
#可根据版本不同修改phpfpmpidfilelockfile变量。
其他地方不用修改。
phpfpm="/usr/local/php7/sbin/php-fpm"
pidfile=${PIDFILE-/usr/local/php7/var/run/php-fpm.pid}
lockfile=${LOCKFILE-/usr/local/php7/var/run/php-fpm.lock}
start(){
echo-n$"Starting$prog:
"
dir=$(dirname${pidfile})
[-d$dir]||mkdir$dir
daemon--pidfile${pidfile}${phpfpm}
RETVAL=$?
echo
[$RETVAL-eq0]&&touch${lockfile}
}
stop(){
echo-n$"Stopping$prog:
"
killproc-p${pidfile}php-fpm
RETVAL=$?
echo
if[$RETVAL-eq0];then
rm-f${lockfile}${pidfile}
fi
}
restart(){
stop
start
}
reload(){
echo-n$"Reloading$prog:
"
if!
${phpfpm}--test;then
RETVAL=6
echo$"notreloadingduetoconfigurationsyntaxerror"
failure$"notreloading$progduetoconfigurationsyntaxerror"
else
killproc-p${pidfile}php-fpm-USR2
RETVAL=$?
fi
echo
}
#Seehowwewerecalled.
case"$1"in
start)
start
;;
stop)
stop
;;
status)
status-p${pidfile}php-fpm
RETVAL=$?
;;
restart)
restart
;;
reload|force-reload)
reload
;;
configtest)
${phpfpm}--test
RETVAL=$?
;;
condrestart|try-restart)
[-f${lockfile}]&&restart||:
;;
*)
echo$"Usage:
$0{start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest}"
RETVAL=2
;;
esac
exit$RETVAL
--------------------------fileend---------------------------------
~]#servicephp-fpm{start|stop|status|restart|reload|force-reload|condrestart|try-restart|configtest}
CentOS7:
~]#vim/usr/lib/systemd/system/php-fpm.service
--------------------------filestart---------------------------------
[Unit]
Description=php-fpm
After=syslog.targetnetwork.target
[Service]
Type=forking
PIDFile=/usr/local/php7/var/run/php-fpm.pid
ExecStart=/usr/local/php7/sbin/php-fpm
ExecReload=/bin/kill-USR2$MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
--------------------------fileend---------------------------------
~]#systemctl(start|restart|reload|stop|enable|disable|status)php-fpm.service
2.8:
系统启动服务
CentOS6:
加入chkconfig管理:
~]#chkconfig--addphp-fpm
开机启动:
~]#chkconfig--level345php-fpmon
开机不启动:
~]#chkconfigphp-fpmoff
查看开机是否启动
~]#chkconfig--listphp-fpm
CentOS7:
开机启动:
~]#systemctlenablephp-fpm.service
开机不启动:
~]#systemctldisablephp-fpm.service
2.9:
加入man文档
CentOS6:
~]#vim/etc/man.config
CentOS7:
~]#vi/etc/man_db.conf
写入:
MANPATH/usr/local/php7/php/man
备注:
然后就可以使用man命令查看
三:
httpdnginx与php连接
3.1:
httpd模块php
要点:
1:
httpd开启模块:
LoadModuleproxy_modulemodules/mod_proxy.so
LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so
2:
php编译指定httpdapxs路径(成为httpd模块)
--with-apxs2=/usr/local/httpd24/bin/apxs
连接:
~]#vi/etc/httpd/httpd.conf
1:
添加:
(编译时这个默认已经添加)
LoadModulephp7_modulemodules/libphp7.so
#LoadModulephp5_modulemodules/libphp5.so
2:
添加index.php:
DirectoryIndexindex.phpindex.html
3:
文件最后添加:
SetHandlerapplication/x-httpd-php
备注:
vhost也可以应用
3.2:
httpd(fastcgi)与php-fpm
要点:
1:
httpd开启模块:
LoadModuleproxy_modulemodules/mod_proxy.so
LoadModuleproxy_fcgi_modulemodules/mod_proxy_fcgi.so
2:
php编译开启模块:
--enable-fpm
连接方式1:
~]#vi/etc/httpd/httpd.conf
最后添加:
#On:
正向代理(默认)Off:
反向代理(此处建议使用)
ProxyRequestsOff
SetHandlerproxy:
fcgi:
//127.0.0.1:
9000
连接方式2:
~]#vi/etc/httpd/httpd.conf
最后添加:
#On:
正向代理(默认)Off:
反向代理(此处建议使用)
ProxyRequestsOff
ProxyPassfcgi:
//127.0.0.1:
9000/var/www/html/
连接方式3:
类型2的改变
~]#vi/etc/httpd/httpd.conf
最后添加:
#On:
正向代理(默认)Off:
反向代理(此处建议使用)
ProxyRequestsOff
ProxyPassMatch^/(.*\.php)$fcgi:
//127.0.0.1:
9000/var/www/html/$1
连接方式设置完后再添加index.php:
DirectoryIndexind
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- php 编译 安装 配置
![提示](https://static.bdocx.com/images/bang_tan.gif)