This guide provides detailed instructions for deploying gcOpen applications using Laravel Forge, a server management tool that simplifies the deployment process for Laravel applications.
Before you begin, make sure you have:
- A Laravel Forge account (subscription required)
- A cloud provider account (AWS, DigitalOcean, Linode, etc.)
- A domain name for your application
- GitHub/GitLab/Bitbucket repository with your gcOpen application
- Log in to your Laravel Forge account
- Navigate to "Server Providers" in the left sidebar
- Click "Connect Provider" and select your cloud provider
- Follow the instructions to authorize Forge to manage your server provider account
-
Click on "Servers" in the left sidebar
-
Click "Create Server"
-
Select your server provider
-
Choose your server options:
- Server Provider: Your linked provider
- Region: Choose the closest region to your users
- Size: 2GB RAM / 1 CPU minimum recommended
- PHP Version: PHP 8.1
- Database: MySQL 8.0
- Load Balancer: No (unless you need high availability)
- Scheduler: Yes (for Laravel scheduled tasks)
- Redis: Optional (for caching and queues)
- Server Name: Choose a meaningful name (e.g., gcopen-production)
-
Click "Create Server" and wait for Forge to provision your server
Once your server is provisioned:
- Click on your server name
- Under the "Sites" tab, click "Add Site"
- Enter your domain name (e.g., gcopen.yourdomain.com)
- Select PHP 8.1
- Leave "Create Database" unchecked (we'll create it manually)
- Click "Add Site"
- Click on the "Database" tab
- Click "Create Database"
- Enter database details:
- Database Name: gcopen_db
- Database User: gcopen_user
- Password: Generate a secure password (or enter your own)
- Click "Create Database"
- Click on your site name
- Navigate to the "Git Repository" tab
- Click "Install Repository"
- Select your repository provider (GitHub, GitLab, or Bitbucket)
- Select the repository that contains your gcOpen application
- Choose the branch to deploy (usually main or master)
- Click "Install Repository"
- Click on the "Environment" tab
- Laravel Forge provides a starter .env file, update it with your settings:
- Set APP_ENV to production
- Set APP_DEBUG to false
- Set APP_URL to your domain
- Update DB_DATABASE, DB_USERNAME, and DB_PASSWORD with the values from step 4
- Configure mail settings, cache, queue, etc. as needed
- Click "Save Environment"
- Click on the "Deploy" tab
- The default script should work for most Laravel applications, but you may want to customize it:
cd /home/forge/your-site.com
git pull origin $FORGE_SITE_BRANCH
composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
npm ci
npm run build
php artisan migrate --force
php artisan config:cache
php artisan route:cache
php artisan view:cache
php artisan storage:link
# Optional: Clear Redis cache
# redis-cli flushall- Click "Save Script"
- Toggle "Quick Deploy" to "On"
- This will automatically deploy your application when you push to the configured branch
- Click on the "SSL" tab
- Click "LetsEncrypt"
- Enter your email address
- Select both domain variations (with and without www)
- Click "Obtain Certificate"
- Once the certificate is issued, click "Activate"
The Laravel scheduler should already be set up during server creation. Verify by checking the "Scheduler" tab.
If your application uses queues:
- Click on the "Queue" tab
- Click "Add Worker"
- Configure the worker:
- Connection: Choose your queue connection (usually database or redis)
- Queue: default (or your custom queue name)
- Processes: 1 (or more depending on your needs)
- Sleep: 3
- Timeout: 60
- Tries: 3
- Click "Create Worker"
- Click on the "Deploy" tab
- Click "Deploy Now"
- Wait for the deployment to complete and check the deployment log for any errors
For critical applications, you may want to set up Forge Daemon to monitor your site:
- Click on the "Monitoring" tab
- Click "Install Daemon"
- Configure monitoring settings as needed
- Click "Install Daemon"
To configure database backups:
- Click on the "Backups" tab
- Click "Create Backup Configuration"
- Configure backup settings:
- Database: Select your database
- Frequency: Daily (recommended)
- Time: Choose a time with low traffic
- Retention: 7 days (or as needed)
- Click "Create"
If your deployment fails:
- Check the deployment log for errors
- Ensure your .env file is properly configured
- Verify that your repository is accessible to Forge
- Check that composer.json includes all required dependencies
If you encounter permission issues:
- SSH into your server using the SSH key provided by Forge
- Run the following commands:
sudo chown -R forge:forge /home/forge/your-site.com/storage sudo chown -R forge:forge /home/forge/your-site.com/bootstrap/cache sudo chmod -R 775 /home/forge/your-site.com/storage sudo chmod -R 775 /home/forge/your-site.com/bootstrap/cache
If your application can't connect to the database:
- Verify database credentials in the .env file
- Check that the database exists and the user has proper permissions
- Ensure your server's firewall allows connections to the database port
When performing maintenance or updates:
- SSH into your server
- Navigate to your site directory
- Run
php artisan downto put the site in maintenance mode - Perform your maintenance tasks
- Run
php artisan upto bring the site back online
Laravel Forge provides a streamlined way to deploy and manage your gcOpen applications. It handles server provisioning, deployment, SSL certificates, and other common tasks, allowing you to focus on developing your application rather than server administration.
Key benefits of using Laravel Forge:
- Simplified server management
- Automated deployments via Git integration
- Easy SSL certificate management
- Built-in monitoring and backup solutions
- Integration with Laravel's ecosystem
Remember to:
- Keep your application up to date
- Monitor server resources
- Regularly backup your database
- Review server logs for issues
For more advanced configurations or custom needs, you can always SSH into your server and make manual adjustments.