How to install LAMP in CentOS? [Quick Guide]

8:30 pm May 11, 201715707

I. introduction

in this step-to-step tutorial under CentOS, we will see how to set up a LAMP server: Linux Apache – MariaDB-PHP, to prepare your Linux system to hosting applications.

II. Installation of the web server Apache

the first step in the MariaDB-Apache-PHP architecture is to install and configure Apache. So we’re going to connect to the application account, previously created and run the following command:

 $ sudo yum install httpd 

this task runs with the privileges of the County root, since it uses a sudo command. The password requested, is the account of work, i.e., according to the example above, the account wiki.

Before you can start the service, it must make the daemon httpd accessible during the reboot the system:

 $ sudo systemctl enable httpd.service $ sudo systemctl start httpd.service 

at this stage, we can verify that the service is active and operational by connecting to the following url: http://. If the name is not stated in the directory of the company DNS names, you can always connect to the url referring to the IP address of the server. We should then see the screen below, on the open browser:

reminder: in order to know the IP address of a server, you can run the following command which will inevitably return the IP address of the local server:

 $ sudo ip addr sho eth0 | grep inet | AWK '{print $2}';. [sed's//*$//'

Si you do not want to open a browser, it is also possible to use the curl tool, that allows to respond to HTTP requests, without for as much consume exorbitant resources, a browser such as Firefox:

 $ curl http://

III. Data base MariaDB Server installation

you can then install the MariaDB database (in lieu of the MySQL engine, bought by Oracle Corp.), in order to store the information to access the wiki site:

 $ sudo yum install mariadb mariadb-server 

once the installation is complete, you can start the service mariadb to secure its access :

 $ sudo systemctl start mariadb 

one can then run the script mysql_secure_installation on the new instance MariaDB, to remove the default options, which are not always wise and lock a little more access to the system database:

 $ sudo mysql_secure_installation 

the script Wizard offers first place to initialize the password of the root of the instance account :

for the rest of the questions proposed by this script, you can leave the default options and tap [ENTER] to each of them.

We can then make the active service during each reboot of the operating system:

 $ sudo systemctl enable mariadb.service 

IV. The content PHP Server installation

now that the database instance is installed and ready to be used, you can also install the PHP part to display dynamic content. This information will be distributed via the base MariaDB and displayed through the Apache Server:

 $ sudo yum install php php-mysql 

at this stage, must then restart the httpd service to take into account the new PHP layer built into the Apache web server:

 $ sudo systemctl restart httpd.service 

in order to expand the possibilities of the PHP interpreter You can also add modules below. This is not a requirement, only an option:

– php – bcmath.x86_64: PHP applications using the bcmath library.
– php – cli.x86_64: for PHP CLI command line.
– php – common.x86_64: standard files for PHP.
– php – dba.x86_64: applications PHP database abstraction layer.
– php – devel.x86_64: files needed for the construction of PHP extensions.
– php – embedded.x86_64: PHP library for embedded applications.
– php – enchant.x86_64: extension of Enchantment for PHP applications.
– php – fpm.x86_64: PHP FastCGI process manager.
– php – gd.x86_64: module for PHP applications using the gd library.

In order to know the existing modules on the system, you can execute the following statement:

 $ sudo yum search php-

you can have even more information about a package, in particular, with the command below:

 $ sudo yum info  

example: information about the package php – fpm:

 $ sudo yum info php - fpm 

one can then check that the system is properly configured and that the PHP options are taken into account. To do this, simply create a PHP script, that will be called info.php. For this script to be recognized by the Apache web server, it must be saved in a special directory called web root.

In a CentOS 7 distribution by default, this directory is located in/var/www/html. So we’ll have to edit a file info.php in this same directory, with the following content:


, by running the url http:///info.php, we should be able to visualize the PHP homepage, below:

ATTENTION: code test includes no space between “?” and “php”. If there is, we must delete it, because the result would be a blank page!

That is, your under CentOS LAMP server is ready to host your applications!