Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  How-Tos  >  LAMP On CentOS 6
Top Scroll

LAMP On CentOS 6

 4 min

LAMP stands for a Linux, Apache, MySQL and PHP. If you wish to host a website on your own Virtual Private Server, you will need to install LAMP.

1. Linux – Linux is a Operating System using which you will be able to access your server and manage the applications over it.
2. Apache – Apache is a web server supported on Linux and Windows both. Using the web server you can service the web requests over the internet.
3. MySQL – MySQL is a open source Relation Database Management System (RDBMS). MySQL is the widely used database over the internet.
4. PHP – PHP is a server-side scripting language using which you can develop your website, applications, portal, etc. It is Open Source and used widely by many CMS and applications.

Requirements

You should have a virtual private server OR a physical server also called as dedicated server with root privileges. The server should be connected to internet and should be accessible via SSH.

Make sure hostname is set to the server. You can check the server’s hostname with command

# hostname

Install Apache & Configure

To install apache2, use the command. Type y (yes) & proceed with the installation.

# yum install httpd

Once installed, start apache & add it to chkconfig. This will ensure that the service starts even after server reboots.

# service httpd start

# chkconfig httpd on

Now, try browsing the server IP & it should show Apache 2 test page. You can locate your server IP with any of the command below.

# ifconfig

# lynx -dump cPanel.net/showip.cgi

Now let’s configure apache for the optimum performance. The apache tweak that we will perform will be suitable for VPS with 512MB to 1GB RAM. The values can be raised as and when the CPU and Memory is increased.

Let’s backup the apache configuration file before making any changes. The best practice is to backup config files just in case anything goes wrong OR if you wish to revert the changes.

# cp /etc/httpd/conf/httpd.conf /root/httpd.conf.backup

Open the config files and adjust the entries as below. These can be adjusted depending on the websites you wish to host & the number of visitors on your website.

KeepAlive On
<IfModule prefork.c>
StartServers        2
MinSpareServers     6
MaxSpareServers     10
MaxClients          100
MaxRequestsPerChild 3000
</IfModule>

Save the file and exit. Restart apache with command

service httpd restart

Configure VirtualHost In Apache

You can configure apache depending on your needs. We will see how to configure apache for your first domain yourdomain.com. When installed, apache listens on all the IP’s assigned/added on your server.

Create a file under /etc/httpd/conf.d named vhost.conf. Enter the contents below are replace yourdomain.com with your actual domain name.

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>

If you wish to host multiple websites on the same server, you can add the code in this same file as and when required.

Let’s create the directories which are called/used in your VirtualHost entry. Then restart apache without fail.

# mkdir -p /var/www/yourdomain.com/public_html

# mkdir /var/www/yourdomain.com/logs

# service httpd restart

A default page will appear when you access yourdomain.com. If in case you make any changes to the vhost.conf file, make sure you restart OR reload httpd service without fail. Simply, replace restart with reload if you wish to reload httpd service.

Install and Configure MySQL

With yum install MySQL package/rpm.

# yum install mysql-server -y

Start the installed MySQL service and configure it so that MySQL starts at boot.

# service mysqld start

# chkconfig mysqld on

Execute the command below which will secure MySQL. It will allow you to Set a root Password, Remove anonymous users, Disallow root login remotely, Remove test database and access to it, Reload privilege tables now.

# mysql_secure_installation

Create MySQL Database

Login to your MySQL command prompt. It will ask you to enter the root password. Enter the root password when asked for.

# mysql -u root -p

Create MySQL database and assign MySQL user.

# create database dbname;

# grant all on dbname.* to ‘mysqluser’ identified by ‘password’;

Note Replace dbname, mysqluser & password with the actual details that you wish to use. password should be alpha numeric & strong. Avoid dictionary words when assigning a password.

Exit MySQL command prompt by hitting Ctrl + d OR with quit command.

Install and Configure PHP

With yum install PHP package/rpm.

# yum install php php-pear php-mysql -y

The command will required PHP modules with MySQL support. php-mysql is required if you wish to connect the database using connection string in PHP.

Let’s configure error reporting for logs being polled. Error logs are required when you are in the process to develop a website, portal, CMS, blog, etc.

Open /etc/php.ini and modify the values as below.

error_reporting = E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR
error_log = /var/log/php/error.log

Make sure to create the php directory so that error logs can be polled.

# mkdir /var/log/php

# chown apache.apache /var/log/php -R

You can even modify upload_max_filesize, max_execution_time, disable_functions, etc depending on your requirement.

# service httpd restart

Restart apache service whenever you commit changes in /etc/php.ini file.

You can adjust/add the values that we have mentioned depending on your server configuration, type of website that you wish to host. Feel free to initiate a chat with our technician if you wish to discuss more about configuring LAMP on your server.

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.