π How to Deploy a Symfony Project on Amazon Lightsail β Step-by-Step Guide (2025)
In this guide, Iβll walk you through the exact steps I followed to deploy a Symfony project (app.danieluxury.top
) on an Apache-based Ubuntu server using Amazon Lightsail. This tutorial covers everything from DNS and SSL to Symfony installation and permissions β with real-world errors and how we fixed them.
π§± Prerequisites
- A registered domain (e.g. via Hostinger)
- An Amazon Lightsail instance (Ubuntu + Apache)
- A Symfony project on Git (private or public)
- SSH access to your server
π¦ 1. Create a Lightsail Instance
- Go to the Lightsail Console
- Create an Ubuntu-based instance (e.g., Ubuntu 22.04 LTS)
- Choose your instance size and region
- Name it something like
symfony-server
- Wait for it to boot, then connect via SSH
βοΈ 2. Install LAMP Stack (Apache, PHP, MariaDB, Composer)
Use this script to automate installation:
curl -O https://yourdomain.com/scripts/install-lamp.sh
chmod +x install-lamp.sh
sudo ./install-lamp.sh
Script contents:
#!/bin/bash
set -e
apt update && apt upgrade -y
apt install -y apache2 mariadb-server php libapache2-mod-php php-cli php-mysql \
php-xml php-mbstring php-curl php-zip php-intl php-bcmath php-soap acl
systemctl enable apache2 mariadb
systemctl start apache2 mariadb
mysql_secure_installation
a2enmod rewrite
systemctl restart apache2
apt install -y git unzip curl
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
πΎ 2.1. Add Swap Space (Optional but Recommended)
For small instances, adding swap prevents memory issues during composer operations:
sudo fallocate -l 1G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Verify swap is active:
sudo swapon --show
free -h
π 3. Set Up DNS for Your Domain
Update A records in your domain provider (e.g. Hostinger):
Type | Name | Value |
---|---|---|
A | @ | YOUR_LIGHTSAIL_IP |
A | www | YOUR_LIGHTSAIL_IP |
A | app | YOUR_LIGHTSAIL_IP |
π 4. Set Up Apache Virtual Hosts + SSL
HTTP redirect:
<VirtualHost *:80>
ServerName app.danieluxury.top
Redirect permanent / https://app.danieluxury.top/
</VirtualHost>
HTTPS site:
<VirtualHost *:443>
ServerName app.danieluxury.top
DocumentRoot /home/ubuntu/Projects/SD-Sy7/public
<Directory /home/ubuntu/Projects/SD-Sy7/public>
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/app.danieluxury.top/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/app.danieluxury.top/privkey.pem
ErrorLog /var/log/apache2/app.danieluxury.top-error.log
CustomLog /var/log/apache2/app.danieluxury.top-access.log combined
</VirtualHost>
Enable and reload Apache:
sudo a2ensite app.danieluxury.top.conf
sudo a2ensite app.danieluxury.top-le-ssl.conf
sudo a2enmod rewrite ssl
sudo systemctl reload apache2
π 5. Install SSL Certificate
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d app.danieluxury.top
π§ 6. Clone Symfony Project & Setup
cd ~/Projects
git clone https://github.com/youruser/yourrepo.git SD-Sy7
cd SD-Sy7
composer install
Create .env.local
:
APP_ENV=prod
APP_DEBUG=0
APP_SECRET=your_secret
DATABASE_URL="mysql://symfony:your_password@127.0.0.1:3306/sd_sy7?serverVersion=10.11.2-MariaDB&charset=utf8mb4"
π§° 7. Set Up Database
sudo mysql
CREATE DATABASE sd_sy7 CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'symfony'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON sd_sy7.* TO 'symfony'@'localhost';
FLUSH PRIVILEGES;
EXIT;
Run:
php bin/console doctrine:migrations:migrate --no-interaction
π§Ό 8. Set Permissions
sudo mkdir -p var/log var/cache/prod
sudo chown -R ubuntu:www-data var
sudo chmod -R 775 var
Or use ACL:
sudo setfacl -R -m u:www-data:rwX -m u:ubuntu:rwX var
sudo setfacl -dR -m u:www-data:rwX -m u:ubuntu:rwX var
π§― 9. Clear Cache & Restart Apache
php bin/console cache:clear --env=prod
php bin/console cache:warmup --env=prod
sudo systemctl restart apache2
π 10. Fix File Access Permissions
sudo chmod o+x /home
sudo chmod o+x /home/ubuntu
sudo chmod o+x /home/ubuntu/Projects
sudo chmod o+x /home/ubuntu/Projects/SD-Sy7
sudo chmod -R o+rx /home/ubuntu/Projects/SD-Sy7/public
π§ͺ 11. Test & Debug Logs
Check Symfony logs:
tail -n 50 var/log/prod.log
Apache error logs:
tail -n 50 /var/log/apache2/app.danieluxury.top-error.log
π Result
π Visit: https://app.danieluxury.top β You did it!
This setup is now production-ready with HTTPS, structured logging, correct file permissions, and DNS redirection.
π Extras
Use this to collect system info (optional script):
./system-info.sh
#!/bin/bash
echo "===== π₯οΈ SYSTEM INFORMATION ====="
echo "Hostname : $(hostname)"
echo "User : $(whoami)"
echo "Uptime : $(uptime -p)"
echo "Date & Time : $(date)"
echo -e "\n===== π§ MEMORY ====="
free -h
echo -e "\n===== πΎ DISK USAGE ====="
df -h /
echo -e "\n===== βοΈ OS & KERNEL ====="
echo "OS : $(lsb_release -d | cut -f2)"
echo "Architecture : $(uname -m)"
echo "Kernel : $(uname -r)"
echo -e "\n===== π’ CPU ====="
lscpu | grep -E '^Model name|^CPU\(s\)|^Thread|^Core|^Socket'
echo -e "\n===== π NETWORK ====="
echo "IP Address : $(hostname -I)"
ip a | grep inet
echo -e "\n===== π OPEN PORTS ====="
sudo ss -tuln
echo -e "\n===== π¦ INSTALLED PACKAGES ====="
echo "APT packages : $(dpkg --get-selections | wc -l)"
echo -e "\n===== β
DONE ====="