Blog

Installation of a web server on Linux

In this tutorial, we will learn how to install a web server under a Linux environment

How to install a web server on a linux environment?

In this tutorial I will present you the installation of the LAMP platform. This one means L for Linux, A for Apache, M for MySQL and P for PHP. This platform allows to get a stable web server, dynamic pages and a powerful database server.


Installation of the Apache server 

First of all, we will install Apache, which is the web server itself.
When we speak about web server, we often think about the machine, but this term also indicates the software which allows the machine to analyze the requests of a user (in http form), and to return the file corresponding to the request (or an error if the file is not found, or the request badly formulated).
\In the context of Apache, it is therefore the software that we are talking about.

Before installing the server, we will make sure that our server is up to date. To carry out these commands, you must have administrator rights.

sudo apt-get update
sudo apt-get upgrade

Once your server is up to date, we can install the Apache server.

sudo apt-get install apache2

Once the installation is finished, we will give us the access rights to the apache folder to easily administer our sites.

sudo chown -R nathan:www-data /var/www/html/
sudo chmod -R 770 /var/www/html/

instead of nathan, you have to put your user

 

Installation of PHP

PHP (the language this time) is mainly used to make a site dynamic, i.e. the user sends information to the server which sends back results modified according to this information. In contrast, a static site does not adapt to the information provided by a user. It is saved as a file once and for all, and will always deliver the same content.

sudo apt-get install php php-mbstring

Installing MySQL on your server

Now that we have implemented PHP, you will probably want to store information for use in your sites. For this, we use databases most often.
So we will set up a DBMS (Database Management System), namely MySQL.


MySQL is a free, powerful, massively used DBMS (about 56% market share of free DBMS). Once again, MySQL is a must-have for any kind of development, so you should absolutely learn and master it.

sudo apt-get install mysql-server php-mysql

Let's check that MySQL is working properly.

sudo mysql --user=root

We are now going to delete the root user and create a new root user, because the default one is only usable by the system administrator account, and is therefore not accessible to the server's PHP scripts.

DROP USER 'root'@'localhost';
CREATE USER 'root'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

Your web server is now ready.

PHPMyAdmin, to easily manage your databases

PHPMyAdmin is an application developed in PHP, and which aims to provide a simplified interface for MySQL.
It allows you for example to see quickly and in a readable way the content of your database, or to manipulate it without having to make your own MySQL queries

sudo apt-get install phpmyadmin

PHPMyAdmin will ask you several questions about its settings.


As we have already configured the database, choose no to the question about using dbconfig-common. Choose to use PHPMyAdmin for an Apache server. For the root password, this is the one you used for MySQL.

You must also activate the mysqli extension.

sudo phpenmod mysqli
sudo service apache2 reload

0 commentaire

Leave a Comments

© 2024. All rights reserved

Nathan Dierickx

.