- PHP编译安装
yum -y install epel-release #安装epel源
yum -y install gcc gcc-c++ make pcre pcre-devel zlib zlib-devel openssl openssl-devel libxml2 libxml2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel openldap openldap-devel libmcrypt libmcrypt-devel #安装依赖包
cd /usr/loacl/src/
wget http://hk1.php.net/distributions/php-5.6.40.tar.gz #下载php安装包
tar -zxf php-5.6.40.tar.gz
cd php-5.6.40
./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --enable-ctype --with-mysqlnd --with-mysqli=mysqlnd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --with-gd --enable-gd-native-tty --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-ldap-sasl --with-xmlrpc --enable-zip --enable-soap --with-gettext --enable-fpm #检查配置环境
make && make install #编译安装
cp php.ini-production /usr/local/php/etc/php.ini #复制默认配置文件到php安装目录下的etc下
vim /etc/profile #在环境变量配置文件末行加入一下内容
export PATH=$PATH:/usr/local/php/sin/:/usr/local/php/bin/
source /etc/profile #重新加载环境变量配置文件
php -v #查看php版本
cd /usr/local/php/etc/ #进入php下的etc配置目录
cp php-fpm.conf.default php-fpm.conf #cp默认配置
查看php-fpm.conf的listen配置,默认是127.0.0.1:9000
vim /usr/lib/systemd/system/php.fpm.service #配置systemctl管理php-fpm,添加一下内容
[Unit]
Description=php-rpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=multi-user.target
systemctl start php-fpm #启动php-fpm
netstat -tulnp|grep php-fpm #查看是否监听9000端口
ps -auxfww|grep php-fpm #查看php-fpm进程
-
php-fpm是用于连接nginx和php,有两种工作方式
1、socket
2、网络方式(默认方式,监听127.0.0.1:9000端口) -
nginx的默认配置无法出来php程序,在nginx的html目录下创建一个test.php文件,游览器访问192.168.1.84/test.php发现无法显示(192.168.1.84为nginx服务器)
vim /usr/local/nginx/html/test.php <?php echo"test.html" ?>
修改nginx默认配置文件,在location里面的index.htm后面加入index.php,再把location ~ .php$ 项目取消注释,修改
/scripts$fastcgi_script_name;为 d o c u m e n t r o o t document_root documentrootfastcgi_script_name;vim /usr/local/nginx/conf/nginx.conf server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { root html; index index.html index.htm indexphp; } location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }
修改后再访问192.168.1.84/test.php则可以正常访问