Apache Web Server on CentOS 6

Select distribution:
Traducciones al Español
Estamos traduciendo nuestros guías y tutoriales al Español. Es posible que usted esté viendo una traducción generada automáticamente. Estamos trabajando con traductores profesionales para verificar las traducciones de nuestro sitio web. Este proyecto es un trabajo en curso.
Deprecated

This guide has been deprecated and is no longer being maintained.

Create a Linode account to try this guide with a $ credit.
This credit will be applied to any valid services used during your first  days.

The Apache HTTP Server (Apache) is an open-source web server application. This guide explains how to install and configure an Apache web server on CentOS 6.

If instead you would like to install a full LAMP (Linux, Apache, MySQL, and PHP) stack, please see the LAMP on CentOS 6 guide.

Note
This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, you can check our Users and Groups guide.

Before You Begin

  1. Ensure that you have followed the Getting Started and Securing Your Server guides, and the Linode’s hostname is set.

    To check your hostname run:

    hostname
    hostname -f
    

    The first command should show your short hostname, and the second should show your fully qualified domain name (FQDN).

  2. Update your system:

    sudo yum update
    

Install Apache

  1. Install the Apache HTTP Server:

    sudo yum install httpd
    
  2. Edit the main Apache configuration file to adjust the resource use settings. The settings shown below are a good starting point for a Linode 2GB:

    File: /etc/httpd/conf/httpd.conf
    1
    2
    3
    4
    5
    6
    7
    
    <IfModule prefork.c>
        StartServers        4
        MinSpareServers     20
        MaxSpareServers     40
        MaxClients          200
        MaxRequestsPerChild 4500
    </IfModule>

Configure Apache for Virtual Hosting

  1. Create a file under /etc/httpd/conf.d named vhost.conf. Replace instances of example.com with your own domain information:

    File: /etc/httpd/conf.d/vhost.conf
    1
    2
    3
    4
    5
    6
    7
    8
    
    <VirtualHost *:80>
         ServerAdmin admin@example.org
         ServerName example.org
         ServerAlias www.example.org
         DocumentRoot /srv/www/example.org/public_html/
         ErrorLog /srv/www/example.org/logs/error.log
         CustomLog /srv/www/example.org/logs/access.log combined
    </VirtualHost>

    Additional virtual host blocks can be added to the file for any other domains you wish to host on the Linode.

  2. Create the directories referenced above:

    sudo mkdir -p /srv/www/example.org/public_html
    sudo mkdir -p /srv/www/example.org/logs
    
  3. Start Apache:

    sudo service httpd start
    
  4. Set Apache to start at boot:

    sudo chkconfig httpd on
    

Apache Mods and Scripting

Install Apache Modules

By default, modules are located in the /etc/httpd/modules/ directory. Configuration directives for the default modules are located in /etc/httpd/conf/httpd.conf, while configuration options for optional modules installed with yum are generally placed in .conf files in /etc/httpd/conf.d/.

  1. List available Apache modules:

    sudo yum search mod_
    
  2. Install any desired modules:

    sudo yum install mod_[module-name]
    

    Modules should be enabled and ready to use following installation

Install Support for Scripting

The following commands install Apache support for server-side scripting in PHP, Python, and Perl. Support for these languages is optional based on your server environment.

To install:

  • Perl support:

    sudo yum install mod_perl
    
  • Python support:

    sudo yum install mod_wsgi
    
  • PHP support:

    sudo yum install php php-pear
    

More Information

You may wish to consult the following resources for additional information on this topic. While these are provided in the hope that they will be useful, please note that we cannot vouch for the accuracy or timeliness of externally hosted materials.

This page was originally published on


Your Feedback Is Important

Let us know if this guide was helpful to you.


Join the conversation.
Read other comments or post your own below. Comments must be respectful, constructive, and relevant to the topic of the guide. Do not post external links or advertisements. Before posting, consider if your comment would be better addressed by contacting our Support team or asking on our Community Site.
The Disqus commenting system for Linode Docs requires the acceptance of Functional Cookies, which allow us to analyze site usage so we can measure and improve performance. To view and create comments for this article, please update your Cookie Preferences on this website and refresh this web page. Please note: You must have JavaScript enabled in your browser.