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.

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.

A LAMP (Linux, Apache, MySQL, PHP) stack is a common web stack used for hosting web content. This guide shows you how to install a LAMP stack on an Ubuntu 14.04 (LTS) server.

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.

  2. Update your system:

    sudo apt-get update && sudo apt-get upgrade


Install and Configure

  1. Install Apache 2.4:

    sudo apt-get install apache2
  2. Edit the main Apache configuration file, apache2.conf, to adjust the KeepAlive setting:

    File: /etc/apache2/apache2.conf
    KeepAlive Off
  3. The default multi-processing module (MPM) for Apache is the event module, but by default PHP uses the prefork module. Open the mpm_prefork.conf file located in /etc/apache2/mods-available and edit the configuration. Below is the suggested values for a 2GB Linode:

    File: /etc/apache2/mods-available/mpm_prefork.conf
    <IfModule mpm_prefork_module>
            StartServers            4
            MinSpareServers         20
            MaxSpareServers         40
            MaxRequestWorkers       200
            MaxConnectionsPerChild  4500
  4. Disable the event module and enable prefork:

    sudo a2dismod mpm_event
    sudo a2enmod mpm_prefork
  5. Restart Apache:

    sudo service apache2 restart

Configure Virtual Hosts

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

  1. Within the /etc/apache2/sites-available/ directory, create a configuration file for your website,, replacing with your own domain information:

    File: /etc/apache2/sites-available/
    <VirtualHost *:80>
         DocumentRoot /var/www/html/
         ErrorLog /var/www/html/
         CustomLog /var/www/html/ combined
         <Directory /path/to/public/website/>
            Require all granted
    The 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 above-referenced directories:

    sudo mkdir -p /var/www/html/
    sudo mkdir /var/www/html/
  3. Link your virtual host file from the sites-available directory to the sites-enabled directory:

    sudo a2ensite

    If you later need to disable your website, run:


  4. Reload Apache:

    sudo service apache2 reload

    Assuming that you have configured the DNS for your domain to point to your Linode’s IP address, virtual hosting for your domain should now work.

    If there are additional websites you wish to add to your Linode repeat the above steps to add them.


Install and Configure

  1. Install the mysql-server package:

    sudo apt-get install mysql-server

    Choose a secure password when prompted.

  2. Run mysql_secure_installation, a program that helps secure MySQL. You will be presented with the opportunity to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases:


Create a MySQL Database

  1. Log into MySQL:

    mysql -u root -p

    Enter MySQL’s root password, and you’ll be presented with a MySQL prompt.

  2. Create a database and a user with permissions for it. In this example the database is called webdata, the user webuser and password password:

    create database webdata;
    grant all on webdata.* to 'webuser' identified by 'password';
  3. Exit MySQL:



  1. Install PHP, and the PHP Extension and Application Repository:

    sudo apt-get install php5 php-pear

    If you need MySQL support also install php5-mysql

    sudo apt-get install php5-mysql
  2. Once PHP5 is installed, tune the configuration file located in /etc/php5/apache2/php.ini to enable more descriptive errors, logging, and better performance. The following modifications provide a good starting point:

    File: /etc/php5/apache2/php.ini
    error_log = /var/log/php/error.log
    max_input_time = 30
    Ensure the lines above are uncommented. Commented lines begin with a semicolon (;).
  3. Create the log directory for PHP and give the Apache user ownership:

    sudo mkdir /var/log/php
    sudo chown www-data /var/log/php
  4. Reload Apache:

    sudo service apache2 reload

Congratulations! You have now set up and configured a LAMP stack.

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.