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.4 run :
sudo apt-get install apache2
- In order to adjust the KeepAlive setting, edit the main Apache configuration file.
File : /etc/apache2/apache2.conf
KeepAlive Off
- The event module is the default MPM (multi – processing module) for Apache, but PHP uses the perfork module. In order to edit this configuration open the file mpm_prefork.conf file located in /etc/apache2/mods-available.
The following configurations are for a 2GB instance:
<IfModule mpm_prefork_module> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 200 MaxConnectionsPerChild 4500 </IfModule>
- Disable the event module:
sudo a2dismod mpm_event
- Enable prefork:
sudo a2enmod mpm_prefork
- Restart Apache:
sudo systemctl restart apache2
Configuration of Virtual Hosts
Note : By default Apache listens on all IP addresses available on it.
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 link your virtual host file from sites-available directory to sites-enabled direvtory run :
sudo a2ensite <yourDomainName>.com.conf
In order to disable the virtual host run :
sudo a2dissite <yourDomainName>.com.conf
4. Restart Apache:
sudo systemctl restart apache2
You should have configured the DNS for your domain to point to your instance’s IP address, virtual hosting for your domain should now work.
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
- Reload Apache :
sudo service httpd reload
You are now good to go!