说在前面:
本人系统ubuntu12.04 64位,先前编译安装有php5.5.7版本,现在为了满足composer对php的版本要求特尝试安装php7,使用的用户为www先前已经添加。
安装依赖库:
apt-get install libxml2-dev openssl libjpeg-dev libpng-dev libcurl3-openssl-dev libfreetype6-dev libxslt-dev
指定下载目录并下载源码:
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
解压进入目录:
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
编译:
#防止网络中断带来不必要的麻烦可以使用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
复制配置文件:
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
启动成功
Starting php-fpm done
开机自启动:
echo "/etc/init.d/php-fpm70 start" >> /etc/rc.locale