Skip to content
Free website migration on every plan, done by our team.Learn more ›
Servers

How to set up a LAMP stack on Ubuntu

Install Linux, Apache, MariaDB and PHP on an Ubuntu VPS, secure the database, add a virtual host for your domain and enable free SSL, step by step.

Short answer: On a fresh Ubuntu VPS, install Apache, MariaDB and PHP with apt, secure the database, create a virtual host for your domain, point your DNS to the server and add a free Let's Encrypt certificate with Certbot.

1. Secure the server first

See first 10 things to do on a VPS.

2. Install the stack

sudo apt update
sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql -y

3. Secure the database

Run sudo mysql_secure_installation, set a strong root password and remove test data. Create a separate database and user for each site.

4. Create a virtual host

Create a site folder, add an Apache configuration for your domain, enable it and reload Apache. Point your domain's A record to the server. See DNS records explained.

5. Add free SSL

Install Certbot and request a certificate for your domain. It renews automatically. See free SSL certificates.

6. Finish

  • Install only the PHP extensions you need.
  • Set up backups and monitoring. See server monitoring.

Prefer not to manage it yourself?

Shared hosting gives you all of this ready to use, with cPanel. See our web hosting plans.

Frequently asked questions

LAMP or LEMP?

LEMP swaps Apache for Nginx. See LiteSpeed vs Apache vs Nginx.

Can I add a control panel later?

Yes, but it's easiest on a fresh server.

Ready when you are

Host it where it performs

NVMe speed, offshore privacy and a written SLA — live in minutes on AuroxHost.