Centos部署PHP

环境:Centos7

安装PHP步骤:

一:安装依赖

复制代码
yum install epel-release -y

yum install gcc openssl-devel libxml2-devel bzip2-devel libmcrypt-devel sqlite-devel oniguruma-devel -y

二:下载php源码⽂件

复制代码
 cd /usr/local/src

 wget https://www.php.net/distributions/php-7.4.11.tar.xz

三:编译安装php

复制代码
tar xf php-7.4.11.tar.xz

cd php-7.4.11

./configure --prefix=/usr/local/php74 -enable-mysqlnd--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-zlib --with-config-file-path=/etc/php74 --with-config-file-scan-dir=/etc/php.d --enable-mbstring --enable-xml --enable-sockets -enable-fpm --enable-maintainer-zts --disable-fileinfo

make && make install

四:⽣成配置⽂件

复制代码
cp /usr/local/src/php-7.4.11/php.ini-production

/etc/php.ini

cd /usr/local/php74/etc/
 
cp php-fpm.conf.default php-fpm.conf

cd php-fpm.d/

cp www.conf.default www.conf

grep '^[^;]' www.conf
[www]
user = nginx
group = nginx
listen = 127.0.0.1:9000
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

五:创建访问⽇志路径

复制代码
mkdir -p /usr/local/php74/log

六: 启动并验证php

复制代码
 /usr/local/php74/sbin/php-fpm -t
[24-Feb-2023 21:16:06] NOTICE: configuration file /usr/local/php74/etc/php-fpm.conf
test is successful

 cp -a /usr/local/src/php-7.4.11/sapi/fpm/php-
fpm.service /usr/lib/systemd/system/

 systemctl daemon-reload

 systemctl enable --now php-fpm
Created symlink from /etc/systemd/system/multi-user.target.wants/php-fpm.service to
/usr/lib/systemd/system/php-fpm.service.

 ss -lntp|grep 9000
LISTEN   0    128   127.0.0.1:9000           *:*         
users:(("php-fpm",pid=124723,fd=8),("php-fpm",pid=124722,fd=8),("php-
fpm",pid=124721,fd=6))

七:配置nginx⽀持fastcgi

复制代码
vim /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes  1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid    logs/nginx.pid;
events {
 worker_connections  1024;
}
http {
 include    mime.types;
 default_type application/octet-stream;
 sendfile    on;
 keepalive_timeout  65;
 server {
   listen    80;
   server_name localhost;
   location / {
     root  /data/wordpress;  #指定wordpress⽬录
     index index.php index.html index.htm;  #指定默认主⻚
   }
   error_page  500 502 503 504 /50x.html;
   location = /50x.html {
     root  html;
   }
   
   location ~ \.php$ {  #实现php-fpm
     root      /data/wordpress;
     fastcgi_pass  127.0.0.1:9000;
     fastcgi_index index.php;
     fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include    fastcgi_params;
   }
 }
}

cd /usr/local/nginx/sbin/

 ./nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

systemctl restart nginx

八:测试php

复制代码
mkdir -p /data/wordpress

cd /data/wordpress/

 vim test.php
<?php
phpinfo();
?>
相关推荐
Starry_hello world44 分钟前
进程的替换
linux·笔记·有问必答
拥友LikT2 小时前
惠普DL380服务器安装系统以后无法读取到系统盘启动解决方案(其他品牌服务器类似解决思路)
linux·服务器系统安装
程序猿编码2 小时前
Linux 文件变动监控工具:原理、设计与实用指南(C/C++代码实现)
linux·c语言·c++·深度学习·inotify
网硕互联的小客服2 小时前
SSD和HDD存储应该如何选择?
linux·运维·服务器·网络·安全
lemon3106242 小时前
浪潮服务器装linux系统步骤
linux·运维·服务器
gugugu.2 小时前
Linux进程:进程状态
linux·运维·服务器
Wang's Blog2 小时前
Linux小课堂: Apache虚拟主机配置之基于IP与域名的服务器部署指南
linux·服务器·apache
Wang's Blog2 小时前
Linux小课堂: Apache服务在CentOS上的安装与基础配置指南
linux·centos·apache
我爱钱因此会努力2 小时前
ansible实战- 循环创建多个用户
运维·服务器·centos
广药门徒2 小时前
Linux 驱动开发中,主设备号和次设备号不同的两个驱动能否正常工作
linux·运维·驱动开发