How to Install a Local Web Server on Linux to Practice
With Apache, PHP and MySQL (LAMP) to practise web development without needing hosting.
A local web server lets you practise web development (or just understand how it works) without needing to hire hosting or expose anything to the internet.
Installing Apache (the web server)
sudo apt install apache2
sudo systemctl status apache2
Open a browser and visit http://localhost — if you see
Apache's welcome page, it's working.
Adding PHP (for dynamic sites)
sudo apt install php libapache2-mod-php
sudo systemctl restart apache2
Adding a database (MySQL/MariaDB)
sudo apt install mariadb-server
sudo mysql_secure_installation
This last one runs a wizard that sets up basic security (administrator password, removing test users).
This combination (Linux + Apache + MySQL + PHP) is known as "LAMP" — one of the most used and documented web technology stacks that exist, with years of resources available for any question that comes up.
Where your web files go
By default, Apache serves content from /var/www/html
— place your HTML/PHP files there to see them at
http://localhost.
Tip: if you prefer a more modern, isolated approach, Docker lets you set up a complete LAMP environment in containers, easier to completely clean up when you finish practising, without leaving traces installed directly on your system.
Warning: this is for practising on your own machine (localhost) — exposing a web server to the real internet requires significant additional security measures, beyond this basic installation.
Frequently asked questions
What does LAMP mean?
Linux, Apache, MySQL (or MariaDB) and PHP — the combined set of technologies that form the basis of many traditional websites, with extensive documentation available.
Is it safe to expose this server to the internet directly?
Not without significant additional measures — this basic installation is meant for practising locally (localhost), not for serving real content to the internet without additional protections.
Is Docker better than installing LAMP directly?
For practising and experimenting, Docker offers the advantage of an isolated environment that's easy to remove entirely, without leaving components installed directly on your system if you decide not to continue.