PHP的源码安装与配置

PHP源码安装包下载

PHP的源码安装包可以在PHP的官方网站http://www.php中下载,本次安装所使用的PHP安装包是php-5.6.20.tar.bz2。使用环境是redhat企业6.5版本。

PHP源码包的编译和安装

PHP的源码包可以根据以下步骤进行编译安装。

[root@server1 ~]# tar jxf php-5.6.20.tar.bz2
[root@server1 ~]# cd php-5.6.20
[root@server1 php-5.6.20]# ./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt  --with-mhash
[root@server1 php-5.6.20]# make
[root@server1 php-5.6.20]# make install

./configure中的参数可以在./configure –help中查看,根据实际情况的不同需要加入不同的参数。
在./configure编译步骤中,需要安装依赖包。

[root@server1 php-5.6.20]# yum install -y libxml2-devel
[root@server1 php-5.6.20]# yum install -y curl-devel
[root@server1 php-5.6.20]# yum install -y gmp-devel
[root@server1 php-5.6.20]# yum install -y net-snmp-devel
# 除此之外还有安装包 libmcrypt-devel、 libmcrypt 、gd-devel安装包系统没有自带,需要网站上下载。

PHP的配置

  • PHP的配置文件
    PHP的配置文件是/usr/local/lnmp/php/etc目录下的php-fpm.conf文件和php.ini文件,这两个文件本身是不存在的,需要复制其他文件。
[root@server1 php]# cp /root/php-5.6.20/php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@server1 php]# vim /usr/local/lnmp/php/etc/php.ini

date.timezone = Asia/Shanghai

[root@server1 php]# cp /usr/local/lnmp/php/etc/php-fpm.conf.default /usr/local/lnmp/php/etc/php-fpm.conf
[root@server1 php]# vim /usr/local/lnmp/php/etc/php-fpm.conf

pid = run/php-fpm.pid
  • 复制启动脚本
    将启动脚本复制到/etc/init.d目录下,并给予可执行权限。
[root@server1 php]# cp /root/php-5.6.20/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@server1 php]# chmod +x /etc/init.d/php-fpm
[root@server1 php]# chkconfig --add php-fpm

PHP启动

至此PHP的源码安装及配置就已经完成,可以启动PHP了,如果需要其他配置,也可以自己修改。

更多推荐

PHP的源码安装与配置