What is LAMP?
LAMP is a common web stack which stands for Linux, Apache, MySQL and PHP. It is used to prepare servers in order to host web content.
- To check your short hostname use the following command:
hostname
- To check your FQDN (fully qualified domain name) use the following command:
hostname -f
- To update your instance’s repositories and packages run:
sudo apt-get update && sudo apt-get upgrade
Apache
Installation and configuration
- To Install Apache 2.2 run :
sudo apt-get install apache2
- In order to adjust the resource use settings edit the main Apache configuration file.
The following configurations are for a 2GB instance:
File : /etc/apache2/apache2.conf
KeepAlive Off <IfModule mpm_prefork_module> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 200 MaxConnectionsPerChild 4500 </IfModule>
Configuration name based virtual hosts
You can have as many virtual host files as needed to support the amount of domains hosted in the instance.
1.Create an <yourDomainName>.com.conf file in /etc/apache2/sites-available.
File : /etc/apache2/sites-available/<yourDomainName>.com.conf
<VirtualHost *:80> ServerAdmin webmaster@<yourDomainName>.com ServerName <yourDomainName>.com ServerAlias www.<yourDomainName>.com DocumentRoot /var/www/html/<yourDomainName>.com/public_html/ ErrorLog /var/www/html/<yourDomainName>.com/logs/error.log CustomLog /var/www/html/<yourDomainName>.com/logs/access.log combined </VirtualHost>
Repeat this process if you are hosting multiple domains.
2.Create new directories for your websites and website logs.
sudo mkdir -p /var/www/html/<yourDomainName>.com/public_html sudo mkdir /var/www/html/<yourDomainName>.com/logs
Repeat the process if you are hosting multiple websites.
- To enable the virtual host of the website run :
sudo a2ensite <yourDomainName>.com.conf
In order to disable the virtual host run :
sudo a2dissite <yourDomainName>.com.conf
- Restart Apache:
sudo systemctl restart apache2
MySQL
Installation and configuration
- To Install MySQL package run :
sudo yum install mysql-server
- In order to securely install MySQL run :
mysql_secure_installation
Create a MySQL Database
- Login to MySQL :
mysql -u root -p
- Create a database and user :
create database tableName; grant all on tableName.* to 'username' identified by 'password';
- Exit mySQL:
quit
PHP
Installation and configuration
- To Install PHP5 and the PHP extension and Application repository run :
sudo apt-get install php5 php-pear
If you require MySQL support install php5-mysql
sudo apt-get install php5-mysql
2.Edit /etc/php5/apache2/php.ini and change the following values.
The following configurations are for a 2GB instance:
File : /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
Note : All the lines above should be uncommented. (the ; should be removed ) :
- Create the PHP log directory:
sudo mkdir /var/log/php
- Give ownership to the Apache user :
sudo chown apache /var/log/php
- Restart Apache :
sudo service httpd restart
You are now good to go!