Build LAMP Server (step by step guide)

Share your expert knowledge and show off your skills.
Post Reply
nasacis
Battalion Havaldaar Major
Posts: 269
Joined: Sat Dec 13, 2003 3:58 pm
Location: Faisalabad
Contact:

Build LAMP Server (step by step guide)

Post by nasacis »

This document will walk you through the installation of what is known
as a "LAMP" Linux, Apache, MySQL and PHP system.

OS: CentOS 5.2
Apache: httpd-2.2.9.tar.gz
MySQL:mysql-5.0.51b.tar.gz
PHP:php-5.2.6.tar.gz
Method: tar-ball

Build and Install MySQL
groupadd mysql
useradd -g mysql -c "MySQL Server" mysql
cd /usr/local/src/mysql-4.1.22
chown -R root.root *
./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

Configuring MySQL

./scripts/mysql_install_db
chown -R root:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data
cp support-files/my-medium.cnf /etc/my.cnf
chown root:sys /etc/my.cnf
chmod 644 /etc/my.cnf
echo "/usr/local/mysql/lib/mysql" >> /etc/ld.so.conf
ldconfig
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
cd /usr/local/mysql/bin
ln -s /usr/local/mysql/bin/* /usr/bin/

Security Issue
Edit /etc/my.cnf and uncomment the line (delete the leading #).
skip-networking

Start MySQL
/etc/rc.d/init.d/mysql start
mysqladmin version
mysqladmin -u root password new-password #replace new-password with
your actual password of your database

Test Mysql
mysql -u root -p #provide password which you set with above command
and you will see mysql prompt
mysql>
drop database test;
use mysql;
delete from db;
delete from user where not (host="localhost" and user="root");
flush privileges;
update user set user="sqladmin" where user="root";
flush privileges;
create database foo;
drop database foo;
\q


Build and Installing APACHE
./configure --prefix=/usr/local/apache
make && make install

Build and Install PHP
./configure --with-apxs2=/usr/local/apache/bin/apxs --disable-debug --
enable-ftp --enable-inline-optimization --enable-magic-quotes --
enable-mbstring --enable-wddx=shared --enable-xml --with-gd --with-
gettext --with-mysql=/usr/local/mysql --with-regex=system --with-zlib-
dir=/usr/lib
make && make test && make install
cp php.ini-dist /usr/local/lib/php.ini
ln -s /usr/local/lib/php.ini /etc/php.ini
ln -s /usr/local/apache/conf/httpd.conf /etc/httpd.conf
vi /etc/httpd.conf #and add these content type in apache conf file
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.htm index.html

Start Apache
ln -s /usr/local/apache/bin/apachectl /etc/rc.d/init.d/httpd
ln -s /etc/rc.d/init.d/httpd /etc/rc.d/rc3.d/S90httpd
/etc/rc.d/init.d/httpd start

Regards
Nafees Ahmed
Cell: +92.300.8653568
UAN: 041-111432432
Nexlinx Faisalabad
www.nexlinx.net.pk
nafees29@gmail.com
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

LAMP on Ubuntu

Post by x2oxen »

Here is the One for Ubuntu Server

Installing Apache2

1. Open up the Terminal (Applications > Accessories > Terminal).

2. Copy/Paste the following line of code into Terminal and then press enter:

Code: Select all

sudo apt-get install apache2
3. The Terminal will then ask you for you're password, type it and then press enter.

Testing Apache2

To make sure everything installed correctly we will now test Apache to ensure it is working properly.

1. Open up any web browser and then enter the following into the web address:

Code: Select all

http://localhost/
You should see a folder entitled apache2-default/. Open it and you will see a message saying "It works!" , congrats to you!

Installing PHP5

In this part we will install PHP 5.

Step 1. Again open up the Terminal (Applications > Accessories > Terminal).

Step 2. Copy/Paste the following line into Terminal and press enter:

Code: Select all

sudo apt-get install php5 libapache2-mod-php5
Step 3. In order for PHP to work and be compatible with Apache we must restart it. Type the following code in Terminal to do this:

Code: Select all

sudo /etc/init.d/apache2 restart
Testing PHP5

To ensure there are no issues with PHP let's give it a quick test run.

Step 1.
In the terminal copy/paste the following line:

Code: Select all

sudo gedit /var/www/testphp.php
This will open up a file called phptest.php.

Step 2.
Copy/Paste this line into the phptest file

Code: Select all

<?php
phpinfo();
?>
Step 3. Save and close the file.

Step 4. Now open you're web browser and type the following into the web address:

Code: Select all

 http://localhost/testphp.php
Congrats you have now installed both Apache and PHP!

Installing MySQL5

To finish this guide up we will install MySQL. (Note - Out of Apache and PHP, MySQL is the most difficult to set up. I will provide some great resources for anyone having trouble at the end of this guide.)

Step 1.
Once again open up the amazing Terminal and then copy/paste this line:

Code: Select all

sudo apt-get install mysql-server
Step 2. This is where things may start to get tricky. Begin by typing the following into Terminal:

Code: Select all

mysql -u root -p
Enter in the password that you setup during the apt-get install process.

Step 3.
We are now going to install a program called phpMyAdmin which is an easy tool to edit your databases. Copy/paste the following line into Terminal:

Code: Select all

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin
After that is installed our next task is to get PHP to work with MySQL. To do this we will need to open a file entitled php.ini. To open it type the following:

Code: Select all

gksudo gedit /etc/php5/apache2/php.ini
Step 4. Once the text editor opens the php.ini file, go to the bottom of the file and add in the following line:

Code: Select all

extension=mysql.so
This will allow you to use MySQL within your PHP scripts.

Now just restart Apache and you are all set!

Code: Select all

sudo /etc/init.d/apache2 restart
Last edited by x2oxen on Mon Aug 18, 2008 10:39 am, edited 1 time in total.
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
mudasir
Captain
Posts: 565
Joined: Tue Oct 17, 2006 5:23 am
Location: Dubai
Contact:

Post by mudasir »

AOA,

Good work... Its worth an appreciation.
Kind Regards
Mudasir Mirza (RHCE)
(+971)55-1045754
http://www.crystalnetworks.org
http://www.diglinux.com
nasacis
Battalion Havaldaar Major
Posts: 269
Joined: Sat Dec 13, 2003 3:58 pm
Location: Faisalabad
Contact:

Post by nasacis »

thanks for appreciation
Nafees Ahmed
Cell: +92.300.8653568
UAN: 041-111432432
Nexlinx Faisalabad
www.nexlinx.net.pk
nafees29@gmail.com
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

php step 2 is broken.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
nasacis
Battalion Havaldaar Major
Posts: 269
Joined: Sat Dec 13, 2003 3:58 pm
Location: Faisalabad
Contact:

Post by nasacis »

from mine post ?
Nafees Ahmed
Cell: +92.300.8653568
UAN: 041-111432432
Nexlinx Faisalabad
www.nexlinx.net.pk
nafees29@gmail.com
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

is there a step 2 in your post?
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
nasacis
Battalion Havaldaar Major
Posts: 269
Joined: Sat Dec 13, 2003 3:58 pm
Location: Faisalabad
Contact:

Post by nasacis »

yes, but i did not mention :D
Nafees Ahmed
Cell: +92.300.8653568
UAN: 041-111432432
Nexlinx Faisalabad
www.nexlinx.net.pk
nafees29@gmail.com
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

This is what my aptitude search showed up.

root@proxy:~# aptitude search php5
p libapache2-mod-php5 ---------server-side, HTML-embedded scripting language (apache 2 module)
p libgv-php5---------Php5 bindings for graphviz
p php5---------server-side, HTML-embedded scripting language (meta-package)
p php5-apache2-mod-bt---------PHP bindings for mod_bt


Its working fine for me!
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
lambda
Major General
Posts: 3452
Joined: Tue May 27, 2003 7:04 pm
Location: Lahore
Contact:

Post by lambda »

the phptest step is broken.
Watch out for the Manners Taliban!
Isn't it amazing how so many people can type "linuxpakistan.net" into their browsers but not "google.com"?
LinuxFreaK
Site Admin
Posts: 5132
Joined: Fri May 02, 2003 10:24 am
Location: Karachi
Contact:

Re:

Post by LinuxFreaK »

Dear x2oxen,
Salam,

Agreed with lambda, you need to add some thing like this.

Code: Select all

<?php
phpinfo();
?>
Best Regards.
Farrukh Ahmed
x2oxen
Major General
Posts: 1114
Joined: Wed Aug 22, 2007 3:17 pm
Location: Faisalabad
Contact:

Post by x2oxen »

Its done! Is it seems ok now?
Muhammad Usman
+92-321-6640501
Chemonics International
http://usmanpk.com
Post Reply