How To Install Linux, Apache, MySQL, PHP (LAMP) stack On CentOS 7

For web development what you need is LAMP on your linux machine.

Following are the steps to install LAMP

  1. Get the VPN server from
    2. For other cheaper options for the hosting where we simply need to host anyone website in PHP
      1. Visit this link: Shared Hosting Plans
  2. Once you purchase the VPN or shared Server as mentioned above or in case you already have a server in place with you and its OS is CENTOS, refer below simple steps to get your server ready
  3. Install Apache

    1. to install apache in centos  trigger following command :
      1. commands:
        sudo yum install httpd

        Since we are using a sudo command, these operations get executed with root privileges.

      2. Once it installs, you can start Apache on your VPS:
        sudo systemctl start httpd.service
      3. As this is started you can check the same at your browser


      4. If you see this page, then your web server is now correctly installed. The last thing you will want to do is enable Apache to start on boot. Use the following command to do so:
        sudo systemctl enable httpd.service
      5. disable/add a port to the firewall using the command :
        1. iptables -I INPUT 5 -i eth0 -p tcp –dport 80 -m state –state NEW,ESTABLISHED -j ACCEPT
        2. if your system is using firewalld 
          1. For instance, if we are running a web server serving conventional HTTP traffic, we can allow this traffic for interfaces in our “public” zone for this session by typing:
            • sudo firewall-cmd –zone=public –add-service=http

            You can leave out the --zone= if you wish to modify the default zone. We can verify the operation was successful by using the --list-all or --list-services operations:

            • sudo firewall-cmd –zone=public –list-services
            1. dhcpv6-client http ssh
            2. Once you have tested that everything is working as it should, you will probably want to modify the permanent firewall rules so that your service will still be available after a reboot. We can make our “public” zone change permanent by typing:
              • sudo firewall-cmd –zone=public –permanent –add-service=http

              You can verify that this was successful by adding the --permanent flag to the --list-servicesoperation. You need to use sudo for any --permanent operations:

              • sudo firewall-cmd –zone=public –permanent –list-services
              dhcpv6-client http ssh

              Your “public” zone will now allow HTTP web traffic on port 80. If your web server is configured to use SSL/TLS, you’ll also want to add the https service. We can add that to the current session and the permanent rule-set by typing:

              • sudo firewall-cmd –zone=public –add-service=https
              • sudo firewall-cmd –zone=public –permanent –add-service=https

Restart the firewalld service

after this, we should we able to check to see the screen as shown above.

[bibblio style=”bib–row-3 bib–default bib–hover bib–white-label bib–font-arial bib–size-18″ query_string_params=e30=]

  1. Install MySQL (MariaDB)

    Install Mysql following this link  

    1. Command:
      sudo yum install mariadb-server mariadb
    2. start MariaDB with the following command:
      sudo systemctl start mariadb
    3. Start the interactive script by running:
      sudo mysql_secure_installation
      in this command run you would be asked multiple question where you would need to enter password , please enter that and remember for future usage
    4. Enable MariaDB to start on boot. Use the following command to do so:
      sudo systemctl enable mariadb.service
    5. check whether you mysql is installed successfully or not
      1. commoand:
        1. mysql -u root -p “password”
        2. this command should give the mysql prompt
  2. Install PHP

    1. We’re going to install php and php-mysql package :

      sudo yum install php php-mysql
    2. this will install PHP on your centOS
  3. Test PHP Processing on your Web Server

    1. Now it looks like the LAMP is installed on your VM, so to test for the success of the same perform following steps :
      1. In CentOS 7, web directory is located at /var/www/html/. We can create the file at that location by typing:
        sudo vi /var/www/html/info.php
      2. Inside this file enter following line, this line will help us in getting the PHP version info
        <?php phpinfo(); ?>
      3. save and close the file
        1. command :   :wq
      4. disable your VM firewall or run following command to allow access
        1. commands to allow HTTP and HTTPS traffic:
          sudo firewall-cmd --permanent --zone=public --add-service=http 
          sudo firewall-cmd --permanent --zone=public --add-service=https
          sudo firewall-cmd --reload
      5. install mcrypt  – this package is mostly required.
        1. sudo yum install php-mcrypt*
      6. The address you want to visit will be:
    2. LAMP
  4. Conclusion

    Now that you have a LAMP stack installed, you have many choices for what to do next. Basically, you’ve installed a platform that will allow you to install most kinds of websites and web software on your server.

This document is the verified document, so people trying this will not face any error in setting up LAMP and in case any of you are facing any issue please post in the comment below with your concerns.

Leave a Reply

Your email address will not be published. Required fields are marked *