6 Ways to Install Linux, Apache, PHP And MySQL On CentOS (LAMP Stack)
Edit Article

  • 1 Editor

Six Methods:Install LAMP on CentOSInstalling Apache Web Server on CentOSInstalling PHP5 on CentOSInstalling MariaDB MySQL Server ON CentOSInitial Configuration for MariaDBInstaling PhpMyAdmin

I hope that you liked all the previous articles that I have written for you. This article is a very basic one. It is written for all the newbies. This will help guide you guys in installing LAMP stack with MariaDB MySQL, PHP5 and Apache on CentOS7. This article includes screenshots and pictures of all the steps that I have mentioned in the article. The difference between CentOS 6 and CentOS 7 command that will be used in this article will be just of systemctl command.LAMP is a short form of all the necessary software that is needed to run a server. LAMP initially means Linux, Apache, MySQL and PHP. This has now changed after the introduction of MariaDB. MariaDB is basically a branch taken out of MySQL which was considered as the replacement for MySQL. MariaDB was developed by the same developers who developed MySQL. All the features that are present in MySQL can also be found in MariaDB. Another great thing about MariaDB is that it features library binary equivalency and the exact matching with all the MySQL APIs and all of its commands. This means that if there is application that has the ability to run with MySQL then it surely will also run on MariaDB without any glitches. I have already explained in my earlier articles what Apache and PHP are so I will not be explaining it here. We will now be starting the step by step guide:

Method 1 of 6: Install LAMP on CentOS

  1. 1
    • The first thing you will need is a server / VPS that is running CentOS 7. I will strongly suggest that you use CentOS 7 x86_64 minimal if it is available.
    • You will need to have a basic knowledge about how to use Putty or Terminal if you want to access the server by SSH.
    • You should know the basic UNIX commands that are needed to manage an unmanaged server.
    • A cup of coffee and some spare time of yours.

Method 2 of 6: Installing Apache Web Server on CentOS

  1. 1
    As you know that Apache is very easily the most popular web server, because of this very reason Apache is normally included in all of the recent Linux Distro. Apache’s installation is going to be very easy because of this inclusion in the Distro. One thing needs be cleared out before you go on reading the next step and installing Apache. All the commands that you will see in this guide will be written without using the “sudo” prefix. You can use as user who as root privileges but in this guide I will be logging into the server as root. If in case you have disable the root login and are logged in by using some other username that has root capabilities then you can easily add the “sudo” prefix before the commands. But if you want to switch as root then you my simply type su and then hit enter. After hitting enter you may give in your password twice and you will be switched to root. You need to login to your server by using Terminal or Putty. 
    1 11.jpg
  2. 2
    You will now issue the command to install Apache 2.4 on your CentOS 7 server. The command to install Apache is given below:  As can be seen in the screenshot below, the command has not changed.yum install httpd –y
    2 9.jpg
  3. 3
    After the process of installation has finished, you will see a screen that will look like this.
    3 12.jpg
  4. 4
    You will now have Apache 2.4 installed on your VPS. You will now start the service by issuing the command that is given below: systemctl start httpd.service or service httpd start 
    4 8.jpg
      ,The available commands that you can use are given below: systemctl status|start|stop|restart|reload httpd.service # OR, old command : service httpd status|start|stop|restart|reload
  5. 5
    If you want to check that Apache is running or not then you can just open your favorite web browser and try to access your server by entering it IP address: http://xxx.xxx.xxx.xxx Once you access the server by using its IP address you will see that you are greeted by the Apache’s default welcome page.
    5 8.jpg
      , As you can see that in this example Apache v2.4.6 is installed. You may also issue this command directly systemctl status httpd.service Once the command is give, you will see a screen like the one below:
    6 7.jpg
      You will now enable Apache web server to run every time automatically when your server reboots by giving the following command: systemctl enable httpd.service

Method 3 of 6: Installing PHP5 on CentOS

  1. 1
    The default command that is used to directly install PHP5 is:yum install php –yYou will now issue this command and install PHP using yum. That was a really simple command wasn’t it? Since we will firstly be installing MySQL so we will need some PHP MySQL modules along with any other modules that your application or website may need. If you want to view all the modules that are available then you may just issue this command: yum search php- If you are confused then here is no need to be confused. You can simply issue this simple command that is given below. This command contains most of the common PHP modules which most websites need to run with: yum install php php-common php-cli php-devel php-gd php-imap php-intl php-mysql php-process php-xml php-xmlrpc php-zts –y
    7 9.jpg
  2. 2
    Once you are done typing in this command, you will see a similar scree on your end:
    8 8.jpg
  3. 3
    If you want to see which version in installed on your server then you just type in php –v
    9 7.jpg
    In the guide I am using PHP v 5.4.16

