快捷菜单
常用功能一站直达
更多功能请点顶栏「快捷菜单」
本次gpt的centos7如何部署php7.4,经实际测试是没问题的。
以下是gpt回答
在 CentOS 7 上部署 PHP 7.4 可以通过 Remi 仓库(官方推荐的第三方仓库)来完成。以下是详细步骤:
1sudo yum install epel-release -y
2sudo yum install yum-utils -yRemi 仓库提供了最新的 PHP 版本:
1sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y1sudo yum-config-manager --enable remi-php741sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-opcache php-intl php-soap php-redis -y📌 扩展说明:
php-fpm:用于 Nginx 或 Apache 的 FastCGI 模式php-mysqlnd:MySQL 数据库支持php-gd:图像处理php-mbstring:多字节字符串支持php-curl:HTTP 请求支持php-xml:XML 解析支持php-opcache:PHP 字节码缓存(提升性能)
1php -v输出应类似:
1PHP 7.4.x (cli) (built: ...)编辑 php.ini 文件调整参数:
1sudo vi /etc/php.ini常见优化选项:
1memory_limit = 256M
2upload_max_filesize = 64M
3post_max_size = 64M
4max_execution_time = 300
5date.timezone = Asia/Shanghai如果使用 Nginx,需要启动 PHP-FPM:
1sudo systemctl start php-fpm
2sudo systemctl enable php-fpm检查状态:
1sudo systemctl status php-fpm创建一个测试文件:
1echo "<?php phpinfo(); ?>" | sudo tee /var/www/html/info.php访问:
1http://your-server-ip/info.php
2
3
4http://192.168.1.10/info.php如果看到 PHP 信息页面,说明安装成功。
📌http配置:
cat /etc/nginx/conf.d/imgapi.onedayxyy.cn.conf
1server {
2 listen 80;
3 server_name imgapi.onedayxyy.cn;
4 root /var/www/html;
5 index index.php index.html;
6
7 location ~ \.php$ {
8 fastcgi_pass 127.0.0.1:9000;
9 fastcgi_index index.php;
10 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
11 include fastcgi_params;
12 }
13}
imgapi.onedayxyy.cn这里修改为自己的域名即可。
📌https配置:
cat /etc/nginx/conf.d/imgapi.onedayxyy.cn.conf
1server {
2 listen 80;
3 server_name imgapi.onedayxyy.cn;
4 #配置https重定向
5 return 301 https://$host$request_uri;
6}
7
8server {
9 listen 443 ssl;
10 server_name imgapi.onedayxyy.cn;
11 root /images/imgapi;
12 index index.php index.html;
13
14 location ~ \.php$ {
15 fastcgi_pass 127.0.0.1:9000;
16 fastcgi_index index.php;
17 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
18 include fastcgi_params;
19 }
20
21
22
23 ssl_certificate /etc/letsencrypt/live/onedayxyy.cn/fullchain.pem;
24 ssl_certificate_key /etc/letsencrypt/live/onedayxyy.cn/privkey.pem;
25
26 ssl_session_timeout 5m;
27 ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
28 ssl_ciphers EECDH+CHACHA20:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
29 ssl_prefer_server_ciphers on;
30 add_header Strict-Transport-Security "max-age=31536000";
31
32 access_log /var/log/nginx/photo.onedayxyy.cn.https.log;
33}
1sudo rm /var/www/html/info.php1sudo firewall-cmd --permanent --add-service=http
2sudo firewall-cmd --permanent --add-service=https
3sudo firewall-cmd --reload如果安装了多个 PHP 版本,可以切换默认版本:
1sudo update-alternatives --config php只需启用 Remi 的 PHP 8.x 仓库:
1sudo yum-config-manager --enable remi-php80
2sudo yum update php*| 步骤 | 操作 |
|---|---|
| 1 | 更新系统并安装 EPEL |
| 2 | 添加 Remi 仓库 |
| 3 | 启用 PHP 7.4 仓库 |
| 4 | 安装 PHP 7.4 及扩展 |
| 5 | 检查 PHP 版本 |
| 6 | 优化 php.ini |
| 7 | 启动 PHP-FPM(Nginx 适用) |
| 8 | 测试 PHP |
| 9 | 配置 Nginx/Apache |
| 10 | 安全优化 |
现在你的 CentOS 7 已经成功运行 PHP 7.4!如果有问题,欢迎留言讨论。🚀
安装:
1sudo yum install epel-release -y
2sudo yum install yum-utils -y
3
4sudo yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm -y
5
6sudo yum-config-manager --enable remi-php74
7
8sudo yum install php php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-opcache php-intl php-soap php-redis -y
9
10php -v
11
12sudo systemctl start php-fpm
13sudo systemctl enable php-fpm
14sudo systemctl status php-fpm日历 · 精选 · 友链 · 更多
如果内容对你有帮助,欢迎请我喝杯咖啡 ☕



One的公众号
爱折腾博客的小白