Files
Laravel-Docker-Dev-Template/deploy/apache/apache-setup.md
2026-03-06 08:57:05 +02:00

1.9 KiB

Apache Virtual Host Setup for Laravel

Prerequisites

Ubuntu 24.04 with Apache2 and PHP-FPM installed.

Required Apache Modules

Enable the necessary modules:

sudo a2enmod rewrite
sudo a2enmod headers
sudo a2enmod ssl
sudo a2enmod proxy_fcgi
sudo a2enmod deflate
sudo a2enmod expires
sudo a2enmod setenvif

Installation Steps

1. Copy Virtual Host Configuration

sudo cp deploy/apache/laravel-site.conf /etc/apache2/sites-available/your-app.conf

2. Edit Configuration

Update the following in the config file:

  • ServerName - Your domain name
  • DocumentRoot - Path to Laravel's public folder
  • Directory - Same path as DocumentRoot
  • Log file names

3. Enable Site

sudo a2ensite your-app.conf
sudo a2dissite 000-default.conf  # Disable default site if needed

4. Test Configuration

sudo apache2ctl configtest

5. Restart Apache

sudo systemctl restart apache2

SSL with Certbot

Install Certbot and obtain SSL certificate:

sudo apt install certbot python3-certbot-apache
sudo certbot --apache -d your-domain.com -d www.your-domain.com

Certbot will automatically modify your Apache configuration for SSL.

File Permissions

Set correct permissions for Laravel:

sudo chown -R www-data:www-data /var/www/your-app
sudo chmod -R 755 /var/www/your-app
sudo chmod -R 775 /var/www/your-app/storage
sudo chmod -R 775 /var/www/your-app/bootstrap/cache

Common Issues

403 Forbidden

  • Check directory permissions
  • Ensure AllowOverride All is set
  • Verify mod_rewrite is enabled

500 Internal Server Error

  • Check Laravel logs: storage/logs/laravel.log
  • Check Apache error logs: /var/log/apache2/your-app-error.log
  • Ensure .env file exists and has correct permissions

PHP Not Processing

  • Verify PHP-FPM is running: sudo systemctl status php8.3-fpm
  • Check socket path matches in Apache config