php+apache环境搭建
【先安装apache】
apache快速安装:https://www.cnblogs.com/brad93/p/16718104.html
PHP安装教程参考:https://www.cnblogs.com/kyuang/p/6801942.html
1、安装基础环境:
yum -y install gcc libxml2 libxml2-devel sqlite-devel libcurl-devel.x86_64 php-gd libpng libpng-devel &&yum -y install oniguruma oniguruma-devel
安装(下载地址:https://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/)
2、libmcrypt、oniguruma安装:
cd /usr/local && wget https://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz && tar -zxvf libmcrypt-2.5.8.tar.gz && cd libmcrypt-2.5.8/ && ./configure –prefix=/usr/local/libmcrypt && make && make install && cd .. && rm -rf libmcrypt-2.5.8 && rm -rf libmcrypt-2.5.8.tar.gz &&cd /usr/local && wget http://down.24kplus.com/linux/oniguruma/oniguruma-6.9.4.tar.gz &&tar -zxf oniguruma-6.9.4.tar.gz && cd oniguruma-6.9.4 && ./autogen.sh && ./configure -disable-fileinfo –prefix=/usr && make && make install && cd .. && rm -rf oniguruma-6.9.4.tar.gz && rm -rf oniguruma-6.9.4
3、安装php(下载地址:https://www.php.net/downloads.php)(安装位置:/usr/local/php)
cd /usr/local/ && wget https://www.php.net/distributions/php-7.4.30.tar.gz && tar -zxvf php-7.4.30.tar.gz && cd /usr/local/php-7.4.30 && ./configure -disable-fileinfo –with-apxs2=/usr/local/apache2/bin/apxs –prefix=/usr/local/php –with-curl –enable-zip –with-zlib –with-zlib-dir –enable-ftp –with-openssl –enable-mysqlnd –with-mysqli –with-pdo-mysql=mysqlnd –enable-mbstring –enable-fpm && make && make install &&cd .. &&rm -rf php-7.4.30.tar.gz
4、为php提供配置文件(在安装目录下拷贝配置文件放到: /usr/local/php/lib/)
cp /usr/local/php-7.4.30/php.ini-production /usr/local/php/lib/php.ini
5、为php-fpm提供配置文件
创建www用户,已有忽略:groupadd www && useradd -g www www
配置文件修改:(存放位置:/usr/local/php/lib)
cd /usr/local/php/lib && cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/lib/php-fpm.conf && vim php-fpm.conf
在;pid = run/php-fpm.pid下方添加或解掉注释修改为:
pid = /usr/local/php/var/run/php-fpm.pid
cd /usr/local/php/etc/php-fpm.d && cp -r www.conf.default www.conf && vim www.conf
修改子配置内容:(目录在: /usr/local/php/lib/php-fpm.d/)
user = www #启动进程的帐户和组
group = www #启动进程的帐户和组
#测试php-fpm配置
/usr/local/php/sbin/php-fpm -t
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini -y /usr/local/php/lib/php-fpm.conf -t
#启动php-fpm
/usr/local/php/sbin/php-fpm
/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini -y /usr/local/php/lib/php-fpm.conf
启动、重启、停止apache(注意路径)
/usr/local/apache2/bin/apachectl -k start
/usr/local/apache2/bin/apachectl -k restart
/usr/local/apache2/bin/apachectl -k stop
#查看php-fpm运行状态
ps -A | grep php-fpm
#查看9000端口占用情况
netstat -tunlp | grep 9000
查看php.ini配置所在位置:php –ini
解决上面命令无法查询的问题:
export PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
export PATH=$PATH:/usr/local/php/bin
延伸教程“通过启动脚本控制PHP-FPM开关”:(个别情况下能开不能关??)https://www.cnblogs.com/brad93/p/16700749.html