![]() |
| LAMP Configuration on Ubuntu |
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.
Before you begin update your system -
# sudo apt-get update && sudo apt-get upgrade
Apache
Install and Configure
sudo apt-get install apache2 |
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.-
Within the
/etc/apache2/sites-available/directory, create a configuration file for your website,example.com.conf, replacingexample.comwith your own domain information:
- vim /etc/apache2/sites-available/example.com.conf
<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 /var/www/html/> Require all granted </Directory></VirtualHost>
The
ErrorLogandCustomLogentries are suggested for more fine-grained logging, but are not required. If they are defined (as shown above), thelogsdirectories must be created before you restart Apache. -
Create the above-referenced directories:
sudo mkdir -p /var/www/html/example.com/public_html
sudo mkdir /var/www/html/example.com/logs
-
Link your virtual host file from the
sites-availabledirectory to thesites-enableddirectory:
sudo a2ensite example.com.conf
If you later need to disable your website, run:
sudo a2dissite example.com.conf
-
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.
MySQL
Install and Configure
-
Install the
mysql-serverpackage:
Choose a secure password when prompted.sudo apt-get install mysql-server
-
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:
mysql_secure_installation
Create a MySQL Database
-
Log into MySQL:
mysql -uroot -p
Enter MySQL’s root password, and you’ll be presented with a MySQL prompt.
-
Create a database and a user with permissions for it. In this example the databse is called
webdata, the userwebuserand passwordpassword:
create database webdata;
grant all on webdata.* to 'webuser' identified by 'password';
-
Exit MySQL:
quit
PHP
-
Install PHP, and the PHP Extension and Application Repository:
sudo apt-get install php5 php-pear php5-mysql
-
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:
- /etc/php5/apache2/php.ini
- error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
- error_log = /var/log/php/error.log
- max_input_time = 30
-
Create the log directory for PHP and give the Apache user ownership:
sudo mkdir /var/log/php
sudo chown www-data /var/log/php
-
Reload Apache:
sudo service apache2 reload

Comments