Laravel 5 & Vue.js 部署至DigitalOcean生产环境方法咨询
Hey there! Let me walk you through some solid deployment steps for your Laravel 5 + Vue.js project—since I know finding clear guides for older Laravel versions can be tricky.
Laravel 5 + Vue.js Production Deployment Guide
Server Setup (Recommended for Small to Mid-Sized Apps)
- Start with a LEMP/LAMP stack (Linux, Nginx/Apache, MySQL, PHP 7.x – Laravel 5 requires PHP 5.6.4+, but 7.x is way more stable for production).
- For platforms like DigitalOcean, their one-click LEMP/LAMP droplets work great. Just don’t skip hardening the server first: set up SSH keys, disable password login, install UFW firewall, and run regular updates with
apt update && apt upgrade.
Core Deployment Steps
1. Get Your Code on the Server
- Use Git to clone your repo directly:
git clone your-repo-url /var/www/your-project - If Git isn’t an option, upload a zipped version via SFTP, then unzip it with
unzip project.zip
2. Configure Environment Variables
- Copy the example env file:
cp .env.example .env - Edit
.envwith your production database credentials,APP_URL, and setAPP_ENV=production,APP_DEBUG=false - Generate a fresh app key:
php artisan key:generate
3. Install Dependencies
- Install PHP dependencies (skip dev packages for production):
composer install --no-dev --optimize-autoloader - For Vue.js assets, install Node.js first, then run:
This minifies your JS/CSS and bundles everything into thenpm install npm run productionpublicfolder.
4. Fix File Permissions
- Make sure the web server can write to critical directories:
sudo chown -R www-data:www-data /var/www/your-project/storage sudo chown -R www-data:www-data /var/www/your-project/bootstrap/cache sudo chmod -R 775 /var/www/your-project/storage sudo chmod -R 775 /var/www/your-project/bootstrap/cache
5. Set Up Nginx (Example Config)
- Create a server block file at
/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:/run/php/php7.4-fpm.sock; # Adjust to match your PHP version } location ~ /\.ht { deny all; } } - Enable the site:
sudo ln -s /etc/nginx/sites-available/your-project /etc/nginx/sites-enabled/ - Test config and reload:
sudo nginx -t && sudo systemctl reload nginx
6. Database Setup
- Create a production database and user in MySQL:
CREATE DATABASE laravel_prod; CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'strong-password-here'; GRANT ALL PRIVILEGES ON laravel_prod.* TO 'laravel_user'@'localhost'; FLUSH PRIVILEGES; - Run migrations (force to skip production prompt):
php artisan migrate --force
Extra Tips for Stability
- Set up a cron job for Laravel’s scheduler:
crontab -ethen add* * * * * cd /var/www/your-project && php artisan schedule:run >> /dev/null 2>&1 - Enable free SSL with Let’s Encrypt using Certbot—this is non-negotiable for modern apps.
- If you’re using Laravel queues or Echo, use Supervisor to keep processes running in the background.
Also, huge props on writing your own Vue.js deployment guide for DigitalOcean! If you want to refine it, consider adding sections on:
- Optimizing Vue assets (like using
npm run buildwith Vue CLI) - Nginx config for single-page apps (adding a fallback to
index.htmlfor client-side routing) - Automating deployments with simple bash scripts or tools like Deployer
内容的提问来源于stack exchange,提问作者DukesNuz
相关产品推荐
相关产品推荐

