Centos Linux Operating Systems

Build WebServer on Centos 7

LAMP (Linux, Apache, MySQL, PHP)

In this guide, we will walk through installing all of these components (except for Linux, which is already installed as your OS when you create the server).

Install Apache

  1. Make sure that your software is up to date:
    #sudo yum update
  2. Install Apache:
    #sudo yum install httpd
  3. Start Apache:
    #sudo systemctl start httpd.service
  4. Set Apache to start on server boot:
    #sudo systemctl enable httpd.service

Install MySQL

  1. Install MariaDB, which is a community-developed fork of MySQL:
    #sudo yum install mariadb-server mariadb
  2. Start the service:
    #sudo systemctl start mariadb
  3. Set MySQL to start on server boot:
    #sudo systemctl enable mariadb.service
  4. Run this command to finish setting up the installation:
    #sudo mysql_secure_installation
    Enter current password for root (enter for none):
    OK, successfully used password, moving on...
    Setting the root password ensures that nobody can log into the MariaDB
    root user without the proper authorization.
    New password: password
    Re-enter new password: password
    Password updated successfully!
    Reloading privilege tables..
     ... Success!
  5. You will be asked for the root password. Because you didn’t set it earlier, press Enterto set a password now.
  6. Type “Y” to set the root password.
  7. Enter and confirm the new password.
  8. You will be asked more questions as part of the security configuration. It is a best practice to respond “Y” to these system prompts

Install PHP

  1. Install PHP:
    #sudo yum install php php-mysql

    Enter “Y” to install.

  2. Restart Apache:
    #sudo systemctl restart httpd.service

Update Firewall

#sudo firewall-cmd --permanent --zone=public --add-service=http
#sudo firewall-cmd --permanent --zone=public --add-service=https
#sudo firewall-cmd --reload


Test PHP processing on Apache

  1. Create a new PHP file under the /var/www/html directory:
    sudo vi /var/www/html/info.php
  2. When the file opens, type in the following code:
  3. Save and close the file:
  4. To verify it worked, type this URL in your browser:
    http://your server’s IP address/info.php

A page displays with the PHP version, extensions, build date, and other information.


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.

Leave a Reply

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