在 Ubuntu 16.04 下原始碼編譯安裝 PHP7 過程記錄。
一、下載 PHP7 的最新版原始碼
php7.0.9 下載地址 http://php.net/get/php-7.0.9.tar.gz/from/a/mirror
二、解壓
tar -zxf /tmp/php-7.0.9.tar.gz
三、安裝相關依賴庫
sudo apt-get update
sudo apt-get install libxml2-dev
#安裝 gcc
sudo apt-get install build-essential
sudo apt-get install openssl
sudo apt-get install libssl-dev
sudo apt-get install make
sudo apt-get install curl
sudo apt-get install libcurl4-gnutls-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libpng-dev
sudo apt-get install libmcrypt-dev
sudo apt-get install libreadline6 libreadline6-dev
四、編譯:(編譯引數 2 箇中選擇一個,第一段大部分機器即可編譯,第二段引數推薦 64 位 x86 系統編譯)
cd /tmp/php-7.0.9
./configure –prefix=/usr/local/php –with-config-file-path=/usr/local/php/etc –enable-fpm –with-fpm-user=www –with-fpm-group=www –with-mysqli –with-pdo-mysql –with-iconv-dir –with-freetype-dir –with-jpeg-dir –with-png-dir –with-zlib –with-libxml-dir=/usr –enable-xml –disable-rpath –enable-bcmath –enable-shmop –enable-sysvsem –enable-inline-optimization –with-curl –enable-mbregex –enable-mbstring –with-mcrypt –enable-ftp –with-gd –enable-gd-native-ttf –with-openssl –with-mhash –enable-pcntl –enable-sockets –with-xmlrpc –enable-zip –enable-soap –without-pear –with-gettext –disable-fileinfo –enable-maintainer-zts
cd /tmp/php-7.0.9
./configure –prefix=/usr/local/php –enable-fpm –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-opcache –with-mysql –with-mysqli –with-mysql-sock –enable-pdo –with-pdo-mysql –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 –enable-bz2 –with-readline –without-sqlite3 –without-pdo-sqlite –with-pear –with-libdir=/lib/x86_64-linux-gnu –with-gd –with-jpeg-dir=/usr/lib –enable-gd-native-ttf –enable-xml
五、執行 make 和 sudo make install 安裝
make && sudo make install
六、配置 php-fpm
cd /usr/local/php/etc
cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
cp www.conf.default www.conf
user = www
group = www
如果 www 使用者不存在,那麼先新增 www 使用者
groupadd www
useradd -g www www
七、驗證 PHP
/usr/local/php/bin/php -v
八、啓動 php-fpm
sudo /usr/local/php/sbin/php-fpm