Linux,centos 下编译安装 PHP 5.5

最后更新时间:2014-02-07 15:30:49UEANER

系统环境:

  • CentOS 6.5 x86_64

下载 PHP 源码包

# wget http://cn2.php.net/distributions/php-5.5.9.tar.bz2# tar xf php-5.5.9.tar.bz2 -C /usr/local/src/

添加 epel 源

# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

安装依赖

# yum install gcc bison bison-devel zlib-devel libmcrypt-devel mcrypt mhash-devel openssl-devel libxml2-devel libcurl-devel bzip2-devel readline-devel libedit-devel

创建 www 用户

# groupadd www# useradd -g www -s /sbin/nologin -M www

编译安装

# cd /usr/local/src/php-5.5.9/# ./configure \--prefix=/usr/local/php \
--with-config-file-path=/etc \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-opcache \
--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-gettext \
--enable-mbstring \
--with-iconv \
--with-mcrypt \
--with-mhash \
--with-openssl \
--enable-bcmath \
--enable-soap \
--with-libxml-dir \
--enable-pcntl \
--enable-shmop \
--enable-sysvsem \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline \
--without-sqlite3 \
--without-pdo-sqlite \
--with-pear

参数说明:

""" 安装路径 """--prefix=/usr/local/php \
""" php.ini 配置文件路径 """--with-config-file-path=/etc \
""" 优化选项 """--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
""" 启用 opcache,默认为 ZendOptimizer+(ZendOpcache) """--enable-opcache \
""" FPM """--enable-fpm \
--with-fpm-user=www \
--with-fpm-group=www \
""" MySQL """--with-mysql=mysqlnd \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
""" 国际化与字符编码支持 """--with-gettext \
--enable-mbstring \
--with-iconv \
""" 加密扩展 """--with-mcrypt \
--with-mhash \
--with-openssl \
""" 数学扩展 """--enable-bcmath \
""" Web 服务,依赖 libxml """--enable-soap \
--with-libxml-dir \
""" 进程控制 """--enable-pcntl \
--enable-shmop \
--enable-sysvsem \
""" socket & curl """--enable-sockets \
--with-curl \
""" 压缩与归档 """--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令行快捷键绑定 """--with-readline \
""" 禁用 SQLite 支持扩展 """--without-sqlite3 \
--without-pdo-sqlite \
""" 更多 PHP 扩展与应用库 """--with-pear

如果你的 Web Server 使用的 Apache 请添加类似:--with-apxs2=/usr/local/apache/bin/apxs 参数。

关于 mysqlnd 请查看 什么是 PHP 的 MySQL Native 驱动? 或查看 MySQL 官方介绍:MySQL native driver for PHP, 或 Installation on Unix

更多编译参数请使用 ./configure --help 查看。

# make -j2# make install

如果想重新安装:

# make clean# make clean all# ./configure ...# make -j2# make install

配置 PHP

配置文件

# cp php.ini-development /etc/php.ini

php-fpm 服务

# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm# chmod +x /etc/init.d/php-fpm

启动 php-fpm

# service php-fpm startStarting php-fpm  done

php-fpm 可用参数 start|stop|force-quit|restart|reload|status

添加 PHP 命令到环境变量

编辑 ~/.bash_profile,将:

PATH=$PATH:$HOME/bin
改为:
PATH=$PATH:$HOME/bin:/usr/local/php/bin

使 PHP 环境变量生效:

# . ~/.bash_profile

查看看 PHP 版本

# php -v
PHP 5.5.9(cli)(built:Feb7201415:06:34)Copyright(c)1997-2014The PHP GroupZendEngine v2.5.0,Copyright(c)1998-2014ZendTechnologies
转载请注明出处。
本文地址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux