linux實踐——編譯安裝PHP7

說在前面:php

  本人系統ubuntu12.04 64位,先前編譯安裝有php5.5.7版本,如今爲了知足composer對php的版本要求特嘗試安裝php7,使用的用戶爲www先前已經添加。mysql

安裝依賴庫:  sql

apt-get install libxml2-dev openssl libjpeg-dev libpng-dev  libcurl3-openssl-dev libfreetype6-dev libxslt-dev

指定下載目錄並下載源碼:  ubuntu

cd /tmp
wget  http://cn2.PHP.net/distributions/php-7.0.5.tar.gz  
#http://cn.php.net/distributions/php-7.0.18.tar.gz

解壓進入目錄:  api

tar zxvf php-7.0.5.tar.gz
cd php-php-7.0.5
mkdir -p /alidata/server/php-7.0.5
ln -s /alidata/server/php-7.0.5 /alidata/server/php70
mkdir -p /alidata/log/php70
touch /alidata/log/php70/php-fpm.log

  

編譯:bash

#防止網絡中斷帶來沒必要要的麻煩可使用screen命令多重視窗管理程序
screen -S installphp7
#若是網絡中斷可用screen -r installphp7恢復現場,exit直接退出screen做業
#顯示目前全部的screen做業 screen -ls
./configure  --prefix=/alidata/server/php70  \
--with-curl \
--with-freetype-dir  \
--with-gd \
--with-gettext  \
--with-iconv-dir  \
--with-kerberos  \
--with-libdir=lib64  \
--with-libxml-dir \
 --with-mysqli  \
--with-openssl  \
--with-pcre-regex  \
--with-pdo-mysql  \
--with-pdo-sqlite  \
--with-pear  \
--with-png-dir  \
--with-xmlrpc  \
--with-xsl \
 --with-zlib  \
--enable-fpm  \
--enable-bcmath  \
--enable-libxml  \
--enable-inline-optimization  \
--enable-gd-native-ttf  \
--enable-mbregex  \
--enable-mbstring  \
--enable-opcache  \
--enable-pcntl  \
--enable-shmop  \
--enable-soap  \
--enable-sockets  \
--enable-sysvsem  \
--enable-xml  \
--enable-zip

安裝,短則幾分鐘長則幾十分鐘視機器速度而定:網絡

make
make install

複製配置文件:php7

cp php.ini-production /alidata/server/php70/etc/php.ini
#adjust php.ini
sed -i 's#; extension_dir = \"\.\/\"#extension_dir = "/alidata/server/php70/lib/php/extensions/no-debug-non-zts-20151012/"#'  /alidata/server/php70/etc/php.ini
sed -i 's#extension_dir = \"\.\/\"#extension_dir = "/alidata/server/php70/lib/php/extensions/no-debug-non-zts-20151012/"#'  /alidata/server/php70/etc/php.ini
sed -i 's/post_max_size = 8M/post_max_size = 64M/g' /alidata/server/php70/etc/php.ini
sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 64M/g' /alidata/server/php70/etc/php.ini
sed -i 's/;date.timezone =/date.timezone = PRC/g' /alidata/server/php70/etc/php.ini
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /alidata/server/php70/etc/php.ini
sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /alidata/server/php70/etc/php.ini
#adjust php-fpm
cp /alidata/server/php70/etc/php-fpm.conf.default /alidata/server/php70/etc/php-fpm.conf
sed -i 's,user = nobody,user=www,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,group = nobody,group=www,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 5,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 35,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,^pm.max_children = 5,pm.max_children = 100,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,^pm.start_servers = 2,pm.start_servers = 20,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,;error_log = log/php-fpm.log,error_log = /alidata/log/php70/php-fpm.log,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /alidata/log/php70/\$pool.log.slow,g'   /alidata/server/php70/etc/php-fpm.conf
sed -i 's,user = nobody,user=www,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,group = nobody,group=www,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,^pm.min_spare_servers = 1,pm.min_spare_servers = 5,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,^pm.max_spare_servers = 3,pm.max_spare_servers = 35,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,^pm.max_children = 5,pm.max_children = 100,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,^pm.start_servers = 2,pm.start_servers = 20,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,;pid = run/php-fpm.pid,pid = run/php-fpm.pid,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,;error_log = log/php-fpm.log,error_log = /alidata/log/php70/php-fpm.log,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
sed -i 's,;slowlog = log/$pool.log.slow,slowlog = /alidata/log/php70/\$pool.log.slow,g'   /alidata/server/php70/etc/php-fpm.d/www.conf
#self start
install -v -m755 ./sapi/fpm/init.d.php-fpm  /etc/init.d/php-php70
/etc/init.d/php-fpm70 start

啓動成功composer

Starting php-fpm  done

  

開機自啓動:curl

echo "/etc/init.d/php-fpm70 start" >> /etc/rc.locale
相關文章
相關標籤/搜索