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.

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

A LAMP (Linux, Apache, MySQL, PHP) stack is a common web stack used to prepare servers for hosting web content. This guide shows you how to install a LAMP stack on a CentOS 6 system.

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 -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

Apache Web

Install and Configure

  1. Install Apache 2:

    sudo yum install httpd
  2. Edit the httpd.conf under /etc/httpd/conf/ to adjust the resource use settings. The settings shown below are a good starting point for a Linode 2GB:


    Before changing any configuration files, it is advised that you make a backup of the file. To make a backup:

    cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup

    File: /etc/httpd/conf/httpd.conf
    KeepAlive Off
    <IfModule prefork.c>
        StartServers        4
        MinSpareServers     20
        MaxSpareServers     40
        MaxClients          200
        MaxRequestsPerChild 4500

Configure Apache Virtual Hosts

There are different ways to set up virtual hosts; however, the method below is recommended. By default, Apache listens on all IP addresses available to it.

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

    File: /etc/httpd/conf.d/vhost.conf
    NameVirtualHost *:80
    <VirtualHost *:80>
         DocumentRoot /var/www/
         ErrorLog /var/www/
         CustomLog /var/www/ combined

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

    ErrorLog and CustomLog entries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), the logs directories must be created before you restart Apache.
  2. Create the directories referenced above:

    sudo mkdir -p /var/www/
    sudo mkdir /var/www/
  3. Start Apache for the first time, and set it to run at boot:

    sudo service httpd start
    sudo /sbin/chkconfig --levels 235 httpd on

    You should new be able to view a default Apache page on your website.


    Anytime you change an option in your vhost.conf file, or any other Apache configuration file, remember to reload the configuration with the following command:

    sudo service httpd reload


Install and Configure

  1. Install the MySQL package:

    sudo yum install mysql-server
  2. Start MySQL, and set it to run at boot:

    sudo service mysqld start
    sudo /sbin/chkconfig --levels 235 mysqld on
  3. Run mysql_secure_installation to secure MySQL. You will be given the option to change the root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases and reload privileges. It is recommended that you answer yes to these options:


Create a MySQL Database

  1. Log in to MySQL:

    mysql -u root -p

    Enter MySQL’s root password. You will then be presented with a MySQL prompt.

  2. Create a database and user:

    create database webdata;
    grant all on webdata.* to 'webuser' identified by 'password';

    In the above example webdata is the name of the database, webuser the user, and password a strong password.

  3. Exit MySQL:


With Apache and MySQL installed you are ready to move on to installing PHP.


Install and Configure

  1. Install PHP:

    sudo yum install php php-pear

    If you wish to install MySQL support for PHP also install the php-mysql package:

    sudo yum install php-mysql
  2. Edit /etc/php.ini for better error messages and logs, and upgraded performance. These modifications provide a good starting point for a Linode 2GB:

    File: /etc/php.ini
    error_log = /var/log/php/error.log
    max_input_time = 30
    Ensure that all the lines noted above are uncommented. A commented line begins with a semicolon (;).
  3. Create the log directory for PHP and give the Apache user ownership:

    sudo mkdir /var/log/php
    sudo chown apache /var/log/php
  4. Restart Apache:

    sudo service httpd restart

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.