LNMP 架构是一种常见的 Web 应用服务器架构,由 Linux 操作系统、Nginx 服务器、MySQL 数据库和 PHP 编程语言组成。以下是实现动态网站部署的步骤:
yum install -y nginx
systemctl start nginx
systemctl enable nginx
yum install -y mariadb-server mariadb
systemctl start mariadb
systemctl enable mariadb
yum install -y php php-fpm php-mysql
systemctl start php-fpm
systemctl enable php-fpm
vim /etc/nginx/conf.d/default.conf
在配置文件中添加以下内容:
server {
listen 80;
server_name example.com;
root /usr/share/nginx/html;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
systemctl restart nginx
mysql -u root -p
在 MySQL shell 中执行以下命令:
CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;
EXIT;
将你的动态网站文件(例如 WordPress)上传到 /usr/share/nginx/html
目录下。
chown -R nginx:nginx /usr/share/nginx/html
在浏览器中输入你的服务器 IP 地址或域名,检查网站是否正常运行。
在网站根目录下创建一个包含以下内容的 info.php
文件:
<?php
phpinfo();
?>
通过浏览器访问 http://your_server_ip/info.php
,查看 PHP 信息页面以确认一切正常。
以上步骤可以帮助你在 Linux 系统上成功部署 LNMP 环境并实现动态网站部署。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: Linux中如何查看CPU信息和利用率