Compile and install PHP 5.6 under Linux

System environment:

CentOS 6.5 / 7.0 x86_64
Fedora 20 x86_64
Download PHP source package
# wget http://cn2.php.net/distributions/php-5.6.0.tar.xz
# xz -d php-5.6.0.tar. xz
# tar xf php-5.6.0.tar -C /usr/local/src/
add epel sources
# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6 -8.noarch.rpm
install dependencies
# 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 sqlite-devel
Note: if The source of epel 7 you use may not have mcrypt mhash mhash-devel several packages, download from http://dl.fedoraproject.org/pub/epel/6/x86_64/, use yum localinstall xxx.rpm or rpm -Uvh xxx.rpm can be installed manually.

Create www user
# groupadd www
# useradd -g www -s /sbin/nologin -M www
编译安装
# cd /usr/local/src/php-5.6.0/

# ./configure \
--prefix=/usr/local/php56 \
--with-config-file-path=/usr/local/php56/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-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-sockets \
--with-curl \
--with-zlib \
--enable-zip \
--with-bz2 \
--with-readline
参数说明:

""" 安装路径 """
--prefix=/usr/local/php56 \
""" php.ini 配置文件路径 """
--with-config-file-path=/usr/local/php56/etc \
""" 优化选项 """
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
"""Enable opcache, default is 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 服务,soap 依赖 libxml """
--enable-soap \
--with-libxml-dir \
"""Processes, Signals and Memory""" \ --enable-sysvmsg \ --enable-sysvsem --enable-shmop \
--enable-pcntl \



--enable-sysvshm \
""" socket & curl """
--enable-sockets \
--with-curl \
""" Compress and archive"""
--with-zlib \
--enable-zip \
-- with-bz2 \
""" GNU Readline command line shortcut key bindings"""
--with-readline
If your Web Server uses Apache, please add something like: --with-apxs2=/usr/local/apache-xx/ bin/apxs parameter.

About mysqlnd, please check What is the MySQL Native driver for PHP? Or check the official MySQL introduction: MySQL native driver for PHP, or Installation on Unix.

PHP 5.6 has a built-in phpdbg interactive debugger, which can be enabled by --enable-phpdbg, and a phpdbg command will be generated in the PREFIX/bin directory. You can try it if you are interested.

For more compilation parameters, please use . /configure --help View.

# make -j8
# make install
If you want to reinstall:

# make clean
# make clean all

# ./configure ...
# make -j8
# make install
Configure PHP
configuration files:

# cp php.ini-development /usr/local/php56/etc/php.ini
php-fpm service

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

# service php-fpm56 start
Starting php-fpm done
php-fpm Available parameters start|stop|force-quit|restart|reload|status

Add PHP commands to environment variables
Edit ~/.bash_profile, add :

Change PATH=$PATH:$HOME/bin
to:
PATH=$PATH:$HOME/bin:/usr/local/php56/bin
Make PHP environment variables take effect:

# . ~/.bash_profile
View PHP version

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327058857&siteId=291194637