在Linux系统下管理Laravel项目涉及多个方面,包括安装必要的软件、配置Web服务器、版本控制、任务调度、日志管理等。以下是详细的管理步骤:
sudo apt-get update sudo apt-get install php php-cli php-fpm php-json php-common php-mysql php-zip php-mbstring php-xml php-bcmath php-curl php-pear php-bcmath sudo apt-get install git curl -sS https://getcomposer.org/installer | php sudo mv composer.phar /usr/local/bin/composer sudo apt-get install nginx sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/your-project sudo ln -s /etc/nginx/sites-available/your-project /etc/nginx/sites-enabled sudo nginx -t sudo systemctl restart nginx sudo apt-get install apache2 libapache2-mod-rewrites sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/your-project sudo a2ensite your-project sudo a2enmod rewrites sudo systemctl restart apache2 确保Web服务器配置正确,以便能够处理Laravel的路由和静态文件。
server { listen 80; server_name yourdomain.com; root /path/to/your/laravel/public; add_header X-Frame-Options "SAMEORIGIN"; add_header X-XSS-Protection "1; mode=block"; add_header X-Content-Type-Options "nosniff"; index index.html index.htm index.php; charset utf-8; 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; } location ~ /\.(?!well-known).* { deny all; } } <VirtualHost *:80> ServerAdmin webmaster@localhost DocumentRoot /path/to/your/laravel/public DirectoryIndex index.php Options Indexes FollowSymLinks AllowOverride All Require all granted </VirtualHost> 使用Git进行版本控制:
cd /path/to/your/laravel/project git init git add . git commit -m "Initial commit" git remote add origin https://github.com/your-username/your-repository.git git push -u origin master 使用Laravel的Artisan命令行工具定义周期性任务:
app/Console/Kernel.php文件:protected function schedule(Schedule $schedule) { $schedule->command('your:command')->everyMinute(); } * * * * * cd /path/to/your/laravel/project && php artisan schedule:run >> /dev/null 2>&1 .env文件:LOG_CHANNEL=single LOG_LEVEL=debug LOG_FILE=laravel.log tail -f storage/logs/laravel.log php artisan log:clear php artisan log:clear --since="2021-01-01" /etc/logrotate.d/laravel文件:/path/to/your/laravel/storage/logs/*.log { daily missingok rotate 14 compress notifempty create 640 root adm } 通过以上步骤,你可以在Linux系统下有效地管理Laravel项目,确保项目的顺利进行和高质量交付。