LAMP Quickstart For Red Hat Enterprise Linux 4
LAMP Quickstart For Red Hat Enterprise Linux 4
Dave Jaffe
Dell Enterprise Marketing
December 2005
Introduction
A very common way to build web applications with a database backend is called
a “LAMP Stack”, where “LAMP” stands for the Linux® operating system, the
Apache web server, the MySQL database, and the PHP (or Perl or Python) web
application language. This Quickstart will take you through configuring and
starting up the LAMP components, and then downloading, installing and testing a
complete LAMP application, an online DVD Store written by Dell engineers. The
DVD Store application, including four PHP pages and the code needed to build
and load the MySQL database, can be used as a model for your own LAMP web
application.
This Quickstart assumes you have successfully installed Red Hat® Enterprise
Linux 4 on your server (RHEL4 ES edition was used for the test but the
instructions should be similar for the other RHEL4 editions) and are moderately
familiar with Linux commands (you will need to be able to edit files). Total time to
work through the Quickstart should be 30 – 60 minutes.
Getting Started
For ease of use, log into the system as root.
Verify that the required packages have been installed. To do this, click on
Applications => Systems Settings => Add/Remove Packages. This will bring up
a window showing all of the packages available, and what has already been
installed, sorted by groups. Scroll down to the Servers section and verify the
Web Server and MySQL Database have been checked. Under details of
MySQL Database, verify that both php-mysql and mysql-server have also
been checked. If any of these items have not been previously checked, simply
click the update button at the bottom of the window and provide the appropriate
installation media as requested.
For purposes of this document, the hostname is “rhel4es” and the root password
is “password” (you should use something more creative, of course!). You will
need to ensure that all of the appropriate host name information has been
set in your network environment (updating DNS, or /etc/hosts, etc.) You will
need to create a non-root user to own the PHP and MySQL code. We used user
“web” with password “web”.
useradd web
passwd web
At this point, it will prompt you for the new password. Use “web” as the password
(ignore the warnings for BAD PASSWORD – you can always change this later).
For the rest of this document you will enter some commands as root and some
as web. [Hint: use two Linux command shells, one for root, one for web. If you
are logged in as root you can use the command su – web to login as web in that
command shell].
cd /etc/httpd/conf
cp httpd.conf httpd.conf.orig
gedit httpd.conf
Find the line with #ServerName new.host.name:80 and add below it:
ServerName rhel4es
Save your changes; close the window. Next, you will start the web server, and
configure it so that it will automatically start on the next reboot. Type the
following into the shell window:
service httpd start
chkconfig httpd on
To test Apache, bring up a web browser with URL http://localhost. You should
see the Red Hat Enterprise Linux Test Page:
Next you need to start the MySQL service (called “mysqld”), and set it to always
start when the machine starts. Type the following into the terminal shell:
service mysqld start
chkconfig mysqld on
Now configure user access to the MySQL database. To change root’s password
(replace the final “password” with your root password), give privileges to the web
This will prompt you for the password you just entered above, and start the
MySQL monitor. You will need to ensure that you also add access based on
your specific host name as well (i.e. [email protected]). Type the
following at the mysql> prompt:
grant all privileges on *.* to web@localhost identified by 'web';
grant all privileges on *.* to web@rhel4es identified by 'web';
delete from mysql.user where User='';
exit
This will start the MySQL monitor as the user “web”. Type the following at the
mysql> prompt to test it:
show databases;
Type “exit” to leave the MySQL monitor. Type “exit” again to log out as “web”.
This shows that MySQL has been installed with the initial two databases.
cd /etc
cp php.ini php.ini.orig
gedit php.ini
Save the document, close the window, then continue typing the following into the
terminal shell window to restart the web server and put the changes you just
made into effect:
service httpd restart
To test PHP, create a test PHP page. Type the following into the terminal
window:
cd /var/www/html
gedit default.php
su – web
wget http://linux.dell.com/dvdstore/ds2.tar.gz
wget http://linux.dell.com/dvdstore/ds2_mysql.tar.gz
This will create several directories under /home/web/ds2 with the DVD Store data
files and driver programs, as well as the MySQL build and load scripts. Now, as
root, you will need to create a directory to put the PHP pages:
cd /var/www/html
mkdir ds2
Now you are ready to create and test the MySQL DVD Store database. As web:
cd ~/ds2/mysqlds2
sh mysqlds2_create_all_nosp.sh
mysql –u web --password=web
mysql> exit
This shows that the DVD Store has been installed correctly with 8 tables and
20,000 initial customers.
The DVD Store LAMP stack is ready for testing. With your browser, access
http://rhel4es/ds2. You should see the DVD Store Login page:
Click on “Start Shopping”, search for some DVDs by Title, Actor or Category, add
DVDs to your shopping cart, and finally purchase them using your stored credit
card number.
You now have a working LAMP stack. By basing your application on the MySQL
and PHP code included here, you can jumpstart your own LAMP stack!
THIS PAPER IS FOR INFORMATIONAL PURPOSES ONLY, AND MAY CONTAIN TYPOGRAPHICAL ERRORS AND
TECHNICAL INACCURACIES. THE CONTENT IS PROVIDED AS IS, WITHOUT EXPRESS OR IMPLIED WARRANTIES
OF ANY KIND.