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 環境并實現動態網站部署。