编译安装php-5.4.44
编译安装php-5.4.44
1. 首先,安装必要的库文件,一面编译被打断:
yum install -y gcc gcc-c++ make zlib zlib-devel pcre pcre-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5-devel openssl openssl-devel openldap openldap-devel openldap-clients openldap-servers libmcrypt libmcrypt-devel libaio libaio-devel
本来不需要这么多的,为了避免以后出现其他错误,建议全部扩展。需要epel源,具体方法参考:http://www.cnblogs.com/llius/p/5105051.html
2. 下载php:
# cd /usr/local/src # wget http://au1.php.net/distributions/php-5.4.44.tar.bz2 # tar jxf php-5.4.44.tar.bz2
3. 新建php-fpm普通用户:
# useradd -s /sbin/nologin -M php-fpm //-s /sbin/nologin:禁止php-fpm用户登录,-M:不在/home下生成php-fpm的家目录
4. 参数初始化:
# cd php-5.4.44 ./configure \ --prefix=/usr/local/php \ --with-apxs2=/usr/local/apache2/bin/apxs \ //该选项对php解析非常重要,正确的make && make install 后会在/usr/local/apache2/modules目录生成libphp5.so --with-config-file-path=/usr/local/php/etc \ --with-mysql=/usr/local/mysql \ --with-libxml-dir \ --with-gd \ --with-jpeg-dir \ --with-png-dir \ --with-freetype-dir \ --with-iconv-dir \ --with-zlib-dir \ --with-bz2 \ --with-openssl \ --with-mcrypt \ --enable-soap \ --enable-gd-native-ttf \ --enable-mbstring \ --enable-sockets \ --enable-exif \ --disable-ipv6
保存配置文件后,检验配置是否正确的方法为:
# /usr/local/php/sbin/php-fpm -t //返回如下结果,说明没有错误
NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
因为路径长,可以设立一个别名:
# vim ~/.bashrc //在alias队列后面添加如下内容: alias php-fpm='//usr/local/php/sbin/php-fpm' # source !$ //即: source ~/.bashrc
7. php的启动(需要拷贝启动脚本):
# cp /usr/local/src/php-5.3.27/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm //拷贝启动脚本 # chmod 755 /etc/init.d/php-fpm //需有x权限 # service php-fpm start //启动
Starting php-fpm done //返回如下结果,说明开启成功
# chkconfig add php-fpm //这两步是添加开机启动
# chkconfig php-fpm on
# ps aux |grep php-fpm //应该有20余个php-fpm进程,因为在上面的配置文件里面定义了: pm.start_servers = 20