CentOS 源码编译安装 PHP

  • 服务器环境 CentOS 7.2
  • 安装的 PHP 版本 5.6.30

编译安装 PHP 之前先编译安装了 MySQL 5.6.35
戳我

首先下载对应的 PHP 源码包

mkdir ~/downloads
cd ~/downloads
wget http://sg2.php.net/distributions/php-5.6.30.tar.gz

解压

tar -zxvf php-5.6.30.tar.gz
cd php-5.6.30

需要准备一些依赖包,下载

yum install -y libxml2-devel openssl-devel libcurl-devel gd gd-devel libmcrypt libmcrypt-devel libtool

配置检查当前系统环境

./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv --with-jpeg-dir --with-png-dir --with-gd --with-freetype-dir --with-libxml-dir --with-pdo-mysql --with-openssl --with-mhash --with-zlib-dir --with-curl --with-gettext --with-pear --enable-calendar --enable-bcmath --enable-sockets --enable-mbstring --with-mcrypt --enable-fpm

如果是 PHP7(移除了 --with-mysql 的编译参数,无需预先安装好 MySQL,直接指定 mysqlnd 即可,未测试 5.* 版本是否可以这样编译)

./configure --prefix=/usr/local/php --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv --with-jpeg-dir --with-png-dir --with-gd --with-freetype-dir --with-libxml-dir --with-openssl --with-mhash --with-zlib-dir --with-curl --with-gettext --with-pear --enable-calendar --enable-bcmath --enable-sockets --enable-mbstring --with-mcrypt --enable-fpm

发现缺了

再执行上面的 ./configure 通过

接下来编译安装

make & make install

拷贝配置文件

cp php.ini-development /usr/local/php/lib/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf

最后往 /etc/profile 追加 PHP 的 bin sbin 两个目录路径

vim /etc/profile
PATH=/usr/local/php/bin:/usr/local/php/sbin:$PATH
export PATH
source /etc/profile

查看 PHP 版本信息

php -v

你可能感兴趣的:(CentOS 源码编译安装 PHP)