在Linux系统中迁移Laravel项目,可以按照以下步骤进行:
使用Git:
git clone <repository-url> /path/to/new/location
cd /path/to/new/location
使用FTP/SFTP:将项目文件从旧服务器下载到新服务器。
composer install --no-interaction --prefer-dist --optimize-autoloader
.env.example
文件并重命名为.env
:cp .env.example .env
.env
文件,配置数据库连接、邮件服务、队列等设置。php artisan key:generate
php artisan migrate
php artisan optimize
Nginx:
server {
listen 80;
server_name yourdomain.com;
root /path/to/new/location/public;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
Apache:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /path/to/new/location/public
<Directory /path/to/new/location/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Nginx:
sudo systemctl restart nginx
Apache:
sudo systemctl restart apache2
.env
中正确配置了相关设置,并运行相应的迁移命令。通过以上步骤,你应该能够成功地将Laravel项目从旧服务器迁移到新服务器。