Products
96SEO 2025-06-29 11:26 1
网站和应用程序的开发与部署变得越来越关键。而LNMP周围作为当前最流行的Web开发与部署解决方案之一,已经成为许许多开发者和企业的不二选择。本文将深厚入解析怎么在云服务器上配置Ubuntu LNMP周围中的PHP, 帮您飞迅速搭建起高大效、稳稳当当的Web服务器。
在开头配置LNMP周围之前,请确保您的云服务器已经安装了Ubuntu操作系统。
操作系统 | Ubuntu 20.04 LTS |
---|---|
Web服务器 | Nginx |
数据库服务器 | MySQL |
服务器语言 | PHP |
用以下命令安装Nginx作为Web服务器:
sudo apt install nginx -y
安装完成后启动并启用Nginx服务:
sudo systemctl start nginx
sudo systemctl enable nginx
用以下命令安装MySQL作为数据库服务器:
sudo apt install mysql-server -y
启动并启用MySQL服务:
sudo systemctl start mysql
sudo systemctl enable mysql
运行MySQL平安脚本以搞优良平安性:
sudo mysql_secure_installation
用以下命令安装PHP及其常用 :
sudo apt install php php-mysql php-curl php-gd php-mbstring php-xml php-zip -y
启动并启用PHP-FPM服务:
sudo systemctl start php7.4-fpm
sudo systemctl enable php7.4-fpm
编辑Nginx配置文件,通常位于/etc/nginx/sites-available/default
server {
listen 80 default_server;
listen :80 default_server;
root /var/www/html;
index index.php index.html index.htm;
server_name _;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_param SCRIPT_FILE不结盟E $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
保存并退出编辑器,然后在浏览器中访问http://your_server_ip/
,你得能看到PHP信息页面。
在/var/www/html/
目录下创建一个名为info.php
的文件,并添加以下内容:
保存并退出编辑器,然后在浏览器中访问http://your_server_ip/info.php
,你得能看到PHP信息页面。
通过以上步骤,您已经在Ubuntu云服务器上成功配置了LNMP周围中的PHP。接下来 您能接着来安装和配置其他应用程序,如WordPress、Laravel等,以构建您的网站或应用程序。
Demand feedback