The necessary software on Linux to be able to host websites on a server is: Apache, MariaDB (formerly MySQL) and PHP, also known as LAMP, which are the initials we have bolded. As we can see, you need to install 3 programs, we will start with Apache. This tutorial is for all versions of Ubuntu, and in the tabs, you will also find all the commands to install LAMP on Red Hat-based distributions (Fedora, CentOS, etc.).
At Clouding, we offer the pre-installed LAMP Image with Ubuntu, so this manual installation is not necessary. You can directly use this image to create a server with the LAMP stack ready to go.
How to install Apache
First, access your server via SSH and execute the following command:
# apt install apache2
You can check that Apache is running by executing:
# service apache2 status
# yum install httpd && systemctl start httpd.service && systemctl enable httpd.service
You can check that Apache is running by executing:
# systemctl status httpd
You should see it as active (running):
● apache2.service – LSB: Apache2 web server Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: active (running) since Fri xxxx-xx-xx xx:xx:xx CEST; 17s ago
Once Apache is installed, if you enter the server's IP in a browser, you should see the default page:
How to install MariaDB
To install MariaDB, execute the following command:
# apt install mariadb-server mariadb-client
# yum install mariadb-server mariadb && systemctl start mariadb.service && systemctl enable mariadb.service
You can check that MariaDB is running by executing:
# service mysql status
You should see it as active and running:
● mysql.service – LSB: Start and stop the mysql database server daemon Loaded: loaded (/etc/init.d/mysql; bad; vendor preset: enabled) Active: active (running) Fri xxxx-xx-xx xx:xx:xx CEST; 17s ago
Now, proceed to configure MariaDB by running the following:
# /usr/bin/mysql_secure_installation
It will then ask a series of questions:
- The first step will ask for the "root" password for MariaDB. Press the Enter key as there is no password set.
- Next, it will ask if you want to set a password for the "root" user. It is recommended to use a password.
- The third step will ask if you want to remove anonymous users. Indicate Yes here to delete the data.
- Then it will ask if you want to disable remote login for the "root" user. Indicate Yes here to disable remote access for this user for security reasons.
- It will ask again if you want to remove the "test" database. Indicate Yes again to delete the test database.
- Finally, it will ask if you want to reload privileges. Indicate Yes.
Once you have answered all the questions, you will have MariaDB installed and ready.
How to install PHP with the Apache module
To install PHP, execute the following:
# apt install php php-cli php-mysql libapache2-mod-php && service apache2 restart
# yum install epel-release && yum install php php-mysql php-cli && systemctl restart httpd.service
To change the preference order and give priority to index.php, edit the /etc/apache2/mods-enabled/dir.conf file or the httpd equivalent.
Change the order so it looks like this:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
You will also need to restart Apache to reload the new configuration:
# service apache2 restart
To check that the PHP module is working, create a file /var/www/html/test.php with the code:
<?php phpinfo(); ?>
When you open https://server-IP/test.php in a browser, you should see the PHP information page:
We hope this article has helped you. If you have any doubts about this or any other issue related to your servers at Clouding, write to us at support@clouding.io. We are here to help! 😉