Hosting & VPS Guides

Installing a LAMP Stack on Ubuntu Server

Practical guide to installing Apache, MySQL or MariaDB, PHP and SSL on Ubuntu Server for WordPress, PHP websites and web applications.

By CheckDomainHealth Editorial Team Reviewed by Dionis Ceban Updated Jun 28, 2026 10 min read Beginner

Introduction

A LAMP stack is one of the most common server setups for hosting PHP websites. LAMP stands for Linux, Apache, MySQL or MariaDB, and PHP. On an Ubuntu VPS, this stack can run WordPress, custom PHP applications, landing pages, dashboards and many CMS-based websites.

Installing LAMP is only the first part. A usable production setup also needs firewall rules, virtual hosts, correct file permissions, database security, SSL certificates, backups, updates and monitoring.

Quick answer

Quick answer

To install a LAMP stack on Ubuntu, update the server, install Apache, install MySQL or MariaDB, install PHP and required extensions, configure an Apache virtual host, point DNS to the VPS, enable SSL, test PHP, secure the database, configure backups and monitor website status.

What is LAMP?

A LAMP stack is a web hosting environment made of four parts:

Linux

  • The operating system. In this guide, Ubuntu Server.

Apache

  • The web server that receives browser requests and serves websites.

MySQL or MariaDB

  • The database server used by WordPress, CMS platforms and PHP applications.

PHP

  • The programming language/runtime used by WordPress and many web applications.

LAMP is popular because it is stable, widely documented and compatible with many PHP-based websites.

When to use LAMP

A LAMP stack is a good choice when you need to host PHP-based websites or applications.

Good use cases:

  • WordPress websites
  • WooCommerce stores
  • PHP applications
  • Laravel apps
  • simple business websites
  • landing pages
  • CMS platforms
  • client websites
  • staging environments
  • development servers

LAMP may not be ideal when:

  • your app uses Node.js only
  • you need Nginx-specific reverse proxy setup
  • you prefer a managed control panel
  • you do not want server administration
  • you need containerized deployment

For beginners, LAMP is a practical first manual web stack because it is common and well supported.

Before installation

Before installing LAMP, prepare the VPS.

Check:

  • Ubuntu Server is supported
  • SSH access works
  • server packages are updated
  • firewall allows SSH
  • domain DNS access is available
  • server IP address is known
  • backup plan exists
  • root or sudo user access is available
  • expected PHP version is known
  • website files and database requirements are known

Do not move production websites before the stack is installed, secured, backed up and tested.

Install Apache

Apache is the web server that will serve your website.

Update packages
sudo apt update
sudo apt upgrade -y
Install Apache
sudo apt install apache2 -y
Check Apache status
systemctl status apache2
Allow Apache through firewall
sudo ufw allow 'Apache Full'
sudo ufw status
Test in browser
http://your-server-ip

If Apache is installed correctly, the default Ubuntu Apache page should load from the server IP.

Install MySQL or MariaDB

WordPress and many PHP applications need a database. On Ubuntu, you can use MySQL or MariaDB depending on your preference and compatibility requirements.

Install MySQL
sudo apt install mysql-server -y
Check MySQL status
systemctl status mysql
Run secure installation
sudo mysql_secure_installation
Alternative MariaDB
sudo apt install mariadb-server mariadb-client -y
sudo mysql_secure_installation

Use strong database passwords and avoid using the root database user for website applications.

Install PHP

PHP runs the application code for WordPress and many CMS platforms.

Install PHP and common extensions
sudo apt install php libapache2-mod-php php-mysql php-cli php-curl php-gd php-mbstring php-xml php-zip php-intl -y
Check PHP version
php -v
Restart Apache
sudo systemctl restart apache2

Some applications require specific PHP versions or extensions. Always check the application requirements before deployment.

Create an Apache virtual host

A virtual host tells Apache which domain should serve which website directory.

Example structure:

  • domain: example.com
  • web root: /var/www/example.com/public_html
Create directory and test file
sudo mkdir -p /var/www/example.com/public_html
sudo chown -R www-data:www-data /var/www/example.com
sudo chmod -R 755 /var/www/example.com
echo "<h1>example.com is working</h1>" | sudo tee /var/www/example.com/public_html/index.html
Create Apache config
sudo nano /etc/apache2/sites-available/example.com.conf
Virtual host example
<VirtualHost *:80>
    ServerName example.com
    ServerAlias www.example.com
    DocumentRoot /var/www/example.com/public_html

    <Directory /var/www/example.com/public_html>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/example.com-error.log
    CustomLog ${APACHE_LOG_DIR}/example.com-access.log combined
</VirtualHost>
Enable site
sudo a2ensite example.com.conf
sudo a2enmod rewrite
sudo apache2ctl configtest
sudo systemctl reload apache2

Replace example.com with your real domain. Check Apache config before reloading.

DNS setup

To make the domain load from the VPS, point DNS to the server.

Common records:

  • A record for example.com → VPS IPv4 address
  • AAAA record for IPv6 if used
  • CNAME for www → example.com
  • MX records should remain unchanged if email is hosted elsewhere

If only the website is moving to this VPS, do not change MX, SPF, DKIM or DMARC records unless email is also moving.

Check DNS before pointing your domain

Use DNS Lookup to confirm A, AAAA and CNAME records before SSL issuance and website testing.

Run DNS Lookup →

Enable SSL with Certbot

After DNS points to the VPS and Apache serves the domain, install SSL.

Install Certbot
sudo apt install certbot python3-certbot-apache -y
Issue certificate
sudo certbot --apache -d example.com -d www.example.com
Test renewal
sudo certbot renew --dry-run
Check Apache
sudo systemctl reload apache2

SSL will only issue correctly if DNS points to the server and ports 80/443 are reachable.

