003-LNMP之PHP环境搭建
2021-01-28 02:13
标签:mct fastcgi evel php编译安装 listen param define libmcrypt yum 正文: php官网:https://www.php.net/ 搜狐镜像源:http://mirrors.sohu.com/ (推荐,国内源下载速度嗖嗖的) 1.php编译安装前解决依赖包 2.源码编译安装php 3.php编译安装说明 4.启动php-fpm 5.验证php-fpm的启动 1.进程 2.端口 3.日志 6.使用systemctl管理php-fpm 7.nginx默认配置无法处理php程序,只会下载,需要改配置文件nginx.conf 8.nginx+php-fpm结合的配置 9.页面test.php访问测试
常见问题: 1、运行systemctl start php-fpm报错 解决方法: 003-LNMP之PHP环境搭建 标签:mct fastcgi evel php编译安装 listen param define libmcrypt yum 原文地址:https://www.cnblogs.com/chenshengkai/p/13216154.htmlyum -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 sqlite sqlite-devel oniguruma-devel oniguruma
./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-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
# 在/usr/local/php/etc目录下,默认是没有php.ini这个配置文件的,需要拷贝一个过去。
# 拷贝的文件路径/usr/local/src/php-7.4.7
cp /usr/local/src/php-7.4.7/php.ini-production /usr/local/php/etc/php.ini
--prefix 指定php的安装目录
--with-config-file-path 指定php的配置文件位置
--with-mysql 让php可以操作mysql
--enable-fpm 主要是nginx要来调用php语言使得php-fpm
# 环境变量
export PATH=$PATH:/usr/local/php/sbin/:/usr/local/php/bin/
# 检查配置文件
php-fpm -t
# 使用默认配置文件
mv /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# 查看php-fpm的listen配置
# 创建配置文件的路径
vi /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
# 写一个test.php测试
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
# 修改默认的/scripts为$document_root,去root->html下面找页面
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
[30-Jun-2020 18:34:23] WARNING: Nothing matches the include pattern ‘/usr/local/php/etc/php-fpm.d/*.conf‘ from /usr/local/php/etc/php-fpm.conf at line 125.
[30-Jun-2020 18:34:23] ERROR: No pool defined. at least one pool section must be specified in config file
[30-Jun-2020 18:34:23] ERROR: failed to post process the configuration
[30-Jun-2020 18:34:23] ERROR: FPM initialization failed
# cd /usr/local/php/etc/php-fpm.d/
# cp www.conf.default www.conf
# /usr/local/php/sbin/php-fpm -t
[30-Jun-2020 18:35:29] NOTICE: configuration file /usr/local/php/etc/php-fpm.conf test is successful
[root@localhost php-fpm.d]# systemctl start php-fpm
Starting php-fpm done