Method 4 of 6: Installing MariaDB MySQL Server ON CentOS

  1. 1
    Installing MariaDB MySQL server is extremely easy if you want to install it on your CentOS 7 server. We will now again make use of the yum package manager:yum install mariadb-server mariadb –y
    10 7.jpg
  2. 2
    You will see a screen like the one below after the command is executed:
    11 6.jpg
  3. 3
    MariaDB is finally installed on your CentOS server. You can now restart it for the first time by keying in this simple systemctl command: systemctl start mariadb.service
    12 6.jpg
    If you want to view the status of MariaDB, just type: systemctl status mariadb

Method 5 of 6: Initial Configuration for MariaDB

  1. 1
    The service is now running but there is something that you must resolve at once. You need to configure MariaDB for the very first time and that includes setting up your MySQL root password. To do that you  need to issue this command: mysql_secure_installationYou will now see a screen that will have a sies of questions for you to answer. The first and main thing to do here is set up your MySQL root password. Rests of the things are just a formality and to skip through it quickly, you can just hit “Enter” key repeatedly when prompted to set the default values.
    13 6.jpg
  2. 2
    To set MariaDB to run automatically on every reboot, you must enter this command:systemctl enable mariadb.service
    14 4.jpg
  3. 3
    Once you’re done, restart MariaDB to test that the newly installed MariaDB is running by logging in as root:mysql -u root –p
    15 6.jpg
    , The screenshot clearly mentions that we are running MariaDBv5.5.37.
  4. 4
    Now you will need to run a test. This test will determine if Apache and PHP are running properly and are able to process any and all *.php files. You will now make a php info page. For making this page you the below given command by restarting Apache:echo “” > /var/www/html/info.php
    16 4.jpg
  5. 5
    Restarting Apache:systemctl restart httpd.serviceYou will now access the php page that you just created by opening your browser.http://xxx.xxx.xxx.xxx/info.phpA page will open that will be similar to the one given below:
    17 3.jpg

Method 6 of 6: Instaling PhpMyAdmin

  1. 1
    The server that you have now has MariaDB, PHP and Apache installed on it. Once all of them are installed, its safe to now install a very popular web based data base management system known as PHPMyAdmin. PHPMyAdmin allows you the ability to manage your database with ease and without having to go and log in through SSH and entering several lines of commands. The sad thing is that this amazing software is currently not available for CentOS 7 default repositories. In this case you have no choice but to add a third party repo like EPEL or RPMForge.
  2. 2
    Method 1: By Using RPMForge You first need to download the rpm file  by issuing the following command: wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
    18 3.jpg
  3. 3
    Now you will enable the repository. Once it is enabled, go ahead and delete the .rpm file as this file in no longer need.rpm -ivh rpmforge-release-* rm rpmforge-release-*
    19 2.jpg
  4. 4
    Method 2: By Using EPEL Firstly, you need to download the .rpm file: wget http://download.fedoraproject.org/pub/epel/beta/7/x86_64/epel-release-7-0.2.noarch.rpm The url that is given above is still in the beta version but if the repository is out of the beta status then most likely the link will be different. If that is the case then you can find the latest download url at Fedora Project Website. Now you will do the same as in method 1. Delete the .rpm after enabling the repository. rpm -ivh epel-release* rm epel-release*
  5. 5
    The next step is to install using yum:yum install phpmyadmin -y The screenshot if the screen is given below.
    20 1.jpg
  6. 6
    That was about it. You now have PHPMyAdmin installed on your VPS. I think it would be best if you configure the newly installed PHPMyAdmin a little bit before you go ahead and use it. The first that you will need to do is backup PMA’s default configuration file: cp /etc/httpd/conf.d/phpMyAdmin.conf /etc/httpd/conf.d/phpMyAdmin.conf.old
  7. 7
    Now you will see the content of PHPMyAdmin.conf on your screen. You now have to allow connection that are coming form remote hosts by editing a few lines of code inside the section . The screen before was like this:
    21 1.jpg
  8. 8
    And afterwards it will be like this:
    22 1.jpg
  9. 9
    In any case those few lines of code need to be edited next.This is the before screen:
    23 1.jpg
  10. 10
    This is the screen afterwards:
    24 1.jpg
  11. 11
    Now the code should look somewhat like this:         # Apache 2.4             Require all granted                 # Apache 2.2      #Order Deny,Allow      #Deny from All      AllowOverride None      Options None      Allow from All      Require all granted    Once you are dine with this just save and exit the editor.
  12. 12
    You will now again have to restart Apache.systemctl restart httpd.serviceYou may now test and open PMA on your web browser by using your server’s IP address:http://xxx.xxx.xxx.xxx/phpmyadminhttp://xxx.xxx.xxx.xxx/phpmyadminOnce this is done, the default login page will opened that looks somewhat it this:
    25 1.jpg


  • That all for this article! You can host any and all websites or blogs that are present or kept in that server, even WordPress.

Article Tools

Did this article help you?


an Author!

Write an Article