How to add LAMP support to Ubuntu 14.0.4 64-bit on New OpenVZ

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

Before You Begin

  1. Ensure that you have followed the Securing Your Server guides, and the RentVPS' hostname is set.

  2. Update your system:

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

Apache

Install and Configure

  1. Install Apache 2.4:

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

    /etc/apache2/apache2.conf
    1
    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 1GB RentVPS:

    /etc/apache2/mods-available/mpm_prefork.conf
    1
    2
    3
    4
    5
    6
    7
    <IfModule mpm_prefork_module>
            StartServers            2
            MinSpareServers         6
            MaxSpareServers         12
            MaxRequestWorkers       39
            MaxConnectionsPerChild  3000
    </IfModule>
    
  4. Disable the event module and enable prefork:

    1
    2
    sudo a2dismod mpm_event
    sudo a2enmod mpm_prefork
    
  5. Restart Apache:

    1
    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,example.com.conf, replacing example.com with your own domain information:

    /etc/apache2/sites-available/example.com.conf
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    <VirtualHost *:80> 
         ServerAdmin webmaster@example.com
         ServerName example.com
         ServerAlias www.example.com
         DocumentRoot /var/www/html/example.com/public_html/
         ErrorLog /var/www/html/example.com/logs/error.log 
         CustomLog /var/www/html/example.com/logs/access.log combined
         <Directory /path/to/public/website/>
            Require all granted
         </Directory>
    </VirtualHost>
    

    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:

    1
    2
    sudo mkdir -p /var/www/html/example.com/public_html
    sudo mkdir /var/www/html/example.com/logs
    
  3. Link your virtual host file from the sites-available directory to the sites-enabled directory:

    1
    sudo a2ensite example.com.conf
    

    If you later need to disable your website, run:

    1
    a2dissite example.com.conf
    
  4. Reload Apache:

    1
    sudo service apache2 reload
    

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

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


MySQL

Install and Configure (Requirement: min. 128MB ram or 512MB swap)

  1. Install the mysql-server package:

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

    1
    mysql_secure_installation
    

Create a MySQL Database

  1. Log into MySQL:

    1
    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 databse is calledwebdata, the user webuser and password password:

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

    1
    quit 
    

PHP

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

    1
    sudo apt-get install php5 php-pear
    

    If you need MySQL support also install php5-mysql

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

    /etc/php5/apache2/php.ini
    1
    2
    3
    error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
    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:

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

    1
    sudo service apache2 reload
    

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

Esta resposta foi útil?

 Imprimir este Artigo

Leia também

How to enable and setup RDP on Windows

NOTE: This is done on Windows 2012 DC R2 edition, other versions might be slightly different.1....

How to fix NoVNC Console Just Black Screen

Debian 5,6,7 This will also work in debian8 if you use sysv-init instead of systemd Editing the...

Difference between OpenVZ and LXC

OpenVZ OpenVZ is a Linux container solution. It was first released in 2005 by SWSoft, now known...

How to order Addons (extra rams/space/bandwidth)

1. Please login and go to to our client area products page2. Click "Active" button on the product...

How to use Debian 8 OpenVPN

If you selected this New OpenVZ template, you just need to SSH to your assigned IP and login as...