1. 安装编译前提
a. 编译环境
# yum -y install gcc gcc-c++ make
b. php 相关模块
# yum -y install libjpeg-devel libpng-devel freetype-devel libxml2-devel libxslt-devel zlib-devel curl-devel mhash-devel openldap-devel gd-devel
c. libiconv模块安装
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1
# ./configure --prefix=/usr/local/libiconv && make && make install
d. libmcrypt模块安装
# wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2F&ts=1304912647&use_mirror=nchc
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure && make && make install
# cd libltdl
# ./configure --enable-ltdl-install && make && make install
e. mysql库链接
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
2. php编译安装
a. 针对apache的编译安装
# vi /usr/local/httpd/bin/apxs
将第一行的
1 | #!/replace/with/path/to/perl/interpreter -w |
替换为
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --with-curlwrappers --with-mhash --with-mcrypt --with-gd --enable-gd-native-ttf --with-xsl --with-openssl --with-ldap --with-ldap-sasl --with-xmlrpc --without-pear --enable-zip --enable-soap --enable-mbstring --enable-ftp --enable-sockets --enable-pcntl --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --disable-rpath --enable-mbregex --with-apxs2=/usr/local/httpd/bin/apxs
# make && make install
配置
# vi /usr/local/httpd/conf/httpd.conf
找到
1 | AddType application/x-gzip .gz .tgz |
下行添加
1 | AddType application/x-httpd-php .php |
找到
2 | DirectoryIndex index.html |
修改为
2 | DirectoryIndex index.html index.htm index.php |
b. 针对nginx的编译安装
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --with-curlwrappers --with-mhash --with-mcrypt --with-gd --enable-gd-native-ttf --with-xsl --with-openssl --with-ldap --with-ldap-sasl --with-xmlrpc --without-pear --enable-zip --enable-soap --enable-mbstring --enable-ftp --enable-sockets --enable-pcntl --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --disable-rpath --enable-mbregex --enable-safe-mode --enable-fpm --with-fpm-user=www --with-fpm-group=www
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# vi /usr/local/php/etc/php-fpm.conf 取消以下;分号注释
3 | ;pm.min_spare_servers = 5 |
4 | ;pm.max_spare_servers = 35 |
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
# chmod 755 /etc/init.d/php-fpm
# chkconfig --add php-fpm
# chkconfig --level 2345 php-fpm on
c. 配置
# mkdir /usr/local/php/etc
# cp php.ini-development /usr/local/php/etc/php.ini
# curl http://pear.php.net/go-pear | /usr/local/php/bin/php
# vi /usr/local/php/etc/php.ini
找到
替换为
1 | extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/" |
3. php扩展模块安装
a. 安装autoconf
# yum -y install autoconf
b. 安装memcache
# wget http://pecl.php.net/get/memcache-3.0.6.tgz
# tar xvf memcache-3.0.6.tgz
# cd memcache-3.0.6
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
c. 安装pdo-mysql
# wget http://pecl.php.net/get/PDO_MYSQL-1.0.2.tgz
# tar xvf PDO_MYSQL-1.0.2.tgz
# cd PDO_MYSQL-1.0.2
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql && make && make install
d. 安装ImageMagick
# wget http://image_magick.veidrodis.com/image_magick/ImageMagick-6.6.9-9.tar.gz
# tar zxvf ImageMagick-6.6.9-9.tar.gz
# cd ImageMagick-6.6.9-9
# ./configure && make && make install
# wget http://pecl.php.net/get/imagick-3.1.0b1.tgz
# tar xvf imagick-3.1.0b1.tgz
# cd imagick-3.1.0b1
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config && make && make install
# vi /usr/local/php/etc/php.ini
找到
下行添加
1 | extension = "memcache.so" |
2 | extension = "pdo_mysql.so" |
3 | extension = "imagick.so" |
4. php加速应用
a. ZendGuardLoader
# tar zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
# cp ZendGuardLoader-php-5.3-linux-glibc23-i386/php-5.3.x/ZendGuardLoader.so /usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/
# vi /usr/local/php/etc/php.ini 未尾加上
2 | zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/ZendGuardLoader.so" |
b. eAccelerator
# wget http://bart.eaccelerator.net/source/0.9.6.1/eaccelerator-0.9.6.1.tar.bz2
# cd eaccelerator-0.9.6.1
# /usr/local/php/bin/phpize
# ./configure --enable-eaccelerator=shared --with-php-config=/usr/local/php/bin/php-config && make && make install
# mkdir -p /usr/local/php/eaccelerator_cache
# cp control.php /usr/local/nginx/html/
# vi /usr/local/php/etc/php.ini 未尾加上
02 | zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so" |
03 | eaccelerator.shm_size="64" |
04 | eaccelerator.cache_dir="/usr/local/php/eaccelerator_cache" |
05 | eaccelerator.enable="1" |
06 | eaccelerator.optimizer="1" |
07 | eaccelerator.check_mtime="1" |
10 | eaccelerator.shm_max="0" |
11 | eaccelerator.shm_ttl="3600" |
12 | eaccelerator.shm_prune_period="3600" |
13 | eaccelerator.shm_only="0" |
14 | eaccelerator.compress="1" |
15 | eaccelerator.compress_level="9" |
16 | eaccelerator.allowed_admin_path="/usr/local/nginx/html/control.php" |
转自:http://www.xtgly.com/2011/05/17/centos-lnamp%E4%B9%8B%E4%B8%89%EF%BC%88%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85-php-5-3-6%EF%BC%89.htm