Installing & Configuring LAMP Stack on RHEL 6 (From Source)

LAMP is an acronym for a popular open-source web development stack that consists of Linux, Apache, MySQL, PHP. Each component plays a critical role in delivering dynamic web applications.

Apache
Apache handles HTTP requests and serves web pages. PHP is embedded in Apache to generate dynamic content. Over 65% of websites run on Apache due to its reliability and scalability.

MySQL
MySQL provides a robust, scalable relational database backend to store your application’s data—users, products, content, etc.—and supports SQL for querying.

PHP
PHP acts as the glue between Apache and MySQL, handling logic, database queries, and dynamic rendering of HTML content.

LAMP Installation on RHEL 6

/usr/local/src/lampLocation to store downloaded tar files
/usr/local/lamp/Base install directory
/usr/local/lamp/apacheApache installation path
/usr/local/lamp/mysqlMySQL installation path
/usr/local/lamp/phpPHP installation path

Flush Firewall

iptables -F
service iptables save

rpm -qa | grep httpd
rpm -qa | grep mysql
rpm -qa | grep php

service httpd stop
service mysqld stop

rpm -e httpd
rpm -e mysql-server

mkdir -p /usr/local/src/lamp /usr/local/lamp
cd /usr/local/src/lamp

wget https://archive.apache.org/dist/httpd/httpd-2.2.22.tar.gz
tar -xvf httpd-2.2.22.tar.gz
cd httpd-2.2.22

yum install -y gcc gcc-c++ make libxml2-devel

./configure –prefix=/usr/local/lamp/apache –enable-so –enable-mods-shared=”most”
make
make install

Start Apache

/usr/local/lamp/apache/bin/apachectl start
netstat -ntlp | grep httpd

Create a soft link to manage Apache

ln -s /usr/local/lamp/apache/bin/apachectl /etc/init.d/httpd
chmod 755 /etc/init.d/httpd

Browse to http://127.0.0.1 and you should see “It works!”

groupadd mysql
useradd -g mysql mysql

cd /usr/local/src/lamp
wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.5.28.tar.gz
tar -xvf mysql-5.5.28.tar.gz
cd mysql-5.5.28

yum install -y cmake ncurses-devel

cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lamp/mysql \
-DMYSQL_DATADIR=/usr/local/lamp/mysql/data
make
make install
chown -R mysql:mysql /usr/local/lamp/mysql

/usr/local/lamp/mysql/scripts/mysql_install_db –user=mysql \
–basedir=/usr/local/lamp/mysql \
–datadir=/usr/local/lamp/mysql/data/

cp /usr/local/lamp/mysql/support-files/mysql.server /etc/init.d/mysqld
cp /usr/local/lamp/mysql/support-files/my-medium.cnf /etc/my.cnf

chkconfig –add mysqld
chkconfig –list mysqld
service mysqld restart
netstat -ntlp | grep mysql

cd /usr/local/src/lamp
wget https://www.php.net/distributions/php-5.4.8.tar.gz
tar -xvf php-5.4.8.tar.gz
cd php-5.4.8

./configure –prefix=/usr/local/lamp/php \
–with-apxs2=/usr/local/lamp/apache/bin/apxs \
–with-mysql=/usr/local/lamp/mysql/
make
make install

cp php.ini-production /usr/local/lamp/php/lib/php.ini

/usr/local/lamp/apache/bin/apachectl -t -D DUMP_MODULES | grep php

Edit the Apache config file

vim /usr/local/lamp/apache/conf/httpd.conf

Find the <IfModule mime_module> section and add

AddHandler application/x-httpd-php .php .html

Create PHP Test File

vim /usr/local/lamp/apache/htdocs/index.php

Add the following

<?php
phpinfo();
?>

Restart services

service httpd restart
service mysqld restart

Browse to: http://127.0.0.1/index.php — and you should see the PHP info page.

While this method gives complete control, for production environments, consider using YUM packages or Docker for easier updates and scalability.

Leave a Comment