Skip to main content

Prerequisites

Before starting, ensure you have the following:
  • A fresh Ubuntu 24.04 server with root or sudo access.
  • A registered domain name with an A record pointing to your server’s public IP address.
  • An SSH client (e.g., Terminal, PuTTY) and an SFTP client (e.g., FileZilla).
  • A secure password for the database user.
  • Your application’s source code and database SQL file.
  • Back up your server before proceeding.
  • Obtain your server’s IP address from your hosting provider (e.g., AWS, DigitalOcean).

Table of Contents

  1. Connect to the Server
  2. Install and Configure Dependencies
  3. Upload Source Code
  4. Configure Application
  5. Enable HTTPS
  6. Set Up Firewall
  7. Troubleshooting

Step 1: Connect to the Server

Connect to your server via SSH to begin the setup process.
  1. Obtain your server’s IP address from your hosting provider.
  2. Open a terminal and connect: ssh root@<your-server-ip>
  3. If using a key-based connection: ssh -i yourkey.pem root@<your-server-ip>
    Verify SSH Service
    sudo systemctl status ssh
    
    • If you can’t connect, ensure port 22 is open: sudo ufw allow 22.
    • Contact your hosting provider if SSH issues persist.

Step 2: Install and Configure Dependencies

Install the necessary software packages for your Aleuto application, including Nginx, PHP 8.4, PostgreSQL, Node.js, Redis, Memcached, Supervisor, and Certbot.
Update Package List
sudo apt update
Upgrade Packages
sudo apt upgrade -y
Install Basic Packages
sudo apt-get install -y software-properties-common curl gnupg debian-keyring debian-archive-keyring apt-transport-https \
ca-certificates build-essential dos2unix gcc git git-lfs libmcrypt4 libpcre3-dev libpng-dev chrony make pv \
python3-pip re2c supervisor unattended-upgrades whois vim cifs-utils bash-completion zsh zip unzip expect
Verify Installation
git --version
Create Swap Space
sudo fallocate -l "$(free -m | awk '/Mem:/ {print $2}')M" /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
swapon --show
  • Swap space prevents memory issues on low-RAM servers.
  • Adjust the size based on your server’s needs.
Install Nginx
sudo apt install -y nginx
Remove Default Site
sudo rm /etc/nginx/sites-enabled/default
Verify Nginx
nginx -v
sudo systemctl status nginx
Add PHP Repository
sudo apt-add-repository ppa:ondrej/php -y
Update Package Lists
sudo apt-get update -y
Install Generic PHP Packages
sudo apt-get install -y --allow-change-held-packages \
php-imagick php-memcached php-redis php-xdebug php-dev imagemagick mcrypt
Install PHP 8.4
sudo apt-get install -y --allow-change-held-packages \
php8.4 php8.4-bcmath php8.4-bz2 php8.4-cgi php8.4-cli php8.4-common php8.4-curl php8.4-dba php8.4-dev \
php8.4-enchant php8.4-fpm php8.4-gd php8.4-gmp php8.4-imap php8.4-interbase php8.4-intl php8.4-ldap \
php8.4-mbstring php8.4-mysql php8.4-odbc php8.4-opcache php8.4-pgsql php8.4-phpdbg php8.4-pspell php8.4-readline \
php8.4-snmp php8.4-soap php8.4-sqlite3 php8.4-sybase php8.4-tidy php8.4-xdebug php8.4-xml php8.4-xmlrpc php8.4-xsl \
php8.4-zip php8.4-memcached php8.4-redis
Configure PHP for Secure Connections
sudo printf "[openssl]\nopenssl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | sudo tee -a /etc/php/8.4/fpm/php.ini
sudo printf "[curl]\ncurl.cainfo = /etc/ssl/certs/ca-certificates.crt\n" | sudo tee -a /etc/php/8.4/fpm/php.ini
Restart PHP-FPM
sudo systemctl restart php8.4-fpm
Verify PHP
php -v
  • Optionally, tune PHP-FPM settings in /etc/php/8.4/fpm/pool.d/www.conf (e.g., pm.max_children) based on server resources.
Download Composer
curl -sS https://getcomposer.org/installer | sudo php
Move Composer
sudo mv composer.phar /usr/bin/composer
Verify Composer
composer --version
Add Node.js Repository
curl -fsSL https://deb.nodesource.com/setup_21.x | sudo -E bash -
Update Package Lists
sudo apt-get update -y
Install Node.js and Tools
sudo apt install -y nodejs
sudo npm install -g npm gulp-cli bower yarn grunt-cli
Verify Node.js and NPM
node -v
npm -v
Install Redis
sudo apt install -y redis-server
Enable and Start Redis
sudo systemctl enable redis-server
sudo service redis-server start
Verify Redis
redis-cli ping
  • Expected output: PONG
