Deploying Laravel 11 Inertia Vue to Coolify using Docker Compose (with and without SSR)
September 15, 2024 (2mo ago)
Deploying Laravel 11 Inertia Vue to Coolify using Docker Compose (with and without SSR)
In this comprehensive guide, we'll walk through the process of deploying a Laravel 11 application with Inertia and Vue.js to Coolify using Docker Compose. We'll cover both Server-Side Rendering (SSR) and non-SSR setups, allowing you to choose the best option for your project.
Prerequisites
Before we begin, make sure you have the following:
A Laravel 11 application with Inertia and Vue.js set up
A Coolify account and server set up
Step 1: Prepare Your Docker Configuration
First, we need to create a Dockerfile and a docker-compose.yaml file in the root of your Laravel project.
Dockerfile
Create a Dockerfile with the following content:
docker-compose.yaml
Create a docker-compose.yaml file with the following content:
If you're not using SSR, keep the ssr service commented out. If you are using SSR, uncomment the ssr service block.
Step 2: Create Additional Configuration Files
docker-entrypoint.sh
Create a docker-entrypoint.sh file in the root of your project:
.dockerignore
Create a .dockerignore file in the root of your project:
node_modules
vendor
.git
.idea
Apache Configuration
Create a file at docker/apache/000-default.conf:
PHP Configuration
Create a file at docker/php/custom.ini:
Step 3: Prepare Your Laravel Application
If you're using SSR, make sure you have set up Inertia SSR properly in your Laravel application.
Modify your app/Providers/AppServiceProvider.php to force HTTPS in production:
This change ensures that all URLs generated by your application in production will use HTTPS.
Step 4: Deploy to Coolify
Log in to your Coolify dashboard.
Connect your Git repository to Coolify.
Create a new project and select "Docker Compose" as the deployment method.
In the Coolify project settings, make sure to set the following environment variables:
DB_HOST: Set this to the name of your database service in the Docker Compose file (e.g., db)
DB_DATABASE: Your database name
DB_USERNAME: Your database username
DB_PASSWORD: Your database password
Any other environment-specific variables your application needs .env
Configure the deployment settings:
Set the container name
Set the domain name
Set the following post-deployment command:
php artisan storage:link
This command will create a symbolic link from public/storage to storage/app/public.
Save your configuration and deploy your application.
Step 5: Post-Deployment Tasks
After successful deployment, go to the Command tab. Execute the following command:
php artisan migrate --force
This command will run your database migrations, ensuring your database schema is up to date.
Conclusion
You have now successfully deployed your Laravel 11 Inertia Vue application to Coolify using Docker Compose, with options for both SSR and non-SSR setups. This configuration provides a scalable and maintainable infrastructure for your application.
Key points to remember:
The AppServiceProvider modification ensures HTTPS usage in production.
The php artisan storage:link command is run as a post-deployment task to set up proper storage linking.
Database migrations are run using the Coolify Command tab after deployment.
Remember to monitor your application's performance and logs, and make adjustments as necessary to optimize its operation in the production environment. If you're using SSR, keep an eye on the SSR service to ensure it's running smoothly and providing the expected performance benefits.