Centos7.5 源码编译安装PHP

安装依赖
yum -y install epel-release
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
 
下载PHP源码版本
cd /data/tools/
wget 'http://hk1.php.net/distributions/php-5.6.40.tar.gz'
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-mysql=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-ttf --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 /data/tools/php-5.6.40/php.ini-production /usr/local/php/etc/php.ini
 
php编译安装说明
--prefix指定php的安装目录
--with-config-file-path指定php的配置文件位置
--with-mysql、--with-mysqli让php可以操作mysql
--enable-fpm主要是nginx要来调用php语言得使用php-fpm
 
修改环境变量
环境变量:
vim /etc/profile ##添加环境变量
export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/
[root@zabbix php-5.6.40]# source /etc/profile ##立即生效
[root@zabbix php-5.6.40]#
[root@zabbix php-5.6.40]# echo $PATH ##查看是否生效
/usr/local/nginx/sbin:/usr/local/nginx/sbin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/php/sbin/:/usr/local/php/bin/
修改php-fpm配置
使用默认配置文件:cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
检查配置文件是否成功:php-fpm -t
查看php-fpm的listen配置
[root@zabbix etc]# cat /usr/local/php/etc/php-fpm.conf | grep 9000
listen = 127.0.0.1:9000 
配置systemctl启动 
vim /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=php-fpm
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/php/sbin/php-fpm
[Install]
WantedBy=multi-user.target
chmod +x /usr/lib/systemd/system/php-fpm.service
在启动服务之前,需要先重载systemctl命令
systemctl daemon-reload
systemctl start php-fpm.service
systemctl enable php-fpm.service
检查php是否启动
 [root@zabbix etc]# ps -ef | grep php
root 21107 1 0 14:15 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 21108 21107 0 14:15 ? 00:00:00 php-fpm: pool www
nobody 21109 21107 0 14:15 ? 00:00:00 php-fpm: pool www
root 21136 13820 0 14:16 pts/1 00:00:00 grep --color=auto php
测试
修改nginx的默认配置与php对接
vim /usr/local/nginx/html/test.php
<?php
  echo " zabbix test";
?>
 
nginx+php-fpm结合的配置
vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.php index.html index.htm;
}
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;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

 重新加载nginx

nginx -s reload

 

posted @ 2019-06-19 20:57  --smile  阅读(725)  评论(0编辑  收藏  举报