1. 程式人生 > >Linux 下編譯安裝 PHP 5.6

Linux 下編譯安裝 PHP 5.6

系統環境:

  • CentOS 6.5 / 7.0 x86_64
  • Fedora 20 x86_64

下載 PHP 原始碼包

wget http://cn2.php.net/distributions/php-5.6.0.tar.xzxz -d php-5.6.0.tar.xztar xf php-5.6.0.tar -C /usr/local/src/

新增 epel 源

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

安裝依賴

apt-get install libxml2-dev libssl-dev libbz2-dev libcurl3-dev libdb5.1-dev libjpeg-dev libpng-dev libXpm-dev libfreetype6-dev libt1-dev libgmp3-dev libc-client-dev libldap2-dev libmcrypt-dev libmhash-dev freetds-dev libz-dev libmysqlclient15-dev ncurses-dev libpcre3-dev unixODBC-dev postgresql-server-dev-9.1 libsqlite-dev libaspell-dev libreadline6-dev librecode-dev libsnmp-dev libtidy-dev libxslt-dev libt1-dev

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 jemalloc jemalloc-devel
./configure --with-php-config=/usr/local/php/bin/php-config --enable-jemalloc

注:如果你使用的 epel 7 的源,可能會沒有 mcrypt mhash mhash-devel

 幾個包,在 http://dl.fedoraproject.org/pub/epel/6/x86_64/ 中下載,使用 yum localinstall xxx.rpm 或 rpm -Uvh xxx.rpm 手動安裝即可。

建立 www 使用者

groupadd wwwuseradd -g www -s /sbin/nologin -M www

編譯安裝

cd /usr/local/src/php-5.6.0/./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/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 \
""" 啟用 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 服務,soap 依賴 libxml """--enable-soap \
--with-libxml-dir \
""" 程序,訊號及記憶體 """--enable-pcntl \
--enable-shmop \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
""" socket & curl """--enable-sockets \
--with-curl \
""" 壓縮與歸檔 """--with-zlib \
--enable-zip \
--with-bz2 \
""" GNU Readline 命令列快捷鍵繫結 """--with-readline

如果你的 Web Server 使用的 Apache 請新增類似:--with-apxs2=/usr/local/apache-xx/bin/apxs 引數。

PHP 5.6 內建了 phpdbg 互動式偵錯程式,通過 --enable-phpdbg 開啟,會在 PREFIX/bin 目錄下產生一個 phpdbg 命令,感興趣的可以試一下。

更多編譯引數請使用 ./configure --help 檢視。

# make && make install

如果想重新安裝:

make cleanmake clean all./configure ...make && make install

配置 PHP

配置檔案

cp php.ini-development /usr/local/php/etc/php.ini

php-fpm 服務

cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.confcp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpmchmod +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.6.0(cli)(built:Sep23201403:44:18)Copyright(c)1997-2014The PHP GroupZendEngine v2.6.0,Copyright(c)1998-2014ZendTechnologies