Install PostgreSQL
sudo apt-get install -y postgresql-17 postgresql-server-dev-17 postgresql-17-postgis-3 postgresql-17-postgis-3-scripts
Configure PostgreSQL Users
sudo -u postgres psql -c "CREATE ROLE aleuto_user LOGIN PASSWORD 'secure_password_here' SUPERUSER INHERIT NOCREATEDB NOCREATEROLE NOREPLICATION;"
Configure Remote Access
sudo sed -i "s/#listen_addresses = 'localhost'/listen_addresses = '*'/g" /etc/postgresql/17/main/postgresql.conf
sudo echo "host all all 0.0.0.0/0 scram-sha-256" | sudo tee -a /etc/postgresql/17/main/pg_hba.conf
Create Database
sudo -u postgres createdb --echo --owner=aleuto aleuto
Restart PostgreSQL
sudo service postgresql restart
Verify PostgreSQL
sudo -u postgres psql -c "\l"
  • Replace secure_password_here with a strong, unique password.
  • For better security, restrict remote access to specific IPs (e.g., host all all <your-ip>/32 scram-sha-256).
Install Memcached
sudo apt-get install -y memcached
Enable and Start Memcached
sudo systemctl enable memcached
sudo service memcached start
Verify Memcached
sudo systemctl status memcached
Install Supervisor
sudo apt install -y supervisor
Enable and Start Supervisor
sudo systemctl enable supervisor
sudo service supervisor start
Verify Supervisor
sudo systemctl status supervisor
Create Horizon Configuration
sudo nano /etc/supervisor/conf.d/horizon.conf
Horizon Configuration
[program:horizon]
process_name=%(program_name)s
command=php /var/www/aleuto/artisan horizon
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=aleuto
redirect_stderr=true
stdout_logfile=/var/www/aleuto/storage/logs/horizon.log
stopwaitsecs=3600
Create Reverb Configuration
sudo nano /etc/supervisor/conf.d/reverb.conf
Reverb Configuration
[program:reverb]
process_name=%(program_name)s
command=php /var/www/aleuto/artisan reverb:start
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=aleuto
redirect_stderr=true
stdout_logfile=/var/www/aleuto/storage/logs/reverb.log
stopwaitsecs=3600
Update Supervisor
sudo supervisorctl reread
sudo supervisorctl update
sudo supervisorctl start horizon
sudo supervisorctl start reverb
Verify Supervisor Processes
sudo supervisorctl status
  • Ensure Laravel Horizon and Reverb are installed in your project: composer require laravel/horizon laravel/reverb.
  • Check logs (/var/www/aleuto/storage/logs/horizon.log, /var/www/aleuto/storage/logs/reverb.log) if processes fail to start.
Install Certbot
sudo apt install -y certbot python3-certbot-nginx
Verify Certbot
certbot --version
Upgrade Check
sudo apt upgrade -y
Clean Up
sudo apt autoremove -y
sudo apt clean

Step 3: Upload Source Code

Upload your Aleuto application’s source code and database to the server.

Upload Source Code

  1. Download FileZilla Client.
  2. Download your application’s source code.
  3. Upload the source code to /var/www/aleuto.
Set Permissions
sudo chown -R www-data:www-data /var/www/aleuto
sudo chmod -R 775 /var/www/aleuto
  • Verify the directory structure matches your application’s requirements.

Import Database

Import SQL File
psql -U aleuto_user -d aleuto_db -h 127.0.0.1 -p 5432 < /var/www/aleuto/database.sql
Verify Database Import
sudo -u postgres psql -d aleuto_db -c "\dt"
  • Ensure database credentials are set in the .env file before importing.
  • If the import fails, check the SQL file for errors or verify PostgreSQL is running: sudo systemctl status postgresql.

Step 4: Configure Application

Configure Nginx and Laravel to serve your application.

Configure Nginx

Create Nginx Configuration
sudo nano /etc/nginx/sites-available/aleuto
Nginx Configuration
server {
listen 80;
listen [::]:80;
server_name your-domain.com www.your-domain.com;
root /var/www/aleuto/public;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-Content-Type-Options "nosniff";

client_max_body_size 1024M;

index index.php;

charset utf-8;

location / {
try_files $uri $uri/ /index.php?$query_string;
}

location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt  { access_log off; log_not_found off; }

error_page 404 /index.php;

location /app {
proxy_http_version 1.1;
proxy_set_header Host $http_host;
proxy_set_header Scheme $scheme;
proxy_set_header SERVER_PORT $server_port;
proxy_set_header REMOTE_ADDR $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://0.0.0.0:8080;
}

location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}

