迁移一个基于 Debian 的 PHP 项目通常涉及以下几个步骤:
sudo apt update && sudo apt upgrade -y
sudo apt install php php-cli php-fpm php-mysql php-curl php-xml php-zip php-gd php-mbstring php-pear php-bcmath -y
根据项目需求,可能需要安装其他 PHP 扩展。sudo apt install nginx -y # 或者 sudo apt install apache2 -y
/etc/nginx/sites-available/your-site
文件,配置服务器块。server {
listen 80;
server_name your-domain.com;
root /path/to/your/project;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
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-site /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
/etc/apache2/sites-available/your-site.conf
文件,配置虚拟主机。<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /path/to/your/project
<Directory /path/to/your/project>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
然后启用站点:sudo a2ensite your-site.conf
sudo systemctl restart apache2
rsync
或其他文件传输工具。rsync -avz --delete /path/to/old/project/ /path/to/new/project/
mysqldump -u username -p database_name > database_name.sql
mysql -u username -p database_name < database_name.sql
sudo chown -R www-data:www-data /path/to/your/project
sudo find /path/to/your/project -type f -exec chmod 644 {} \;
sudo find /path/to/your/project -type d -exec chmod 755 {} \;
通过以上步骤,你应该能够成功地将基于 Debian 的 PHP 项目迁移到新的服务器上。