Linux的PHP安装配置教程
一、下载安装包
下载地址:PHP安装包下载界面
二、安装PHP
1.安装依赖包和扩展包
yum install libxml2 libxml2-devel libjpeg libjpeg-devel libpng libpng-devel curl curl-devel gd gd-devel freetype freetype-devel zlib zlib-devel perl httpd-devel sqlite-devel autoconf automake libtool
2.安装软件
按顺序输入以下命令
tar xzvf php-8.0.8.tar.gz
cd php-8.0.8/
./configure --enable-fpm --enable-mbstring --prefix=/usr/local/php --with-mysql-sock --with-mysqli --with-pdo-mysql --with-zlib --with-curl
发现问题
上传文件oniguruma-6.9.4.tar.gz
tar xzvf oniguruma-6.9.4.tar.gz
cd oniguruma-6.9.4/
./autogen.sh
./configure --prefix=/usr/local/oniguruma --libdir=/lib64
make && make install
安装好后重新进入文件夹重新执行配置命令
结果如下:
继续执行以下命令
make && make install
结果如下:
3.修改配置
获取配置文件并将其移动到正确的位置,执行以下命令
cp php.ini-development /usr/local/php/php.ini
cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
cp sapi/fpm/php-fpm /usr/local/bin
vim /usr/local/php/php.ini
#找到`cgi.fix_pathinfo=`并修改如下:
cgi.fix_pathinfo=0
vim /usr/local/php/etc/php-fpm.d/www.conf
#修改下列设置
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
; will be used.
user = www
group = www
vim /usr/local/php/etc/php-fpm.conf
#修改下列配置
[global]
; Pid file
; Note: the default prefix is /usr/local/php/var
; Default Value: none
pid = run/php-fpm.pid
4.设置php开机自启动
建立服务文件
vim /usr/lib/systemd/system/php.service
#新建文件,把下面文件内容放到文件中
[Unit]
Description=php
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/bin/php-fpm
ExecReload=kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
ExecStop=kill -INT `cat /usr/local/php/var/run/php-fpm.pid`
PrivateTmp=true
[Install]
WantedBy=multi-user.target
保存退出后,执行以下命令来设置开机自启动
systemctl daemon-reload
systemctl enable php
systemctl start php
5.PHP相关命令
#加入开机自启动
systemctl enable php
#取消开机自启动
systemctl disable php
#启动服务
systemctl start php
#停止服务
systemctl stop php
#重启服务
systemctl restart php
#查看服务当前状态
systemctl status php
#查看开机已启动是否设置成功
systemctl list-units --type=service |grep php
评论区