Install Laravel with LAMP on Ubuntu 24.04 and you will have a Laravel 13 application served by Apache, PHP-FPM, and MariaDB in about 20 minutes. This guide uses Ubuntu’s native PHP 8.3 packages, a separate database account, UFW, and HTTPS.
Prerequisites
- A fresh 64-bit Ubuntu 24.04 LTS (Noble Numbat) VPS with at least 2 GB of RAM and 15 GB of free disk space.
- SSH access as
root, or a normal account with workingsudoprivileges and outbound HTTPS access. - A DNS record such as
YOUR_DOMAINpointing to the VPS public IP before you request a TLS certificate. - A strong database password and an email address such as
YOUR_EMAILfor certificate renewal notices. - A VPSLake Linux VPS with root access if you need a server for Laravel.
These commands assume a sudo-enabled account. If you are logged in as root, remove sudo. Replace each uppercase placeholder with your own value before running its command block.
Step 1: Install the Ubuntu 24.04 LAMP packages
Ubuntu 24.04 includes PHP 8.3 in its standard repositories, so you do not need a third-party PHP repository for this release.
grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' /etc/os-release
sudo apt update
sudo apt full-upgrade -y
sudo apt install -y apache2 mariadb-server curl ca-certificates unzip git ufw php8.3-cli php8.3-fpm php8.3-mysql php8.3-curl php8.3-mbstring php8.3-xml php8.3-zip php8.3-bcmath php8.3-intl php8.3-gd php8.3-opcache
sudo a2enmod proxy_fcgi setenvif rewrite headers
sudo systemctl enable --now apache2 php8.3-fpm mariadb
php -v
sudo systemctl is-active apache2 php8.3-fpm mariadb
The release check should show 24.04 and noble. PHP should begin with 8.3, and the service check should print three active lines.
PRETTY_NAME="Ubuntu 24.04.x LTS"
VERSION_ID="24.04"
VERSION_CODENAME=noble
PHP 8.3.x (cli) ...
active
active
active
Laravel’s deployment requirements include PHP 8.3 and extensions such as cURL, DOM/XML, Mbstring, and PDO. The packages above supply those requirements plus common production extensions.
Step 2: Create a least-privilege MariaDB database
The application gets its own database and local-only login, which avoids giving Laravel administrative access to MariaDB.
sudo mariadb-secure-installation
In the security wizard, remove anonymous users and the test database, disallow remote root login, and reload the privilege tables. Ubuntu commonly uses local socket authentication for the MariaDB administrator, so you can keep that option enabled.
Create the database and two host-specific accounts. Replace YOUR_DB_PASSWORD first; do not use a password containing a single quote in this SQL block.
sudo mariadb <<'SQL'
CREATE DATABASE laravel_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'laravel_app'@'localhost' IDENTIFIED BY 'YOUR_DB_PASSWORD';
CREATE USER 'laravel_app'@'127.0.0.1' IDENTIFIED BY 'YOUR_DB_PASSWORD';
GRANT ALL PRIVILEGES ON laravel_app.* TO 'laravel_app'@'localhost';
GRANT ALL PRIVILEGES ON laravel_app.* TO 'laravel_app'@'127.0.0.1';
FLUSH PRIVILEGES;
SQL
sudo mariadb -e "SHOW DATABASES LIKE 'laravel_app';"
The last command should return laravel_app. Do not open port 3306 in UFW; Apache and MariaDB communicate over the VPS itself.
Database (laravel_app)
laravel_app
Step 3: Install Composer with checksum verification
Composer downloads Laravel’s PHP dependencies. Verifying the installer checksum before executing it protects against a damaged or altered download.
cd /tmp
curl -fsSLo composer-setup.php https://getcomposer.org/installer
EXPECTED_CHECKSUM="$(curl -fsSL https://composer.github.io/installer.sig)"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then echo 'ERROR: Invalid Composer installer checksum'; rm -f composer-setup.php; exit 1; fi
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer --quiet
rm -f composer-setup.php
composer --version
The final line should report Composer 2.x. This follows Composer’s official programmatic installation procedure.
Composer version 2.x.x 20xx-xx-xx
Step 4: Create the Laravel application and configure its environment
Install the project under a dedicated account so Composer scripts and application files do not run with root privileges.
sudo useradd --system --home-dir /var/www/laravelapp --create-home --shell /usr/sbin/nologin laravel
sudo -u laravel -H composer create-project --no-interaction --prefer-dist 'laravel/laravel:^13.0' /var/www/laravelapp
sudo -u laravel -H cp /var/www/laravelapp/.env.example /var/www/laravelapp/.env
sudo -u laravel -H nano /var/www/laravelapp/.env
In the editor, set these values. Use the same database password from Step 2 and keep APP_KEY available for the next command.
APP_ENV=production
APP_DEBUG=false
APP_URL=http://YOUR_DOMAIN
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=laravel_app
DB_PASSWORD=YOUR_DB_PASSWORD
Generate the encryption key and run the initial migrations:
sudo -u laravel -H php /var/www/laravelapp/artisan key:generate --force
sudo -u laravel -H php /var/www/laravelapp/artisan config:clear
sudo -u laravel -H php /var/www/laravelapp/artisan migrate --force
You should see Application key set successfully followed by completed migration lines. A fresh Laravel project does not need seed data unless your own application provides seeders.
Step 5: Point Apache at Laravel’s public directory
Only the public directory should be web-accessible; the project root contains .env, source code, and dependency metadata that must stay private.
Replace YOUR_DOMAIN in this virtual host before saving it:
sudo tee /etc/apache2/sites-available/laravel.conf > /dev/null <<'APACHE'
<VirtualHost *:80>
ServerName YOUR_DOMAIN
DocumentRoot /var/www/laravelapp/public
DirectoryIndex index.php
<Directory /var/www/laravelapp/public>
AllowOverride All
Options -Indexes +FollowSymLinks
Require all granted
</Directory>
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/laravel-error.log
CustomLog ${APACHE_LOG_DIR}/laravel-access.log combined
</VirtualHost>
APACHE
sudo a2dissite 000-default.conf
sudo a2ensite laravel.conf
sudo apachectl configtest
sudo systemctl reload apache2
Syntax OK confirms that Apache accepted the file. The PHP-FPM Unix socket keeps PHP execution on the VPS instead of exposing a separate application port.
Step 6: Set permissions and enable UFW
Apache needs read access to the application and write access only to Laravel’s runtime directories, so apply narrow ownership and modes.
sudo chown -R laravel:www-data /var/www/laravelapp
sudo find /var/www/laravelapp -type d -exec chmod 0750 {} +
sudo find /var/www/laravelapp -type f -exec chmod 0640 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type d -exec chmod 0770 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type f -exec chmod 0660 {} +
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw --force enable
sudo ufw status verbose
UFW should list SSH, HTTP, and HTTPS while leaving MariaDB’s port closed. If your SSH daemon uses a nonstandard port, allow that port before enabling UFW.
Step 7: Add HTTPS with Certbot
Request the certificate only after YOUR_DOMAIN resolves to this VPS and ports 80 and 443 are reachable from the Internet.
sudo apt install -y certbot python3-certbot-apache
sudo certbot --apache --redirect -d YOUR_DOMAIN -m YOUR_EMAIL --agree-tos --no-eff-email
sudo -u laravel -H sed -i 's#^APP_URL=.*#APP_URL=https://YOUR_DOMAIN#' /var/www/laravelapp/.env
sudo -u laravel -H php /var/www/laravelapp/artisan config:clear
sudo -u laravel -H php /var/www/laravelapp/artisan config:cache
Certbot adds the TLS virtual host and redirects HTTP to HTTPS. If DNS is not ready, postpone this step instead of running a production login page over plain HTTP.
Verify the Laravel installation
Use these checks to confirm the services, configuration, migrations, and HTTPS response:
sudo systemctl is-active apache2 php8.3-fpm mariadb
sudo apachectl configtest
sudo -u laravel -H php /var/www/laravelapp/artisan --version
sudo -u laravel -H php /var/www/laravelapp/artisan migrate:status
curl -fsSI https://YOUR_DOMAIN/ | sed -n '1,5p'
Expect three active lines, Syntax OK, a Laravel 13 version, successful migration statuses, and an HTTP success response.
active
active
active
Syntax OK
Laravel Framework 13.x
HTTP/2 200
Open https://YOUR_DOMAIN in a browser. The default Laravel page proves that Apache reaches public, PHP-FPM executes the framework, and the TLS virtual host is serving the application.
Troubleshooting
E: Unable to locate package php8.3-fpm
The package index may be stale, or the server may not actually be Ubuntu 24.04. Confirm the codename is noble, then refresh APT; do not mix packages from another Ubuntu release.
grep -E '^(PRETTY_NAME|VERSION_ID|VERSION_CODENAME)=' /etc/os-release
sudo apt update
sudo apt install -y php8.3-cli php8.3-fpm php8.3-mysql
SQLSTATE[HY000] [1045] Access denied
The password in .env does not match the MariaDB account, or Laravel is using cached configuration. Test the account over TCP and clear the cache after correcting the value.
mariadb -h 127.0.0.1 -u laravel_app -p laravel_app -e 'SELECT 1;'
sudo -u laravel -H php /var/www/laravelapp/artisan config:clear
sudo -u laravel -H php /var/www/laravelapp/artisan migrate --force
Enter the real password when prompted. If the direct query fails, reset the application account rather than granting it global privileges.
403 Forbidden or Permission denied
Apache cannot traverse the project or write to Laravel’s runtime folders. Reapply the application owner, group, and limited modes without using chmod 777.
sudo chown -R laravel:www-data /var/www/laravelapp
sudo find /var/www/laravelapp -type d -exec chmod 0750 {} +
sudo find /var/www/laravelapp -type f -exec chmod 0640 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type d -exec chmod 0770 {} +
sudo find /var/www/laravelapp/storage /var/www/laravelapp/bootstrap/cache -type f -exec chmod 0660 {} +
sudo systemctl reload apache2
503 Service Unavailable or PHP source is downloaded
PHP-FPM may be stopped, or the Apache handler may point at a socket that does not exist. Check the service and the exact socket named in laravel.conf.
sudo systemctl status php8.3-fpm --no-pager
sudo test -S /run/php/php8.3-fpm.sock && echo 'PHP-FPM socket exists'
sudo apachectl configtest
sudo systemctl restart php8.3-fpm apache2
The socket test should print PHP-FPM socket exists, and Apache should return Syntax OK.
Hardening
- Keep
APP_DEBUG=false, back up/var/www/laravelappand MariaDB, and apply Ubuntu security updates during a maintenance window. - Keep port 3306 closed and restrict SSH to trusted source addresses in your provider firewall when possible.
- Test renewal with
sudo certbot renew --dry-run; use VPSLake’s UFW firewall generator when you need to plan additional rules.
FAQ
Does Ubuntu 24.04 include the PHP version Laravel needs?
Yes. Ubuntu 24.04’s native repositories provide PHP 8.3, which satisfies Laravel 13’s minimum PHP version. Using the release’s own packages also avoids adding a separate PHP repository to a fresh server.
Can I install Laravel without a domain name?
You can test the application with an IP address or a temporary local hosts-file entry, but a public DNS name is needed for a normal Let’s Encrypt certificate. Configure HTTPS before accepting passwords, payments, or other sensitive data.
Why does Apache use the public folder?
Laravel stores .env, vendor, and application source outside public. Serving only that directory lets Apache route requests through index.php without making configuration files downloadable.
Should I use php artisan serve on this VPS?
No. artisan serve is intended for development and is not a replacement for Apache, PHP-FPM, firewall rules, or TLS. Use the configured Apache virtual host for the running site.