Laravel is PHP's most popular framework, powering applications from small startups to large-scale platforms. Deploying Laravel to production requires proper environment configuration, queue workers, scheduled tasks, and storage setup.
With Out Plane, you can deploy your Laravel application in under a minute. This guide shows you exactly how.
What You'll Need
Before starting, make sure you have:
- PHP 8.3+ installed on your machine
- Composer installed globally
- A GitHub account
- A Laravel application in a GitHub repository
Don't have PHP installed? Here's how to install it:
- Windows: Download from windows.php.net or use Laragon for a full local environment
- macOS: Use
brew install phpto install the latest version - Linux: Run
sudo apt install php php-cli php-mbstring php-xml php-curl php-zip(Ubuntu/Debian) orsudo dnf install php php-cli php-mbstring php-xml(Fedora)
Install Composer from getcomposer.org if you don't have it yet.
Once PHP and Composer are installed, create a new Laravel application:
composer create-project laravel/laravel my-laravel-app
cd my-laravel-appIf you don't have a Laravel app yet, use our example below.
Quick Start: Sample Laravel Application
Create a new Laravel project:
composer create-project laravel/laravel my-laravel-app
cd my-laravel-appThe default Laravel installation includes a welcome page. Let's add a simple API endpoint.
Update routes/web.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return response()->json([
'message' => 'Hello from Laravel!',
'status' => 'running',
]);
});
Route::get('/health', function () {
return response()->json(['status' => 'healthy']);
});Add an API route in routes/api.php:
<?php
use Illuminate\Support\Facades\Route;
Route::get('/info', function () {
return response()->json([
'framework' => 'Laravel',
'php_version' => PHP_VERSION,
'environment' => config('app.env'),
]);
});Test your application locally:
php artisan serveVisit http://localhost:8000 in your browser. You should see the JSON response.
Add a Dockerfile
Create a Dockerfile in your project root:
FROM php:8.3-cli
RUN apt-get update && apt-get install -y \
git \
unzip \
libpq-dev \
libzip-dev \
&& docker-php-ext-install pdo pdo_pgsql zip bcmath \
&& rm -rf /var/lib/apt/lists/*
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer
WORKDIR /app
COPY composer.json composer.lock ./
RUN composer install --no-dev --optimize-autoloader --no-scripts
COPY . .
RUN composer dump-autoload --optimize \
&& php artisan config:clear \
&& php artisan route:clear \
&& php artisan view:clear
RUN chmod -R 775 storage bootstrap/cache
EXPOSE 8080
CMD ["php", "artisan", "serve", "--host=0.0.0.0", "--port=8080"]This uses php artisan serve for simplicity. For higher traffic applications, consider using Nginx with PHP-FPM or FrankenPHP for better concurrency.
Push this code to a GitHub repository, and you're ready to deploy.
Deploy in 3 Steps
Step 1: Connect Your Repository
- Go to console.outplane.com
- Sign in with your GitHub account
- Select your Laravel repository from the list
Step 2: Configure Your Application
Configure the following settings in the create application form:
Build Method
Select Dockerfile as your build method since the repository includes a Dockerfile.
Basic Settings
- Port: Set to
8080 - Branch: Select
mainor your preferred branch - Region: Choose the region closest to your users
Environment Variables (Required)
Laravel requires certain environment variables for production. Add these using the Add button or Raw Edit:
APP_KEY=base64:your-generated-app-key-here
APP_ENV=production
APP_DEBUG=false
APP_URL=https://your-app.outplane.app
LOG_CHANNEL=stderr
DB_CONNECTION=pgsqlGenerate a secure APP_KEY with:
php artisan key:generate --showThis outputs a base64:... string. Copy it as the value for APP_KEY.
Step 3: Deploy
Click Deploy Application and watch the build process:
- Queued → Waiting for resources
- Building → Installing Composer dependencies, optimizing autoloader
- Deploying → Starting your Laravel application
- Ready → Your app is live
Once the status shows Ready, your application is live. You can find your application URL at the top of the deployment page. Click the URL to open your Laravel app in a new tab. SSL is automatically configured.
Production Best Practices
APP_KEY Generation
Every Laravel application requires an APP_KEY for encryption. Never reuse keys across environments:
php artisan key:generate --showSet this value as the APP_KEY environment variable. Without it, Laravel will throw a runtime exception.
Config and Route Caching
Speed up your application by caching configuration and routes. Add these commands to your Dockerfile:
RUN php artisan config:cache \
&& php artisan route:cache \
&& php artisan view:cacheNote that config:cache bakes environment variables into the cache at build time. If you use env() calls outside of config files, those values will not be available. Always reference configuration values with config() instead.
Storage Permissions
Laravel writes to the storage and bootstrap/cache directories. Ensure they are writable:
RUN chmod -R 775 storage bootstrap/cacheIf your application uses file uploads, configure a cloud storage driver like S3 instead of local disk.
Storage Link
If your application serves files from storage/app/public, create the symbolic link in your Dockerfile:
RUN php artisan storage:linkQueue Workers
For applications that use Laravel's queue system, run a separate worker process. You can deploy a second service on Out Plane with the same repository and a different start command:
php artisan queue:work --tries=3 --timeout=90Set the QUEUE_CONNECTION environment variable to database or redis depending on your driver.
Connecting a Database
Most Laravel applications need a database. Out Plane provides managed PostgreSQL:
- Go to Databases in the sidebar
- Click Create Database
- Select PostgreSQL version and region
- Copy the connection details
Add the database configuration as environment variables:
DB_CONNECTION=pgsql
DB_HOST=your-database-host
DB_PORT=5432
DB_DATABASE=your-database-name
DB_USERNAME=your-database-user
DB_PASSWORD=your-database-passwordAlternatively, use a single DATABASE_URL environment variable if your Laravel application is configured to parse it.
After connecting, run migrations by adding an entrypoint script or running them as a one-off command:
php artisan migrate --forceThe --force flag is required in production to bypass the confirmation prompt.
Custom Domain Setup
Replace the default .outplane.app URL with your own domain:
- Navigate to Domains
- Click Map Domain
- Enter your domain (e.g.,
app.yourdomain.com) - Add the DNS records shown to your domain registrar
Update the APP_URL environment variable to match your new domain:
APP_URL=https://app.yourdomain.comSSL certificates are automatically provisioned once DNS propagates.
Monitoring Your Application
After deployment, monitor your Laravel application:
- Logs: View real-time application logs. Set
LOG_CHANNEL=stderrso Laravel writes logs to standard error, which Out Plane captures automatically. - Metrics: Track CPU, memory, and network usage
- HTTP Logs: Analyze incoming requests, response times, and status codes
Access these from the sidebar in your application dashboard.
For application-level logging, Laravel's built-in logging with the stderr channel works seamlessly:
// config/logging.php is already configured for stderr
// Just use the Log facade anywhere in your application
use Illuminate\Support\Facades\Log;
Log::info('Order processed', ['order_id' => $order->id]);
Log::error('Payment failed', ['error' => $exception->getMessage()]);Troubleshooting
APP_KEY Missing or Invalid
Generate a new key and set it as an environment variable. Without a valid APP_KEY, Laravel cannot encrypt sessions, cookies, or any other data:
php artisan key:generate --showCopy the output and set it as the APP_KEY environment variable in your application settings.
Storage Permission Errors
Ensure storage directories are writable. Add this to your Dockerfile:
RUN chmod -R 775 storage bootstrap/cacheIf errors persist, check that no files were copied with restrictive permissions from your local environment.
500 Internal Server Error
Check your application logs. Navigate to Logs in the sidebar. Common causes:
- Missing
APP_KEYenvironment variable - Database connection failures
- Missing PHP extensions (pdo_pgsql, mbstring, xml)
- Cached configuration referencing unavailable environment variables
Migration Failures
Verify database connectivity. Ensure your DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME, and DB_PASSWORD environment variables are set correctly. Test the connection:
php artisan db:monitorSession and Cache Driver Issues
Use database or Redis drivers in production. The default file driver does not work reliably in containerized environments. Update these environment variables:
SESSION_DRIVER=database
CACHE_STORE=databaseOr use Redis if available:
SESSION_DRIVER=redis
CACHE_STORE=redis
REDIS_HOST=your-redis-host
REDIS_PORT=6379Run php artisan session:table && php artisan migrate if using the database driver.
Next Steps
Your Laravel application is now deployed and running in production. Here's what to explore next:
- Scale your application: Adjust instance types and auto-scaling settings for higher traffic
- Set up CI/CD: Enable automatic deployments on every git push
- Add Redis: Use Redis for queues, cache, and session storage for better performance
- Configure scheduled tasks: Run Laravel's task scheduler with
php artisan schedule:work
Summary
Deploying a Laravel application to Out Plane takes three steps:
- Connect your GitHub repository
- Configure port (8080), APP_KEY, and environment variables
- Deploy and get your live URL
No server configuration, no manual SSL setup, no infrastructure management. Just push your code and go live.
Ready to deploy your Laravel application? Get started with Out Plane and receive $20 in free credit.