How To Install Apache and PHP on CentOS 6

September 8, 2016

How To Install Apache and PHP on CentOS 6

How To Install Apache and PHP on CentOS 6

Apache is the most widely used web server software. Developed and maintained by Apache Software Foundation, Apache is an open source software available for free. It runs on 67% of all webservers in the world. It is fast, reliable, and secure. It can be highly customized to meet the needs of many different environments by using extensions and modules. Most WordPress hosting providers use Apache as their web server software. However, WordPress can run on other web server software as well.

Install Apache

  1. Run the following command on your linux server:
  2. Because the server does not start automatically when you install Apache, you must start it manually.

    The following message is displayed:

    The IP address (shown in this example as 127.0.0.1) is used as the server name by default. In the following steps, set the server name for the next time the server is started.
  3. Open the main Apache configuration file.
  4. Toward the end of the file, locate the section that starts with ServerName and gives an example.
  5. Enter your cloud server host name or a fully qualified domain name. In the following example, the host name is demo.
  6. Reload Apache.

Open the port to run Apache

Apache runs on port 80. In some versions of CentOS, a firewall, which is installed by default, blocks access to port 80. Perform the following steps to open the port.

  1. Run the following command:
  2. After adding that instruction, save your firewall rules so that your web server is accessible the next time you reboot.

Test the Apache installation

Navigate to your Cloud Server IP address (for example, http://123.45.67.89).

If the default CentOS Apache “welcome” screen is displayed, the installation was successful. Contact Rackspace support if you have any problems.

Configure Apache to run automatically

Now that Apache is installed and working, set to start automatically when the server is rebooted.

  1. Run the following command:
  2. Test to confirm that the setting works.

Install PHP

  1. Run the following command:

    The preceding command does not install all the modules available, just a few common ones.
  2. Reload Apache.