Test PHP

Create a temporary PHP info file to confirm PHP is working.

Create and test PHP file
echo "<?php phpinfo(); ?>" | sudo tee /var/www/example.com/public_html/info.php
Open in browser
https://example.com/info.php
Remove after testing
sudo rm /var/www/example.com/public_html/info.php

Do not leave phpinfo files publicly accessible. They expose server configuration details.

File permissions

File permissions affect both security and website functionality.

General guidance:

  • website files should not be globally writable
  • web root should be owned consistently
  • uploads/cache directories may need write access
  • avoid chmod 777
  • use separate users for deployments where possible
  • keep sensitive config files protected

Wrong permissions can cause 403 errors, failed uploads, broken updates or security risks.

Backups and updates

A LAMP stack needs regular maintenance.

Back up:

  • website files
  • databases
  • Apache virtual host configs
  • SSL notes/configuration
  • application environment files
  • uploaded media

Maintain:

  • Ubuntu security updates
  • Apache updates
  • PHP updates
  • database updates
  • application/CMS updates
  • plugin/theme updates if WordPress is used

Store backups off-server. A backup only on the same VPS may be lost if the server fails.

Monitoring

Monitor the stack after setup.

Check:

  • website status
  • Apache service
  • database service
  • SSL expiry
  • disk usage
  • CPU and memory
  • error logs
  • database backups
  • response time
  • HTTP status codes

A LAMP stack can appear healthy until disk fills, database stops or Apache/PHP errors start. Monitoring helps catch issues earlier.

Common problems

Apache not running

High

The web server is stopped or failed to start.

Next step: Check systemctl status apache2 and Apache error logs.

Firewall blocks HTTP/HTTPS

High

The server works locally but cannot be reached publicly.

Next step: Allow ports 80 and 443 through the firewall.

DNS points to wrong IP

Medium

The domain does not reach the VPS.

Next step: Check A/AAAA records and DNS propagation.

PHP code downloads instead of running

High

PHP module or PHP-FPM integration is not configured correctly.

Next step: Install PHP Apache module or correct PHP handler.

Database connection fails

High

The application cannot connect to MySQL/MariaDB.

Next step: Check database name, user, password, host and service status.

Apache virtual host not enabled

Medium

Apache serves default page or wrong site.

Next step: Enable the site config and reload Apache.

SSL certificate fails to issue

Medium

DNS, firewall or domain validation is not ready.

Next step: Confirm DNS points to server and ports 80/443 are open.

Permissions cause 403 errors

Medium

Apache cannot read the website files.

Next step: Review ownership and directory permissions.

phpinfo left public

Low

Server configuration details are exposed.

Next step: Delete info.php after testing.

No database backups

High

Data can be lost after failure or mistake.

Next step: Set automated database backups.

How to install LAMP safely

  1. Step 1: Update Ubuntu

    Apply package updates before installing services.

  2. Step 2: Install Apache

    Install and test the web server.

  3. Step 3: Install MySQL or MariaDB

    Install database server and run secure installation.

  4. Step 4: Install PHP and extensions

    Install PHP plus extensions required by your application.

  5. Step 5: Create virtual host

    Configure Apache for your domain and web root.

  6. Step 6: Point DNS

    Set A/AAAA/CNAME records to the VPS.

  7. Step 7: Enable SSL

    Use Certbot or another SSL method after DNS works.

  8. Step 8: Test PHP and remove test files

    Confirm PHP works, then delete phpinfo files.

  9. Step 9: Set backups

    Back up files, databases and configuration.

  10. Step 10: Monitor services

    Track website status, SSL, Apache, database, disk and logs.

Useful LAMP commands

Useful LAMP commands
Check Apache:
systemctl status apache2

Restart Apache:
sudo systemctl restart apache2

Test Apache config:
sudo apache2ctl configtest

Check enabled sites:
ls /etc/apache2/sites-enabled/

Check Apache error log:
sudo tail -100 /var/log/apache2/error.log

Check MySQL:
systemctl status mysql

Log into MySQL:
sudo mysql

Check PHP version:
php -v

List PHP modules:
php -m

Check disk:
df -h

Check listening ports:
sudo ss -tulpn

Commands are illustrative and may vary by Ubuntu version and installed packages.

WordPress on LAMP

WordPress works well on LAMP, but it needs proper PHP extensions, database setup and file permissions.

Check:

  • PHP version supported by WordPress
  • php-mysql installed
  • upload size limits
  • memory limit
  • rewrite module enabled
  • SSL configured
  • permalinks working
  • database user with limited permissions
  • backups for files and database
  • caching plugin or server cache if needed

For WordPress, enable Apache rewrite module and allow .htaccess overrides in the virtual host if using permalink rules.

Frequently asked questions

What does LAMP mean?

LAMP means Linux, Apache, MySQL or MariaDB, and PHP.

Is LAMP good for WordPress?

Yes. LAMP is one of the most common stacks for WordPress hosting.

Do I need Apache or Nginx?

This guide uses Apache. Nginx is also popular, but configuration is different.

Should I use MySQL or MariaDB?

Both can work for many PHP applications. Check your application requirements.

Why does my domain show the default Apache page?

The virtual host may not be configured, enabled or matched to the domain.

Why did SSL fail?

DNS may not point to the server yet, ports 80/443 may be blocked, or the domain may not resolve correctly.

Can I host multiple websites on one LAMP server?

Yes. Create separate virtual hosts and web roots for each domain.

Use these free tools to verify your configuration after applying changes.

Browse all Hosting & VPS guides →

Need help applying this fix?

Send us your domain, report link or issue details. CheckDomainHealth will review the request and route it to the right technical team if hands-on support is needed.

Get Help Run Domain Health Check

Was this guide helpful?

Your feedback helps us improve our guides for everyone.