LAMP COMPILATION
In this documentation I will show you how can we install the lamp stack from the source code. LAMP stands for Linux, Apache, Mysql, Php (it can be either python or perl ). I run CentOS-6.3 on my computer . You can follow these steps and install the lamp stack on redhat and fedora too.
Note: Before Starting the installation I will give you details of the directory structure that I am going to use
Please flush your firewall before you testing this
[root@freedom] # iptables -F
[root@freedom] # service iptables save
Directory Structure
/usr/local/src/lamp : The Downloaded .tar file will be save here.
/usr/local/lamp : This where we compile install the source code
/usr/local/lamp/apache : we will install Apache under this directory
/usr/local/lamp/mysql : we will install Mysql under this directory
/usr/local/lamp/php : we will install php under this directory
Step1:- Removing the already installed rpms
Note: Most of the linux distributions carry part of the lamp stack by default so we must stop it and remove them
check whether the rpm's are already there
[root@freedom] # rpm -qa | grep httpd <-- Installed
httpd-2.2.15-15.el6.centos.1.x86_64
[root@freedom] # rpm -qa | grep mysql <-- Installed
mysql-server-5.1.61-4.el6.x86_64
[root@freedom] # rpm -qa | grep php <-- Not Installed
**not installed**
stop the services
[root@freedom] # service httpd stop
[root@freedom] # service mysqld stop
removing the Packages
[root@freedom] # rpm -e httpd
[root@freedom] # rpm -e mysql-server
Step2:- Downloading the .tar file
[root@freedom] # mkdir /usr/local/src/lamp
[root@freedom] # mkdir /usr/local/lamp
[root@freedom] # cd /usr/local/src/lamp
[root@freedom] # wget http://apache.techartifact.com/mirror/httpd/httpd-2.2.22.tar.gz
[root@freedom] # wget http://in1.php.net/get/php-5.4.8.tar.gz/from/this/mirror
[root@freedom] # wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.28.tar.gz/from/http://cdn.mysql.com/
Step4:- Installing Compiler and necessary dependencies
[root@freedom] # yum install gcc gcc-c++ cmake ncurses-devel libxml2-devel
Step5.1:- Compiling and Testing Apache
[root@freedom] # tar -xvf httpd-2.2.22.tar.gz
[root@freedom] # cd /usr/local/src/lamp/httpd-2.2.22
[root@freedom] # ./configure --prefix=/usr/local/lamp/apache --enable-so --enable-mods-shared="most"
[root@freedom] # make
[root@freedom] # make install
Note: What is Configure Scipt , Make, Make install
Configure: Configure script Checks some details about the machine on which the software is going to be installed. This script checks for lots of dependencies on your system. For the particular software to work properly, it may be requiring a lot of things to be existing on your machine already. If any of the major requirements are missing on your system, the configure script would exit and you cannot proceed with the installation, until you get those required things. if configure fails we can not execute the make command.
Make: Actual Compilation of the source code
Make install: Install the compiled binaries to proper directories
--prefix : With prefix we specify the location where want to install the software ( /usr/local/lamp/apache/)
default location will be under (/usr/local/apache2)
--enable-so : This will enable DSO (Dynamic Shared Object ) capability so that we can add additional modules to apache
with out recompiling the entire apache.
--enable-mods-shared="most" : List of modules we want to enable . here i choose to enable most of the modules.
Step5.2:- Satrting And testing Apache
[root@freedom]# ll /usr/local/lamp/apache/
total 60
drwxr-xr-x 2 root root 4096 Oct 23 23:17 bin <- all binaries are inside this
drwxr-xr-x 2 root root 4096 Oct 23 23:18 build
drwxr-xr-x 2 root root 4096 Oct 23 23:17 cgi-bin <- Cgi Directory
drwxr-xr-x 4 root root 4096 Oct 23 23:17 conf
drwxr-xr-x 3 root root 4096 Oct 23 23:17 error
drwxr-xr-x 2 root root 4096 Jan 26 2012 htdocs <- Document Root
drwxr-xr-x 3 root root 4096 Oct 23 23:17 icons
drwxr-xr-x 2 root root 4096 Oct 23 23:17 include
drwxr-xr-x 3 root root 4096 Oct 23 23:17 lib
drwxr-xr-x 2 root root 4096 Oct 23 23:18 logs
drwxr-xr-x 4 root root 4096 Oct 23 23:18 man
drwxr-xr-x 14 root root 12288 Jan 26 2012 manual
drwxr-xr-x 2 root root 4096 Oct 23 23:17 modules
[root@freedom] # /usr/local/lamp/apache/bin/apachectl start stating the apache
[root@freedom] # netstat -ntlp | grep httpd checking the apache is running using netstat
tcp 0 0 :::80 :::* LISTEN 31097/httpd
checking
"Now open up a browser and type http://127.0.0.1 or http://yourip you will get test page containing "It works!" "
Note: The default index.html is locate in side the /usr/local/lamp/apache/htdocs/index.html
5.4:- Making Apache start at boot time
[root@freedom] # cd /etc/init.d/
[root@freedom] # chkconfig --del httpd
[root@freedom] # rm -rf httpd
[root@freedom] # wget http://linuxway.weebly.com/uploads/1/2/6/7/12671374/httpd
[root@freedom] # chmod 755 httpd
[root@freedom] # chkconfig --add httpd
[root@freedom] # chkconfig httpd on
6.1 Compiling Mysql
Note: Before Compiling the mysql we need to create a user called "mysql" so that we can run the mysql service under his privilege
[root@freedom] # groupadd mysql
[root@freedom] # useradd -g mysql mysql
[root@freedom] # cd /usr/local/src/lamp
[root@freedom] # ll
total 44848
drwxr-xr-x 12 clado clado 4096 Oct 23 23:58 httpd-2.2.22
-rw-r--r-- 1 root root 7200529 Jan 31 2012 httpd-2.2.22.tar.gz
-rw-r--r-- 1 root root 24739429 Aug 29 22:13 mysql-5.5.28.tar.gz
-rw-r--r-- 1 root root 13978086 Oct 18 23:11 php-5.4.8.tar.gz
[root@freedom] # tar -xvf mysql-5.5.28.tar.gz
[root@freedom] # cd mysql-5.5.28
[root@freedom] # pwd
/usr/local/src/lamp/mysql-5.5.28
[root@freedom] # cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lamp/mysql -DMYSQL_DATADIR=/usr/local/lamp/mysql/data
---------------------------------------------------------------------------------------------------------------------------------------------
Note: If you get any error while running the camke like any dependency error first you nee to install the proper rpm
and before running the cmake again you should remove CMakeCache.txt
[root@freedom] # rm -rf CMakeCache.txt
---------------------------------------------------------------------------------------------------------------------------------------------
[root@freedom] # make
[root@freedom] # make install
[root@freedom] # chown -R mysql:mysql /usr/local/lamp/mysql
[root@freedom] # /usr/local/lamp/mysql/scripts/mysql_install_db --user=mysql --basedir=/usr/local/lamp/mysql/ \
--datadir=/usr/local/lamp/mysql/data/
--------------------------------------------------------------------------------------------------------------------------
If you installed mysql rpm already using rpm then you should go though this steps
[root@freedom] # rm -rf /etc/my.cnf
[root@freedom] # chkconfig --del mysqls
-------------------------------------------------------------------------------------------------------------------------
[root@freedom] # cp /usr/local/lamp/mysql/support-files/mysql.server /etc/init.d/mysqld
[root@freedom] # cp /usr/local/lamp/mysql/support-files/my-medium.cnf /etc/my.cnf
[root@freedom] # chkconfig --add mysqld
[root@freedom] # chkconfig --list mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@freedom] # service mysqld restart
[root@freedom] # netstat -ntlp | grep mysql
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 22455/mysqld
7.1 Compiling php
[root@freedom] # cd /usr/local/src/lamp/
[root@freedom] # tar -xvf php-5.4.8.tar.gz
[root@freedom] # cd php-5.4.8.tar.gz
[root@freedom] # ./configure --prefix=/usr/local/lamp/php --with-apxs2=/usr/local/lamp/apache/bin/apxs \
--with-mysql=/usr/local/lamp/mysql/
[root@freedom] # make
[root@freedom] # make install
[root@freedom] # cp /usr/local/src/lamp/php-5.4.8/php.ini-production /usr/local/lamp/php/lib/php.ini
7.2 Checking php module is installed properly
[root@server php-5.4.8]# /usr/local/lamp/apache/bin/apachectl -t -D DUMP_MODULES | grep php
php5_module (shared)
Syntax OK
7.3 Tell apache to process file starting .php extension
Open up the file "/usr/local/lamp/apache/conf/httpd.conf " then add " AddHandler application/x-httpd-php .php " with in the <IfModule mime_module> ....... </IfModule>
[root@freedom] # vim /usr/local/lamp/apache/conf/httpd.conf
........................
........................
<IfModule mime_module>
........................
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddHandler application/x-httpd-php .php .html
.........................
.........................
</IfModule>
7.4 Checking Everything works properly
Create an index.php under /usr/local/lamp/apache/htdocs/ with the following contents.
[root@freedom] # vim /usr/local/lamp/apache/htdocs/index.php
<?php
phpinfo ();
?>
:wq
[root@freedom] # service httpd restart
[root@freedom] # service mysqld restart
"Now open up a browser and type http://127.0.0.1/index.php or http://yourip you will get test page containing information about php,mysql,apache and all the libraries compiled with php "
Making index.php as the default page
Edit /usr/local/lamp/apache/conf/httpd.conf as follows
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
TO
<IfModule dir_module>
DirectoryIndex index.php index.html
</IfModule>
Removing the Installed LAMP server
you can simply unstall the lamp server by removing the directories in which you have installed the source code but before doing this you should properly stop the running services .
[root@freedom] # service httpd stop
[root@freedom] # service mysqld stop
[root@freedom] # rm -rf /usr/local/lamp/apache
[root@freedom] # rm -rf /usr/local/lamp/mysql
[root@freedom] # rm -rf /usr/local/lamp/php