How to compile and install LAMP Server on CentOS

Install MySQL 5
Steps:-

# cd /usr/local/src

Create a new user and group called ‘mysql’

# groupadd mysql
# useradd -g mysql mysql

For MySQL, go to http://www.mysql.com/ and choose an appropriate mirror to get the newest MySQL version

# wget http://www.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.28-linux2.6-i686.tar.gz/from/http://cdn.mysql.com/
# tar -vxf mysql-5.5.28-linux2.6-i686.tar.gz
# cd mysql-5.5.28-linux2.6-i686
# chown -R root.root *
# make clean

Compile and install MySQL

#./configure \ –prefix=/usr/local/mysql \
–localstatedir=/usr/local/mysql/data \
–disable-maintainer-mode \
–with-mysqld-user=mysql \
–with-unix-socket-path=/tmp/mysql.sock \
–without-comment \
–without-debug \
–without-bench

# make
# make install

Configure MySQL

MySQL is “installed” but we have a few more steps until it’s actually “done” and ready to start. First run the script which actually sets up MySQL’s internal database (named, oddly enough, mysql).

# ./scripts/mysql_install_db

Then we want to set the proper ownership for the MySQL directories and data files, so that only MySQL (and root) can do anything with them.

# chown -R root:mysql /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql/data

Copy the default configuration file for the expected size of the database (small, medium, large, huge)

# cp support-files/my-medium.cnf /etc/my.cnf
# chown root:sys /etc/my.cnf
# chmod 644 /etc/my.cnf

If you get an error message about the data directory not existing, etc., something went wrong in the mysql_install_db step above. Go back and review that; make sure you didn’t get some sort of error message when you ran it, etc.

Now we have to tell the system where to find some of the dynamic libraries that MySQL will need to run. We use dynamic libraries instead of static to keep the memory usage of the MySQL program itself to a minimum.

# echo “/usr/local/mysql/lib/mysql” >> /etc/ld.so.conf
# ldconfig

Now create a startup script, which enables MySQL auto-start each time your server is restarted.

# cp ./support-files/mysql.server /etc/rc.d/init.d/mysql
# chmod +x /etc/rc.d/init.d/mysql
# /sbin/chkconfig –level 3 mysql on

Then set up symlinks for all the MySQL binaries, so they can be run from anyplace without having to include/specify long paths, etc.

# cd /usr/local/mysql/bin
# for file in *; do ln -s /usr/local/mysql/bin/$file /usr/bin/$file; done
# /etc/rc.d/init.d/mysql start
# /etc/rc.d/init.d/mysql stop

Test MySQL

To run a quick test, use the command line program mysql:

mysql -u root -p

and enter your new root user password when prompted. You will then see the MySQL prompt:

mysql>

mysqladmin version
mysqladmin -u root password new-password

Installing Apache 2

# mkdir /usr/src/httpd
# cd /usr/src/httpd
# wget http://apache.techartifact.com/mirror//httpd/httpd-2.4.3.tar.gz
# cd httpd-2.4.3

Compile and Install.

# ./configure –prefix=/usr/local/apache2 [add extra options here if you required]
# make
# make install

# ./configure –prefix=/usr/local/apache2 –enable-mime-magic –enable-expires \
–enable-headers –enable-ssl –enable-http –enable-info –enable-dir \
–enable-rewrite –enable-so

Configuring Apache

You may want to change the document root.

Default DocumentRoot “/usr/local/apache2/htdocs”

Custom: DocumentRoot “/var/www/htdocs” # Or whatever folder you want to set as the document root.
Since we are using PHP, and want to use index.php as the default page in a directory, we have to set that configuration option. Find the line

DirectoryIndex index.html index.html.var
and replace it with, say,

DirectoryIndex index.php index.html index.html.var

Now we must associate all files with the extension ‘php’ with the PHP scripts handler. For this find the line

AddHandler type-map var
and add the following line below that line – like this

AddHandler type-map var
AddHandler php5-script php

Below that there is a AddType section. Add the following line to this section.

AddType application/x-httpd-php .php

Start the Server

# /usr/local/apache2/bin/apachectl start

Go to your document root(/var/www/htdocs) and create a php file called ‘info.php’ and put this code inside it…

<?php
phpinfo();

Now open a browser and try to access http://localhost/ you should see a file listing page with a ‘info.php’ in the list. Click on that link – if you see a PHP information page, your web server is setup correctly.

To make sure MySQL-PHP connection is working, install phpMyAdmin – or write a database connection script – whatever is easier for you.

Installing PHP 5

# mkdir /usr/src/php5
# cd /usr/src/php5
# wget http://in1.php.net/distributions/php-5.4.8.tar.gz
# cd php-5.4.8

Compile and Install.

# ./configure \
–prefix=/usr/local/php5 \
–with-apxs2=/usr/local/apache2/bin/apxs \
–with-mysql=shared,/usr/local/mysql

Start your LAMP Server

You can test your installation by starting your Apache service.

# /usr/local/apache2/bin/apachectl start

Go to your document root(/var/www/htdocs) and create a php file called ‘info.php’ and put this code inside it.

Advertisements

4 thoughts on “How to compile and install LAMP Server on CentOS

  1. Correct me If I’m wrong, but the MySQL file you suggested is a binary file!So, there will be NO cimpilation steps. Right ?!

  2. Someone necessarily lend a hand to make critically posts I’d state.
    This is the very first time I frequented your web page and to this point?
    I amazed with the analysis you made to make this
    particular publish extraordinary. Excellent activity!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s