在LNMP(Linux, Nginx, MySQL, PHP)架構下進行代碼部署,通常涉及以下幾個步驟:
準備工作:
安裝Nginx:
sudo apt update
sudo apt install nginx
sudo systemctl start nginx
sudo systemctl enable nginx
sudo systemctl status nginx
安裝MySQL/MariaDB:
sudo yum install mariadb-server mariadb
sudo mysql_install_db --user=mysql
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
安裝PHP及其擴展:
sudo apt install php php-mysql php-fpm php-xml php-curl php-gd
/etc/php/版本/fpm/pool.d/www.conf
),設置監聽端口或socket。sudo systemctl start php版本-fpm
sudo systemctl enable php版本-fpm
配置Nginx以支持PHP:
/etc/nginx/sites-available/default
)。location \.php
塊中添加以下內容:location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php版本-fpm.sock;
}
sudo systemctl restart nginx
上傳代碼:
/var/www/html
)下創建項目目錄。測試網站:
防火墻配置(如果需要):
sudo systemctl stop firewalld
sudo setenforce 0
以上步驟提供了一個基本的LNMP部署流程,具體細節可能會因Linux發行版和版本的不同而有所變化。