LAMP on CentOS 6

Install Apache Web

sudo yum install httpd



Edit Apache's httpd.conf

The httpd.conf can be found in /etc/httpd/conf/ and configures resource usage.

This is an example of a configuration for a VPS with 2GB of RAM:

KeepAlive Off
 
...
 
<IfModule prefork.c>
StartServers
MinSpareServers 20
MaxSpareServers 40
MaxClients 200
MaxRequestsPerChild 4500
</IfModule>


NOTE: The Apache config should be closely monitored. Different sites may require adjustment of these values to optimize performance. This configuration is presented as a good baseline.


Set Up Virtual Hosts

Create a file named vhost.conf in /etc/httpd/conf.d using your own domain in place of yourdomain.com:

NameVirtualHost *:80
 
<VirtualHost *:80>
ServerAdmin webmaster@yourdomain.com
ServerName yourdomain.com
ServerAlias www.yourdomain.com
DocumentRoot /var/www/yourdomain.com/public_html/
ErrorLog /var/www/yourdomain.com/logs/error.log
CustomLog /var/www/yourdomain.com/logs/access.log combined
</VirtualHost>

NOTE: you will need to make a new entry in your vhost.conf file like this for each domain you intend to host on your VPS

Now you must make the directories referenced in your vhost.conf file - remember to replace yourdomain.com with your actual domain name:

sudo mkdir -p /var/www/yourdomain.com/public_html
sudo mkdir /var/www/yourdomain.com/logs



Start Apache

The first command will start the Apache service, and the second command will make Apache run on boot:

sudo service httpd start
sudo /sbin/chkconfig --levels 235 httpd on





Install MySQL

sudo yum install mysql-server



Start MySQL

sudo service mysqld start
sudo /sbin/chkconfig --levels 235 mysqld on


Secure MySQL

We suggest you answer "yes" to all the options given when you run this command:

mysql_secure_installation


Create a Database

First you will need to log in to MySQL:

mysql -u root -p

Now, create a database and user, replacing webdata with your database name, webuser with your username, and password with a strong password:

create database webdata;
grant all on webdata.* to 'webuser' identified by 'password';

Quit MySQL:

quit



Install PHP

sudo yum install php php-pear


Install MySQL support:

sudo yum install php-mysql


Edit the /etc/php.ini to improve performance, error messages, and logs:

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 error directory

sudo mkdir /var/log/php
sudo chown apache /var/log/php



Restart Apache:

sudo service httpd restart







 

  • 13 Users Found This Useful
Was this answer helpful?

Related Articles

IP rDNS/PTR records

You can configure PTR or Reverse DNS records via the VPS Control Panel under rDNS. The record...

Serial Console

You may wish to use the Serial Console if the SSH console becomes inaccessible. The Serial...

LAMP on Debian 7

Install Apache Web sudo apt-get install apache2 Edit Apache's httpd.confThe...

LAMP on Ubuntu 14.04

Install Apache sudo apt-get update sudo apt-get install apache2 Install MySQL...

WordPress on Ubuntu 14.04

NOTE: You must have the LAMP stack installed before installing WordPress.Create the WordPress...