Linux系统安装nginx和php-fpm
安装nginx
步骤
安装epel源
yum -y install epel-release
安装nginx
yum -y install nginx
启动并设置开机启动
启动nginx:
systemctl start nginx.service
设置开机启动:
systemctl enable nginx.service
检查安装版本:
nginx -v
其他nginx相关命令:
systemctl status nginx # 查看nginx运行状态systemctl start nginx # 启动nginxsystemctl stop nginx # 停止nginxsystemctl restart nginx # 强制重启nginxps -aux | grep -v grep | grep nginx | grep master | awk '{print $12}' # 查看nginx服务,返回master则代表正在运行
安装php-fpm
具体步骤
下载安装包php安装包。自行选择php版本,这里以php-7.4.33.tar.gz为例
官网地址
解压安装包
tar -zxvf php-7.4.33.tar.gz
预安装配置
yum install gcc-c++ libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel gd sqlite sqlite-devel net-snmp net-snmp-devel oniguruma oniguruma-devel
安装perl
yum install -y perl*yum install -y httpd-devel
执行配置命令
./configure --prefix=/usr/local/php \--with-config-file-path=/usr/local/php/etc \--with-mysqli=mysqlnd \--enable-pdo \--with-pdo-mysql=mysqlnd \--with-iconv-dir=/usr/local/ \--enable-fpm \--with-fpm-user=www \--with-fpm-group=www \--with-pcre-regex \--with-zlib \--with-bz2 \--enable-calendar \--disable-phar \--with-curl \--enable-dba \--with-libxml-dir \--enable-ftp \--with-gd \--with-jpeg-dir \--with-png-dir \--with-zlib-dir \--with-freetype-dir \--enable-gd-jis-conv \--with-mhash \--enable-mbstring \--disable-opcache \--enable-pcntl \--enable-xml \--disable-rpath \--enable-shmop \--enable-sockets \--enable-zip \--enable-bcmath \--with-snmp \--disable-ipv6 \--with-gettext \--disable-rpath \--disable-debug \--enable-embedded-mysqli \--with-mysql-sock=/usr/local/mysql \--with-apxs2=/usr/bin/apxs
编译安装
make && make install
生成配置文件
cp php.ini-production /usr/local/php/php.ini
切换到安装目录
cd /usr/local/php/etc/ # 切换到安装目录的etc下cp php-fpm.conf.default php-fpm.conf # 复制一个新的配置文件vim php-fpm.conf # 编辑配置文件,将;pid = run/php-fpm.pid中的;删掉。如果vim报错则使用vi即可cp www.conf.default www.confgroupadd wwwuseradd -g www www
启动php-fpm
/usr/local/php/sbin/php-fpm # 如出现报错,根据内容具体搜索,正常情况不会出现报错
配置环境变量
找到安装目录下的bin目录。当前教程的目录为:/usr/local/php/bin
vim /usr/local/php/bin # 修改内容 # 在export PATH那一行上面,添加:PATH=$PATH:$HOME/bin:/usr/local/php/bin# 先按esc,然后按shift+:,输入wq保存退出source /etc/profile # 刷新环境变量
将php-fpm服务加入到系统服务中可以用systemctl操作
cd /usr/loacl/php-7.4.33/sapi/fpm/ # 到解压目录中的fpm目录中cp php-fpm.service /usr/lib/systemd/system/ # 复制php-fpm.service文件vi /usr/lib/systemd/system/php-fpm.service # 编辑文件# 将ProtectSystem=full修改为ProtectSystem=false
扩展命令
ps -aux|grep php-fpm # 查看php-fpm进程kill -INT `cat /usr/local/php/var/run/php-fpm.pid` # 关闭php-fpmkill -USR2 `cat /usr/local/php/var/run/php-fpm.pid` # 重启php-fpm# 第二个参数选项值:# INT, TERM 立刻终止# QUIT 平滑终止# USR1 重新打开日志文件# USR2 平滑重载所有worker进程并重新载入配置和二进制模块# 以下3个命令均在配置好systemctl操作后才可使用systemctl status php-fpm.service # 查看服务状态systemctl start php-fpm.service # 开启服务systemctl stop php-fpm.service # 关闭服务
参考文献
php:
安装教程
环境变量及systemctl操作php的配置
nginx:
安装教程
来源地址:https://blog.csdn.net/qq_38871632/article/details/128018453