How to set up Linux, Apache, MariaDB & PHP (LAMP) on a Debian 10 VM
Created by Admin at 09-07-2020 10:07:48 +0200LAMP is a bundle of open source software used to run web servers. In this tutorial we will go through the installation of three packages: Apache, MySQL and PHP. We will skip Linux since our vm is already running Debian 10 and this can easily be acquired through one of the default Linux installations on www.cloudcontainers.net.
Before we start installing anything, it's good practice to make sure all of our repositories are up-to-date using the following commands:
$ sudo apt update -y $ sudo apt upgrade -y
Install Apache2
$ sudo apt install apache2 -y # How to find your IP: $ ip addr | grep inet
To check if Apache installed correctly: navigate to your IP address in a browser, you should now see a page telling you everything works correctly like this:
Install MariaDB
Next we'll install a database management system to host our webserver's database.
Use the -y flag to confirm the program can use some disk additional space.
$ sudo apt install mariadb-server -y
After the installation, we run the secure installation script that comes with MariaDB. This will help you configure your system to be more secure.
$ sudo mysql_secure_installation
Your root password will be prompted, next to some additional questions. You can answer yes to all these questions.
Now, we're almost finished, we only have PHP left to install.
Install PHP
Use the following command to install PHP:
$ sudo apt install php libapache2-mod-php php-mysql -y
Next we'll want to make our Apache webserver prefer .php files over .html files. Open the dir.conf file with the following command to start editting:
$ sudo nano /etc/apache2/mods-enabled/dir.conf
Edit the file so as to move index.php to the front of the line. When you're done, your dir.conf file should look like this.
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
Save the dir.conf file and restart apache:
$ sudo systemctl restart apache2
Congratulations, you've now installed LAMP!
Test PHP
Despite having installed PHP, you might still want to test it.
We can easily test it by adding a script that will output some data about our server.
create a new php file:
$ sudo nano /var/www/html/info.php
And add the following script:
?php phpinfo(); ?>
Save and close the file. Go to your browser and navigate to this address:
http://YOURDOMAIN-IP/info.php
You should get a screen, displaying all kinds of server information.
Finally, delete the php script so no unauthorized users get acces to your server's information.
$ sudo rm /var/www/html/info.php
Congratulations, you've now installed and tested LAMP on your Debian 10 installation!
Comments are turned off.