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 system use the following command:
sudo yum update
Apache Web
Installation and configuration
- To Install Apache 2 run :
sudo yum install httpd
- In order to adjust the resource use settings edit the httpd.conf under /etc/httpd/conf/
Before changing any configuration files be sure to make a backup by running the following command :
cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup
Note : The following configurations are for a 2GB instance.
File : /etc/httpd/conf/httpd.conf
KeepAlive Off ... <IfModule prefork.c> StartServers 4 MinSpareServers 20 MaxSpareServers 40 MaxClients 200 MaxRequestsPerChild 4500 </IfModule>
Configuration of Apache Virtual Hosts
- Create a file called vhost.conf under /etc/httpd/conf.d
Replace instances of example.com with your own domain information:
File : /etc/httpd/conf.d/vhost.conf
NameVirtualHost *:80 <VirtualHost *:80> ServerAdmin webmaster@example.com ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/example.com/public_html/ ErrorLog /var/www/example.com/logs/error.log CustomLog /var/www/example.com/logs/access.log combined </VirtualHost>
Note : ErrorLog and CusomLog are not required they are added for more detailed logging. If you decide to define them as in the code above , the log directories must be created before you restart Apache.
- Create the following directories.
sudo mkdir -p /var/www/example.com/public_html sudo mkdir /var/www/example.com/logs
- Start Apache, and set it to run at boot using the following command:
sudo service httpd start sudo /sbin/chkconfig --levels 235 httpd on
Now you can view a default Apache page on your website.
Note : Anytime you change an element in the vhost.conf file or any other Apache configuration file always reload the configuration using the following command :
sudo service httpd reload
MySQL
Installation and configuration
- To Install MySQL package run :
sudo yum install mysql-server
- Start MySQL and set it to run at boot:
sudo service mysqld start sudo /sbin/chkconfig --levels 235 mysqld on
- 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 PHP run :
sudo yum install php php-pear
Note : To install MySQL support for PHP install the following package :
sudo yum install php-mysql
- In order to get better error messages and logs, and upgraded performance edit /etc/php.ini
File : /etc/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