LAMP setup on Ubuntu 14.04

Category : Linux/ Unix



LAMP is an open source Web development platform that uses Linux as the operating system, Apache as the Web server, MySQL as the relational database management system and PHP as the object-oriented scripting language. Because the platform has four layers, LAMP is sometimes referred to as a LAMP stack. Stacks can be built on different operating systems.

This tutorial will guide you through the steps of installing stack on Ubuntu 14.04 Server. Ubuntu will fulfill our first requirement: a Linux Operating System.


Before you Begin

This tutorial is for a non- root user. If you have a root account remove sudo before each command.

STEP 1- Apache

Install and Configure

        1. Update Repos and Install Apache :
          sudo apt-get update
          sudo apt-get install apache2
        2. Edit the main Apache configuration file ,apache2.conf’, to adjust the KeepAlive setting:

          KeepAlive Off
        3. The default multi processing module (MPM) for Apache is the event module, but by default, PHP uses the prefork  Open thempm_prefork.conf file located in /etc/apache2/mods-available and edit the configuration. Below is the suggested values for a 1GB Server:
          <IfModule mpm_prefork_module>
          StartServers 2
          MinSpareServers 6
          MaxSpareServers 12
          MaxRequestWorkers 39
          MaxConnectionsPerChild 3000
        4. Disable the event module and enable prefork:
          sudo a2dismod mpm_event
          sudo a2enmod mpm_prefork
        5. Restart Apache:
          sudo service apache2 restart

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.

Configure Virtual Hosts

      1. Within the/etc/apache2/sites-available/ directory, create a configuration file for your website, com.conf, replacing with your own domain information:
        <VirtualHost *:80>
        DocumentRoot /var/www/html/
        ErrorLog /var/www/html/
        CustomLog /var/www/html/ combined
        <Directory /path/to/public/website/>
        Require all granted
      2. Create the above-referenced directories:
        The ErrorLog and CustomLog entries are suggested for more fine-grained logging but are not required. If they are defined (as shown above), the log directories must be created before you restart Apache.
        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
      4. If you later need to disable your website, run:
      5. Reload Apache:
        sudo service apache2 reload
        Assuming that you have configured the DNS for your domain to point to your Server’s IP address, virtual hosting for your domain should now work.
        If there are additional websites you wish to add to your server repeat the above steps to add them.


Install and Configure

    1. Install the mysql-server package:
      sudo apt-get install mysql-server
    2. Run mysql_secure_installation, a program that helps secure MySQL. Then you can change the MySQL password and you can also remove anonymous user accounts, disable root logins outside of localhost, and remove test databases: Choose a password when the prompt appears.
    3. Login to MySQL using the command
      mysql -u root -p
      Enter the root password for MySQL and prompt will appear.
    4. Now create a database and a user with permissions for it. In this example the database is called data, the user is called user and password password:
      create database data; grant all on data.* to 'user' identified by 'password';
    5. Exit MySQL:

Install PHP, and the PHP Extension and Application Repository: STEP 3-PHP

    1. Install PHP Package
      sudo apt-get install php5 php-pear
    2. If you need MySQL support also installphp5-mysql
      sudo apt-get install php5-mysql
    3. Once PHP5 is installed, tune the configuration file located in/etc/php5/apache2/php.inito enable more descriptive errors, logging, and better performance. The following modifications provide a good starting point:
      error_log = /var/log/php/error.log
      max_input_time = 30
    4. Create the log directory for PHP and give the Apache user ownership: Ensure the lines above are uncommented. Commented lines begin with a semicolon (;).
      sudo mkdir /var/log/phpsudo chown www-data /var/log/php
    5. Reload Apache:
      sudo service apache2 reload

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