How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts
A complete step-by-step guide to building a reliable Ubuntu web server stack with Apache, MySQL, PHP, and virtual host configuration.
Ashim Rudra Paul
Software Engineer

How to Create a Robust Ubuntu Web Server Using Apache, MySQL, PHP, and Virtual Hosts
Importance of a Web Server
A web server is the backbone of any website, serving as the platform that delivers content to users across the globe. The efficiency and reliability of your web server are critical to the success of your online presence.
Overview of Ubuntu, Apache, MySQL, PHP, and Virtual Hosts
In this guide, we will set up a complete web server environment on Ubuntu using:
- Apache as the web server
- MySQL as the database server
- PHP as the scripting language
- Virtual Hosts to run multiple websites on one server
Purpose of This Guide
This article provides a detailed, step-by-step process for setting up a robust web server on Ubuntu, tailored for both beginners and advanced users.
Preliminary Setup
Choosing the Right Hardware
Before installing software, ensure your hardware is suitable for expected traffic and workload.
Consider:
- CPU performance
- RAM capacity
- SSD/HDD storage size and speed
Installing Ubuntu Server
- Download the latest Ubuntu Server ISO from the official Ubuntu website.
- Create a bootable USB drive.
- Install Ubuntu Server using the on-screen installer.
Updating and Upgrading Ubuntu
After installation, update your packages:
Installing Apache
Understanding Apache Web Server
Apache is one of the most widely used web servers, known for robustness, flexibility, and extensive module support.
Install Apache
Start and Enable Apache
Verify Apache Installation
Installing MySQL
Understanding MySQL Database Server
MySQL is a powerful relational database management system used to store and manage data for websites and applications.
Install MySQL
Secure MySQL Installation
Run the built-in security script:
Follow the prompts to:
- Set root password
- Remove anonymous users
- Disable remote root login
- Remove test database
Test MySQL Functionality
Installing PHP
Understanding PHP Scripting Language
PHP is a popular server-side language used for dynamic web applications and database integration.
Install PHP and Core Modules
Install Additional PHP Extensions
Integrate PHP with Apache
You may need to update Apache directory index priority:
Configuring Virtual Hosts
What Are Virtual Hosts?
Virtual hosts allow multiple websites/domains to run on one Apache server. Each site can have its own:
- Document root
- Logging configuration
- Domain settings
Create Site Directory
Set Permissions
Create Virtual Host Config File
Add:
Enable the Virtual Host and Validate Apache Config
Restart Apache
Edit Hosts File for Local Testing
Add this line:
Test Virtual Host
Open this in your browser:
If configured correctly, your demo site should load from /var/www/demo.
Final Thoughts
With this setup, you now have a complete LAMP stack on Ubuntu:
- Linux (Ubuntu)
- Apache
- MySQL
- PHP
You can now host multiple websites efficiently using virtual hosts and scale your server setup as your projects grow.


