以下是Debian系统上部署PHP项目的常规流程:
sudo apt update && sudo apt upgrade -y
sudo apt install nginx
sudo apt install apache2 libapache2-mod-php
sudo apt install php8.2 php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd
apt install php-扩展名(如php-mbstring)。/etc/php/8.2/fpm/pool.d/www.conf):sudo nano /etc/php/8.2/fpm/pool.d/www.conf
确保listen(如/run/php/php8.2-fpm.sock)、user(www-data)、group(www-data)正确。sudo systemctl start php8.2-fpm
sudo systemctl enable php8.2-fpm
/etc/nginx/sites-available/default):sudo nano /etc/nginx/sites-available/default
添加PHP处理配置:location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
sudo nginx -t
sudo systemctl restart nginx
/var/www/html或自定义路径)。chown -R www-data:www-data /var/www/your_project)。sudo apt install mariadb-server
sudo mysql_secure_installation
info.php:echo "<?php phpinfo(); ?>" > /var/www/html/info.php
http://服务器IP/info.php,确认PHP信息页面显示正常。ufw)限制端口访问。sudo apt update && sudo apt upgrade -y
可使用Ansible、Git等工具实现自动化部署,例如通过Ansible Playbook批量执行安装、配置和重启服务。
参考来源: