How to install Apache, PHP and MySQL (LAMP) on Debian

Post Reply
User avatar
Spray
Former staff
Former staff
Posts: 630
https://www.youtube.com/channel/UC40BgXanDqOYoVCYFDSTfHA
Joined: Wed Dec 28, 2011 10:41 pm
Location: Oregon

How to install Apache, PHP and MySQL (LAMP) on Debian

Post by Spray »

This guide will show you how to install Apache2, PHP and MySQL on a Debian Linux VDS. I'll write this assuming this is a fresh install of Debian 10, but it would work on most builds.

The easiest way to do this would be to use the VNC Console tab in your control panel, but it would be smarter to use SSH, with a client such as Putty, available here.

The first thing you'll want to do is make sure that everything is updated on the operating system. Go ahead and enter this command:

Code: Select all

sudo apt-get update

Apache2

Once that's done its business, you can start installing Apache2 with this command:

Code: Select all

sudo apt-get install apache2
It will check for the package, then ask you to confirm the installation. Press "y", then hit Enter.

When this finishes, Apache2 will already be running and your webserver will be active. You can go to "http://www.xxx.yyy.zzz/" - where "www.xxx.yyy.zzz" is the IP address for your VDS - in your web browser and see the Apache test page.


MariaDB

Next, we want to install MariaDB. We'll use the following command to install MariaDB, and the tools it needs to talk to Apache and PHP:

Code: Select all

sudo apt-get install mariadb-server
Again, we'll hit "y" and Enter to confirm the installation.

Now you'll want to do a bit of housekeeping for MariaDB:

Code: Select all

sudo mysql_secure_installation
This will clean up MariaDB and close some security holes that are set by default.

It will ask for the root password, which is currently blank, so press Enter. You'll then be asked if you'd like to create a root password, press "n", then Enter. To then remove anonymous users, press "y", then Enter. To disallow root logins remotely, press "y", then Enter. To remove the test database, press "y", then enter. You'll then want to make the changes take place immediately, so press "y", then Enter. The MariaDB installation is now finished.

Next, we'll need to create an admin user account, as we don't want to to use the root user account for a passworded login or for general server management.

First, open a local MariaDB connection using:

Code: Select all

sudo mariadb
You will see a mariadb> prompt. Use the following command to create the admin user account, ensuring you replace the 'your_password_here' field with your desired password.

Code: Select all

GRANT ALL ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'your_password_here' WITH GRANT OPTION;
Then, you will want to flush privileges so that this takes effect:

Code: Select all

FLUSH PRIVILEGES;
Finally, exit mariadb using:

Code: Select all

exit
PHP

To install PHP, run the following command:

Code: Select all

sudo apt-get install php libapache2-mod-php php-mysql
You'll need to confirm this installation with "y" and Enter, as well.

Now, you'll want to make sure .php files take priority over .html when not specifying, so you'll want to use this:

Code: Select all

sudo nano /etc/apache2/mods-enabled/dir.conf
This will open the index files list in Nano, a text editor. The list will look like this:

Code: Select all

<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
Navigating with your arrow keys, you'll want to delete index.php from where it is currently, and re-enter it just in front of index.html. After doing so, press CTRL+X to exit, then hit "y" to save, and press Enter to save to the same file we opened.

Now we need to restart Apache, using this:

Code: Select all

sudo service apache2 restart
phpMyAdmin

phpMyAdmin is no longer offered as a default repository as of Debian 10, and requires installation from source. Due to the extended length of this installation, we've separated this out into a another tutorial, linked here: viewtopic.php?f=46&t=15660

NOTE: The root directory of your webserver will be in /var/www/html/ and files can be uploaded there to be viewed in the browser.
Post Reply