CentOS源码安装PHP
1.准备工作:
下载php源码包:
wget https://www.php.net/distributions/php-7.2.19.tar.gz (官网下载慢可用百度网盘下载)
2.下载依赖工具:
# yum -y install gcc libxml2 libxml2-devel openssl openssl-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
3.配置php:
# tar -xvf php-7.2.19.tar.gz -C /usr/local
# cd /usr/local/php-7.2.19
#./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php --enable-sockets --enable-fpm --enable-cli --enable-mbstring --enable-pcntl --enable-soap --enable-opcache --disable-fileinfo --disable-rpath --with-mysqli --with-pdo-mysql --with-iconv-dir --with-openssl --with-fpm-user=www --with-fpm-group=www --with-curl --with-mhash --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-zip --with-zlib --enable-simplexml --with-libxml-dir
4.编译安装:
# make && make install
5.配置php.ini
安装目录/usr/local/php/etc
解压目录/usr/local/php-7.2.19
复制文件(/usr/local/php-7.2.19) 同时重命名为php.ini复制到安装目录下
[root@localhost php-7.2.19]# cp php.ini-production /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini date.timezone = PRC (取消注释)
6.配置php-fpm.conf
[root@localhost etc]# cd /usr/local/php/etc [root@localhost etc]# ls pear.conf php-fpm.conf.default php-fpm.d php.ini
[root@localhost etc]# cp php-fpm.conf.default php-fpm.conf [root@localhost etc]# ls pear.conf php-fpm.conf php-fpm.conf.default php-fpm.d php.ini
[root@localhost etc]# vim php-fpm.conf
pid = run/php-fpm.pid #取消前面的分号
7.php-fpm配置文件www.conf
[root@localhost php-fpm.d]# cd /usr/local/php/etc/php-fpm.d
[root@localhost php-fpm.d]# cp www.conf.default www.conf (复制一份www.conf文件)
[root@localhost php-fpm.d]# vim www.conf (如有用户问题可以修改user=nginx,group=nginx)
8.启动php-fpm
# /usr/local/php/sbin/php-fpm
开机自启php-fpm
1.进入系统服务目录
cd /lib/systemd/system
2.编辑服务文件
# vim php-fpm.service [Unit] Description=The PHP FastCGI Process Manager Documentation=http://php.net/docs.php After=network.target [Service] Type=simple PIDFile=/usr/local/php/var/run/php-fpm.pid ExecStart=/usr/local/php/sbin/php-fpm --nodaemonize --fpm-config /usr/local/php/etc/php-fpm.conf ExecReload=/bin/kill -USR2 $MAINPID LimitNOFILE=1000000 LimitNPROC=1000000 LimitCORE=1000000 [Install] WantedBy=multi-user.target
3.启动服务
# systemctl enable php-fpm
# systemctl start php-fpm
配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
http { server { 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; } ... }
测试index.php 新建文件vi index.php(目录/usr/local/nginx/html) <?php phpinfo();?>
# vim /usr/local/nginx/html/index.php <? phpinfo(); ?>