服务器ecs上本来跑了一套nginx+php5.5,由于新项目使用的是laravel5.4,所以不得不把php升级,在此记录下在此安装的过程和遇到的问题,总体来说还算顺利
cd /usr/local/src
切换到自己的安装目录,我下载的是http://php.net/get/php-7.1.4.tar.xz/from/a/mirror,php-7.1.4.tar.gz
tar zxvf php-7.1.4.tar.gz #解压后 cd php-7.1.4/ #切换到解压目录
接着编译:
./configure --prefix=/usr/local/php7 --with-curl --with-freetype-dir --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
--with-png-dir
--with-freetype-dir
--with-jpeg-dir
--with-gd --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
如果配置错误,需要安装需要的模块
sudo apt-get install -y autoconf libtool re2c libxml2-dev openssl libcurl4-openssl-dev libbz2-dev libjpeg-dev libpng12-dev libfreetype6-dev libldap2-dev libmcrypt-dev libmysqlclient-dev libxslt1-dev libxt-dev libpcre3-dev libxpm-dev libt1-dev libgmp-dev libpspell-dev librecode-dev libreadline6-dev bison libtidy-dev
如果出错重新编译即可.编译完成后:
##根据Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf ##You may want to add: /usr/local/php7/lib/php to your php.ini include_path ##这个信息,我们需要在当前 php7目录下执行 cp php.ini-development /usr/local/php7/lib/php.ini (下面会有介绍) 到至,php7-fpm安装成功
接着复制备份文件:
cp php.ini-development /usr/local/php7/lib/php.ini cp /usr/local/php7/etc/php-fpm.conf.default /usr/local/php7/etc/php-fpm.conf cp -R /usr/local/php7/etc/php-fpm.d/www.conf.default /usr/local/php7/etc/php7-fpm.d/www.conf cp -R ./sapi/fpm/php-fpm /etc/init.d/php7-fpm
启动php:
/etc/init.d/php7-fpm
出现
因为启动用户的默认用户组为nobody,我们加个用户组
groupadd nobody
OK,php7-fpm启动成功
顺便配置下nginx搭配php7
我滴配置如下:
server { listen 80; server_name localhost xxxxxx.com ; location / { root /home/www/test; index index.html index.htm index.php; #try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { root /home/www/test; fastcgi_pass 127.0.0.1:9000; #这里是重点额 fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
检测下配置是否正确: /usr/sbin/nginx -t 如果没错后执行: service nginx reload
最终运行结果:
补充:上面如果编译GD库失败:可以执行:sudo apt-get install php7.1-gd