引言在当今的互联网时代,构建一个高效、稳定的网站是每个企业或个人的需求。Rocky Linux 8.2 作为一款免费、开源的操作系统,因其稳定性和兼容性而受到许多开发者和系统管理员的青睐。本文将详细指...
在当今的互联网时代,构建一个高效、稳定的网站是每个企业或个人的需求。Rocky Linux 8.2 作为一款免费、开源的操作系统,因其稳定性和兼容性而受到许多开发者和系统管理员的青睐。本文将详细指导您在 Rocky Linux 8.2 上安装 PHP 和 Nginx,从而构建一个高效网站。
在开始之前,请确保您的 Rocky Linux 8.2 系统已经安装完成,并且您具有 root 权限或 sudo 权限。
Nginx 是一款高性能的 HTTP 和反向代理服务器,它是构建网站的基础。
sudo dnf update -ysudo dnf install nginx -ysudo systemctl start nginxsudo systemctl enable nginxhttp://localhost,您应该能看到 Nginx 的默认欢迎页面。PHP 是一种流行的服务器端脚本语言,用于开发动态网站。
sudo dnf install php php-fpm php-mysql -ysudo systemctl start php-fpmsudo systemctl enable php-fpmsudo nano /etc/nginx/nginx.confhttp 块中,找到 include 指令,添加以下行以包含 PHP 配置:include /etc/nginx/fastcgi_params;/etc/nginx/conf.d/default.conf:sudo nano /etc/nginx/conf.d/default.confserver { listen 80; server_name localhost; root /usr/share/nginx/html; index index.php index.html index.htm; location / { try_files $uri $uri/ /index.php?$query_string; } location ~ .php$ { include snippets/fastcgi-php.conf; fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }
}sudo systemctl reload nginx/usr/share/nginx/html 目录下创建一个名为 info.php 的文件,并添加以下内容:<?php
phpinfo();
?>http://localhost/info.php,您应该能看到 PHP 的信息页面。通过以上步骤,您已经在 Rocky Linux 8.2 上成功安装了 PHP 和 Nginx,并配置了它们以支持 PHP 应用。现在,您可以使用 PHP 和 Nginx 来构建一个高效、稳定的网站。