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 Web
Installation and configuration
- To Install Apache 2.4 run:
sudo apt-get install apache2
- Edit the main Apache configuration file to turn off the KeepAlive setting.
File : /etc/apache2/apache2.conf
KeepAlive Off
- To edit the values according to your requirements open /etc/apache2/mods-available/mpm_prefork.conf.
The following configurations are for a 2GB instance:
File : /etc/apache2/mods-available/mpm_prefork.conf
# prefork MPM # StartServers: number of server processes to start # MinSpareServers: minimum number of server processes which are kept spare # MaxSpareServers: maximum number of server processes which are kept spare # MaxRequestWorkers: maximum number of server processes allowed to start # MaxConnectionsPerChild: maximum number of requests a server process serves <IfModule mpm_prefork_module> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxRequestWorkers 200 MaxConnectionsPerChild 4500 </IfModule> # vim: syntax=apache ts=4 sw=4 sts=4 sr noet
- On Debian 8, the event module should be disabled since it is enabled by default.
sudo a2dismod mpm_event sudo a2enmod mpm_prefork
- Restart Apache:
sudo systemctl restart apache2
Configuration name based virtual hosts
You can have as many virtual host files as needed to support a number of domains hosted in the instance.
- Create new directories for your websites and website logs.
sudo mkdir -p /var/www/html/example.com/public_html sudo mkdir /var/www/html/<yourDomainName>.com/logs
Repeat the process if you are hosting multiple websites.
- 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.
File : /etc/apache2/sites-available/<yourDomainName>.org.conf
<VirtualHost *:80> ServerAdmin webmaster@<yourDomainName>.org ServerName <yourDomainName>.org ServerAlias www.<yourDomainName>.org DocumentRoot /var/www/html/<yourDomainName>.org/public_html/ ErrorLog /var/www/html/<yourDomainName>.org/logs/error.log CustomLog /var/www/html/<yourDomainName>.org/logs/access.log combined </VirtualHost>
- Link your virtual hosts file from sites- available directory to sites-enabled directory.
sudo a2ensite <yourDomainName>.com.conf sudo a2ensite <yourDomainName>.org.conf
Note: In order to disable a site
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
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