本文主要记录 PHP7+Nginx的编译 以及 环境搭建 的操作步骤

1.获取 PHP 指定版本,下载地址可以在这个页面找到:

sudo wget http://cn2.php.net/distributions/php-7.0.7.tar.xz
tar -xvf php-7.0.7.tar.xz

2.安装:

sudo apt-get update
sudo apt-get install nginx mysql-client-core-5.6 git libxml2-dev build-essential openssl libssl-dev make curl libcurl4-gnutls-dev libjpeg-dev libpng-dev libmcrypt-dev libreadline6 libreadline6-dev libjpeg-dev libpng-dev libgmp-dev
sudo ln -s /usr/include/x86_64-linux-gnu/gmp.h /usr/include/gmp.h
cd php-7*

3. 编译

sudo ./configure –prefix=/usr/local/php7.0.7 –enable-fpm –enable-inline-optimization –disable-debug –disable-rpath –enable-shared –enable-opcache –with-gmp  –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
//中间可能会出现 configure: WARNING: unrecognized options: –with-mysql, –enable-bz2
sudo make
sudo make install
sudo ln -s /usr/local/php7.0.7 /usr/local/php
sudo cp php.ini-production /usr/local/php/lib/php/php.ini

4. 配置php-fpm

cd /usr/local/php/etc
sudo cp php-fpm.conf.default php-fpm.conf
cd /usr/local/php/etc/php-fpm.d
sudo cp www.conf.default www.conf
sudo vim www.conf

修改

user = www-data
group = www-data

如果www-data用户不存在,那么先添加www-data用户

groupadd www-data
useradd -g www-data www-data

5. 启动php-fpm

sudo /usr/local/php/sbin/php-fpm

加入系统变量

sudo echo “PATH=$PATH:/usr/local/php/bin”>> /etc/profile
sudo echo “export PATH”>> /etc/profile
source /etc/profile

6. NGINX配置

cd /etc/nginx/sites-enabled
vim default

找到下面的配置, 把注释打开

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have “cgi.fix_pathinfo = 0;” in php.ini
        # With php5-cgi alone:
        fastcgi_pass 127.0.0.1:9000;
        # With php5-fpm:
        #fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
}
sudo service nginx reload
cd /usr/share/nginx/html

写一个index.php 即可看到效果

最后:注意腾讯云安全组的问题,要把对外80端口打开