系統環境:php
# wget http://cn2.php.net/get/php-5.6.26.tar.gz/from/this/mirror -O php56.tar.gz # xz -d php56.tar.xz # tar xf php56.tar -C /usr/local/src/
# 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 sqlite-devel
注:若是你使用的 epel 7
的源,可能會沒有 mcrypt mhash mhash-devel
幾個包,在http://dl.fedoraproject.org/pub/epel/6/x86_64/
中下載,使用 yum localinstall xxx.rpm
或 rpm -Uvh xxx.rpm
手動安裝便可。mysql
# 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-gd \
--enable-gd-native-ttf\
--with-readline
參數說明:linux
""" 安裝路徑 """ --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
--with-gd
若是你的 Web Server 使用的 Apache 請添加相似:--with-apxs2=/usr/local/apache-xx/bin/apxs
參數。sql
關於 mysqlnd
請查看 什麼是 PHP 的 MySQL Native 驅動? 或查看 MySQL 官方介紹:MySQL native driver for PHP, 或 Installation on Unix。apache
PHP 5.6 內建了 phpdbg 交互式調試器,經過 --enable-phpdbg
開啓,會在 PREFIX/bin
目錄下產生一個 phpdbg 命令,感興趣的能夠試一下。api
更多編譯參數請使用 ./configure --help
查看。bash
# make -j8 # make install
若是想從新安裝:curl
# make clean # make clean all # ./configure ... # make -j8 # make install
配置文件:socket
# cp php.ini-development /usr/local/php56/etc/php.ini
php-fpm 服務php-fpm
# 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
cp /usr/local/php56/etc/php-fpm.conf.default php-fpm.conf
chkconfig --add php-fpm56
啓動 php-fpm
# service php-fpm56 start Starting php-fpm done
php-fpm 可用參數 start|stop|force-quit|restart|reload|status
編輯 ~/.bash_profile
,將:
PATH=$PATH:$HOME/bin 改成: PATH=$PATH:$HOME/bin:/usr/local/php56/bin
使 PHP 環境變量生效:
# . ~/.bash_profile
查看看 PHP 版本
# php -v PHP 5.6.0 (cli) (built: Sep 23 2014 03:44:18) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2014 Zend Technologies
轉載請註明出處。
本文地址:http://blog.aboutc.net/linux/65/compile-and-install-php-on-linux