How to Set Up a LAMP Stack on Debian
-
A LAMP (Linux, Apache, MySQL, PHP) stack is a popular web hosting platform typically used to run dynamic websites and web apps. This guide explains how to easily install a LAMP stack on Debian.
Install Apache As the most popular web server software, Apache forms the “A” in our LAMP stack. We install it from the Debian repos:
sudo apt update sudo apt install apache2
Check that Apache is running properly by accessing http://your_server_ip in a browser. The default Apache test page should appear.
Install MySQL Database The MySQL open source database powers the “M” in LAMP. It stores app data to be served dynamically via the web server. Install MySQL Community Server like so:
sudo apt install mysql-server
At the prompt, set a password for the MySQL root user to secure it. Confirm the password again when asked.
Install PHP for Dynamic Content Now for the “P” in LAMP - PHP. This is the scripting language that adds dynamic capabilities and connects our web apps to the MySQL databases:
sudo apt install php libapache2-mod-php php-mysql
We also install the php-mysql package specifically to allow PHP scripts to access our MySQL databases.
Test PHP Processing on Apache Create a simple file info.php inside /var/www/html folder with this content:
php
<?php phpinfo();
Access page via http://your_ip/info.php and check the page loads details about PHP successfully.
That completes our LAMP stack installation! You can now place your PHP apps inside
/var/www/html
folder to deploy them. They will have access to MySQL and dynamic processing via PHP on the Apache web server.