本指南将指导您在Linux系统上完成PHP 5.4.8的编译安装,并将其配置为FastCGI模式。首先,确保系统已更新至最新状态,并安装必要的开发工具和库文件。
1. 安装编译环境和相关库:
yum -y install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel gd bzip2 bzip2-devel curl curl-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel
2. 下载并解压JPEG库源码:
cd /usr/src
wget http://www.ijg.org/files/jpegsrc.v8d.tar.gz
tar zxvf jpegsrc.v8d.tar.gz
cd jpeg-8d
./configure --enable-shared --enable-static
make && make install clean
3. 下载并安装Libmcrypt库:
cd /usr/src
wget http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
tar zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make && make install
4. 下载PHP 5.4.8源码包并进行编译安装:
cd /usr/src
wget http://cn2.php.net/get/php-5.4.8.tar.gz/from/this/mirror
tar zvxf php-5.4.8.tar.gz
cd php-5.4.8
mkdir -p /usr/local/php
./configure --prefix=/usr/local/php \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-libxml-dir=/usr/include/libxml2 \
--with-config-file-path=/usr/local/php/etc/ \
--with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-gd \
--enable-gd-native-ttf \
--with-zlib \
--with-mcrypt \
--with-pdo-mysql=/usr/local/mysql \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-wddx \
--enable-zip \
--with-xmlrpc \
--enable-fpm \
--enable-mbstring \
--with-zlib-dir \
--with-bz2 \
--with-curl \
--enable-exif \
--enable-ftp \
--with-jpeg-dir=/usr/lib64 \
--with-png-dir=/usr/lib64 \
--with-freetype-dir=/usr/lib64 \
--with-iconv \
--enable-xml \
--enable-bcmath \
--enable-sysvsem \
--enable-inline-optimization \
--with-curlwrappers \
--enable-mbregex \
--with-openssl \
--enable-pcntl \
--with-gettext \
--enable-session
make
make install
5. 配置PHP环境:
cp php.ini-production /usr/local/php/etc/php.ini
rm -rf /etc/php.ini
ln -s /usr/local/php/etc/php.ini /etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vi /usr/local/php/etc/php-fpm.conf
# 修改用户和组为www
user = www
group = www
# 取消pid前的分号
pid = run/php-fpm.pid
:wq
6. 设置PHP-FPM服务开机自启:
cp /usr/local/php/etc/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
7. 测试PHP-FPM是否正常工作:
cd /var/www/html
vi index.php
# 输入以下内容测试
phpinfo();
?>
:wq
保存后,在浏览器中访问您的服务器IP地址或域名,如果能看到PHP信息页面,则表示安装成功。