将PHP项目部署到LNMP(Linux, Nginx, MySQL, PHP)平台是一个相对直接的过程,但需要仔细规划和执行。以下是一个最佳流程:
sudo apt update && sudo apt upgrade
sudo apt install nginx
sudo apt install mysql-server
sudo apt install php-fpm php-mysql
sudo nano /etc/nginx/sites-available/your_project
server {
listen 80;
server_name your_domain.com;
root /var/www/your_project/public;
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 unix:/var/run/php/php7.4-fpm.sock; # 根据你的PHP版本调整
}
location ~ /\.ht {
deny all;
}
}
sudo ln -s /etc/nginx/sites-available/your_project /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
sudo mysql -u root -p
CREATE DATABASE your_project_db;
CREATE USER 'your_project_user'@'localhost' IDENTIFIED BY 'your_project_password';
GRANT ALL PRIVILEGES ON your_project_db.* TO 'your_project_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
sudo mkdir -p /var/www/your_project/public
sudo chown -R www-data:www-data /var/www/your_project
/var/www/your_project/public
目录。sudo nano /etc/php/7.4/fpm/pool.d/www.conf
listen = /var/run/php/php7.4-fpm.sock
sudo systemctl restart php7.4-fpm
http://your_domain.com
,确保项目正常运行。sudo ufw allow 'Nginx Full'
sudo ufw allow 'OpenSSH'
sudo ufw enable
通过以上步骤,你应该能够成功地将PHP项目部署到LNMP平台。如果在过程中遇到问题,可以参考官方文档或寻求社区帮助。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。