location ~ /\.(?!well-known).* {
deny all;
}
}
Enable Site
sudo ln -s /etc/nginx/sites-available/aleuto /etc/nginx/sites-enabled/aleuto
Test Nginx Configuration
sudo nginx -t
Restart Nginx
sudo service nginx restart
  • Replace your-domain.com with your actual domain.
  • Check /var/log/nginx/error.log if Nginx fails to start.

Configure Laravel

Navigate to Project Directory
cd /var/www/aleuto
Copy .env.example
cp .env.example .env
Edit .env File
nano .env
Example .env Configuration
APP_URL=https://your-domain.com
DB_CONNECTION=pgsql
DB_HOST=127.0.0.1
DB_PORT=5432
DB_DATABASE=aleuto_db
DB_USERNAME=aleuto_user
DB_PASSWORD=secure_password_here
Install Composer Dependencies
composer install --optimize-autoloader --no-dev
Install NPM Dependencies
npm install
Build Frontend Assets
npm run build
Generate Application Key
php artisan key:generate
Set Permissions
sudo chown -R www-data:www-data storage bootstrap/cache
sudo chmod -R 775 storage bootstrap/cache
Add User to www-data Group
sudo usermod -a -G www-data aleuto
Create Storage Link
php artisan storage:link
Set Up Laravel Scheduler
crontab -e
Add Cron Job
* * * * * cd /var/www/aleuto && php artisan schedule:run >> /dev/null 2>&1
Verify Laravel
php artisan --version
  • Test your application by visiting https://your-domain.com in a browser.
  • Ensure all .env values match your database and server setup.
  • Verify Horizon and Reverb: sudo supervisorctl status.

Step 5: Enable HTTPS

Secure your application with an SSL certificate using Certbot.

Enable HTTPS

Configure DNS
# Set up an A record for your-domain.com and www.your-domain.com pointing to your server’s IP via your DNS provider.
Obtain SSL Certificate
sudo certbot --nginx -d your-domain.com -d www.your-domain.com
Test SSL Renewal
sudo certbot renew --dry-run
Restart Nginx
sudo service nginx restart
Verify SSL
openssl s_client -connect your-domain.com:443 -servername your-domain.com
  • Ensure DNS is fully propagated before running Certbot.
  • Certbot automatically configures Nginx for HTTPS.

Step 6: Set Up Firewall

Configure the firewall to allow necessary traffic.
Allow SSH, HTTP, HTTPS, and Reverb
sudo ufw allow 22
sudo ufw allow 80
sudo ufw allow 443
sudo ufw allow 6001
Enable Firewall
sudo ufw enable
Verify Firewall Status
sudo ufw status
  • Port 6001 is the default for Laravel Reverb; adjust if using a different port in your Reverb configuration.
  • Disable root SSH access for better security: edit /etc/ssh/sshd_config and set PermitRootLogin no, then restart SSH: sudo systemctl restart sshd.

Step 7: Troubleshooting

Common issues and solutions:
  • Nginx Fails to Start:
  • Check syntax: sudo nginx -t
  • View logs: cat /var/log/nginx/error.log
  • Database Connection Errors:
  • Verify .env credentials match the PostgreSQL user and database.
  • Test connection: psql -U aleuto_user -d aleuto_db -h 127.0.0.1
  • Permission Issues:
  • Ensure www-data owns files: sudo chown -R www-data:www-data /var/www/aleuto
  • Check permissions: ls -l /var/www/aleuto
  • Application Not Loading:
  • Verify Laravel logs: cat /var/www/aleuto/storage/logs/laravel.log
  • Ensure PHP-FPM is running: sudo systemctl status php8.4-fpm
  • Horizon or Reverb Not Running:
  • Check Supervisor status: sudo supervisorctl status
  • View logs: cat /var/www/aleuto/storage/logs/horizon.log or cat /var/www/aleuto/storage/logs/reverb.log
  • Ensure packages are installed: composer require laravel/horizon laravel/reverb
  • For persistent issues, check service logs (e.g., /var/log/php8.4-fpm.log, /var/log/postgresql/postgresql-17-main.log).
  • Contact your hosting provider or consult your application’s documentation for specific requirements.

Summary

You’ve successfully set up an Ubuntu 24.04 server with Nginx, PHP 8.4, PostgreSQL 17, Node.js, Redis, Memcached, Supervisor, and a Aleuto application with Horizon and Reverb, secured with an SSL certificate. Your application should now be accessible at https://your-domain.com.