LAMP Stack on CentOS 6

Home » Computer Articles » Linux » LAMP Stack on CentOS 6
April 29, 2015 Linux No Comments

At the very least, you should have a basic linux installation. This how-to assumes you have set up a CentOS 6 x86_64 VPS with 1GB RAM, but it should be applicable to most setups with minimal tweaks. All the commands and changes below should be done as the root user.

 

Before continuing, make sure that everything is up to date.

# yum update

Enable and configure third party repositories

You will need to enable some third party repositories--namely, the EPEL (Extra Packages for Enterprise Linux) repository and the Remi repository. The EPEL repo will let you install nginx, while the remi repo provides you with PHP version 5.5.

Install the 2 repositories:

# rpm --import https://fedoraproject.org/static/0608B895.txt

# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# rpm --import http://rpms.famillecollet.com/RPM-GPG-KEY-remi

# rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

Edit the epel.repo file, add priorities entry, and make sure to set enabled=1 for the mail EPEL repository.

# vi /etc/yum.repos.d/epel.repo

Your /etc/yum.repos.d/epel.repo file should look something like this:

[epel]
name=Extra Packages for Enterprise Linux 6 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-6&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

[epel-debuginfo]
name=Extra Packages for Enterprise Linux 6 - $basearch - Debug
#baseurl=http://download.fedoraproject.org/pub/epel/6/$basearch/debug
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-debug-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

[epel-source]
name=Extra Packages for Enterprise Linux 6 - $basearch - Source
#baseurl=http://download.fedoraproject.org/pub/epel/6/SRPMS
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-source-6&arch=$basearch
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
gpgcheck=1

Edit remi.repo file, add a priorities entry, and make sure to set enabled=1 for the remi and remi-php55 repositories.

# vi /etc/yum.repos.d/remi.repo

Here is what /etc/yum.repos.d/remi.repo should look like:

[remi]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/remi/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-php55]
name=Les RPM de remi de PHP 5.5 pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/php55/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/php55/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-test]
name=Les RPM de remi en test pour Enterprise Linux 6 - $basearch
#baseurl=http://rpms.famillecollet.com/enterprise/6/test/$basearch/
mirrorlist=http://rpms.famillecollet.com/enterprise/6/test/mirror
# WARNING: If you enable this repository, you must also enable "remi"
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-debuginfo]
name=Les RPM de remi pour Enterprise Linux 6 - $basearch - debuginfo
baseurl=http://rpms.famillecollet.com/enterprise/6/debug-remi/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-php55-debuginfo]
name=Les RPM de remi de PHP 5.5 pour Enterprise Linux 6 - $basearch - debuginfo
baseurl=http://rpms.famillecollet.com/enterprise/6/debug-php55/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

[remi-test-debuginfo]
name=Les RPM de remi en test pour Enterprise Linux 6 - $basearch - debuginfo
baseurl=http://rpms.famillecollet.com/enterprise/6/debug-test/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

Install Apache, start the service, and enable on boot

Now, we're ready to install apache:

# yum install httpd

Start the Apache service:

# service httpd start

Setup Apache to start at boot:

# chkconfig httpd on

Note that Apache's default web root directory on CentOS 6 is /var/www/html. This directory may be different depending on what linux distribution you are using.

 

 

Configure Apache

Edit /etc/httpd/conf/httpd.conf for some performance adjustments.

# vi /etc/httpd/conf/httpd.conf

Here is what your httpd.conf file should look like: (Don't copy and paste this into the file, look for each parameter and change them.)

Timeout 100
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5

StartServers 5
MinSpareServers 5
MaxSpareServers 10
ServerLimit 150
MaxClients 150
MaxRequestsPerChild 300

 

Install the MySQL Server and client tools

# yum install mysql mysql-server

Configure MySQL

Here is what your configuration file should look like:

# vi /etc/my.cnf

#
# This group is read both both by the client and the server
# use it for options that affect everything
#
[client-server]
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
query_cache_size = 2M
thread_cache_size = 4
max_connections = 40

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

Matthew Montgomery has a script, MySQL performance tuning primer script, which you can download HERE.

 

 

Start the service and enable at boot

Make sure to start the MySQL service:

# service mysqld start

You should also configure the mysql service to start at boot:

# chkconfig mysqld on

Run mysql_secure_installation

Finally, run mysql_secure_installation to set up a mysql root password and to delete some unnecessary users / tables. Simply run "mysql_secure_installation" and accept all the default answers (except for the root password!).

 

 

Install PHP 5.5

# yum install php php-cli php-mysql php-gd php-pear php-xml php-xmlrpc php-magickwand php-magpierss php-mbstring php-mcrypt php-tidy php-opcache

Configure PHP

# vi /etc/php.ini (Don't copy and paste this into the file, look for each parameter and change them.)

cgi.fix_pathinfo=0
memory_limit = 128M
expose_php = Off
date.timezone = US/Eastern (Set to your timezone)

Test the configuration

Create a phpinfo.php and make sure php is working properly.

# vi /var/www/html/phpinfo.php

<?php
phpinfo();
?>

Go to a web browser and see if the phpinfo page loads proper. If it does great.

 

 

Optional: Enable opcache

Let's enable opcache for better performance, you may not want to enable this is you are making a lot of PHP script changes.

# vi /etc/php.d/opcache.ini (Don't copy and paste this into the file, look for each parameter and change them.)

opcache.memory_consumption=128
opcache.interned_strings_buffer=8
opcache.max_accelerated_files=4000
opcache.revalidate_freq=60
opcache.fast_shutdown=1
opcache.save_comments=0

 

You're done! You should now have a Linux server with apache, MySQL, and PHP running. You can now install a CMS into the /var/www/html directory.

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *