> ### Centos7编译安装PHP ``` [root@localhost local]# yum -y install libxml2 libxml2-devel gd gd-devel [root@localhost local]# wget http://cn2.php.net/distributions/php-7.2.0.tar.gz [root@localhost local]# tar -zxvf php-7.2.0.tar.gz [root@localhost local]# cd php-7.2.0 [root@localhost php-7.2.0]# ./configure \ --prefix=/usr/local/php \ --with-config-file-path=/usr/local/php/etc \ --with-gd \ --enable-pdo \ --with-openssl \ --with-mysqli=mysqlnd \ --with-pdo-mysql=mysqlnd \ --enable-mysqlnd-compression-support \ --enable-mbstring \ --enable-zip \ --enable-fpm [root@localhost php-7.2.0]# make && make install [root@localhost php-7.2.0]# cp php.ini-production /usr/local/php/etc/php.ini [root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost php-7.2.0]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf [root@localhost php-7.2.0]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-7.2.0]# chmod +x /etc/init.d/php-fpm [root@localhost php-7.2.0]# ln -s /etc/init.d/php-fpm /usr/bin/ [root@localhost ~]# vim /etc/profile export PATH=/usr/local/php/bin:$PATH #最后面添加 [root@localhost ~]# source /etc/profile [root@localhost ~]# php -v ``` > ### 配置Nginx ``` [root@localhost conf]# cat > /usr/local/nginx/conf/nginx.conf << EOT worker_processes 1; error_log logs/error.log; pid logs/nginx.pid; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; include vhosts.conf; } EOT [root@localhost conf]# vim /usr/local/nginx/conf/vhosts.conf server { listen 80; server_name localhost; root /usr/local/www/html; access_log logs/host.access.log; location / { autoindex on; } location ~ \.php$ { fastcgi_index index.php; fastcgi_pass 127.0.0.1:9000; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; } } [root@localhost conf]# nginx -c /usr/local/nginx/conf/nginx.conf ``` > ### 测试 ``` 参数 start|stop|force-quit|restart|reload|status|configtest [root@localhost /]# php-fpm start 启动 ``` ------ ``` [root@localhost /]# vim /usr/local/www/html/test2.php <?php //可以查看配置信息 echo phpinfo(); ?> ``` ![img](https://www.kancloud.cn/book/xiaohuamao/source-open-a/preview/images/218.png)