You are on page 1of 5

Linux LAMP PostgreSQL Install & Configure Apache, PHP, and MySQL PSQL on Linux v1.

Global Open Versity


IT Systems Integration Hands-on Labs Training Manual

Apache, PHP, MySQL and PostgreSQL on Linux HowTo


By Kefa Rabah, krabah@globalopenversity.org March 2008 SerengetiSys Labs

Introduction
There are two sections involved in this article: Part 1 covers installation of Apache, MySQL and PHP,
while Part 2 deals mainly with installing PostgreSQL. The article assumes that you already installed
CentOS52.

Assumptions:
It’s assumed that you have a good understanding of Linux operating system and its working environment.
It’s also assumed that you know how to install and configure Linux CentOS5, if not go ahead and pop over
to scribd.com and check out a good HowTo entitled “Install Configure and Upgrade Linux CentOS5 Server
v1.1” to get you started.

Part 1: Installing Apache, PHP, MySQL

These will the basic components for a dynamic, database-driven web site. We use yum to handle of the
required packages

1. Install Apache (httpd), PHP, MySQL (server and client), and the component that allows PHP to talk to
mysql.

yum install httpd* php* mysql* -y

Note that: * indicates install all components

2. Configure the service to start automatically

/sbin/chkconfig httpd on

/sbin/chkconfig --add mysqld

/sbin/chkconfig mysqld on

/sbin/service httpd start

/sbin/service mysqld start

3. IMPORTANT! Set up the mysql database root password. Without a password, ANY user on the box can
login to mysql as database root. The mysql root account is a separate password from the machine root
account.

mysqladmin –u root password 'new-password' \\quotes are required

1
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org A GOV Open Knowledge Access License Technical Publications


Linux LAMP PostgreSQL Install & Configure Apache, PHP, and MySQL PSQL on Linux v1.2

4 Make additional security-related changes to mysql.

Mysql –u root –p
Mysql> DROP DATABASE test; \\ removes the test dbase
Mysql> DELETE FROM mysql.user WHERE user =''; \\ removes anonymous across
Mysql> FLUSH PRIVILEGES;

5. Following the above steps, the document root for Apache is /var/www/hmtl/

6. Create a test PHP script (test.php) and place in the documents root. A useful test script sample:

<?php
Phpinfo();
?>

7. Create a database and database user for your data. You will use this database and username in your
database connection string. The GRANT statement actually creates a new MYSQL user account.

Mysql> GREATE DATABASE web_db;

Mysql> GRANT ALL PRIVILEGES ON web_db.* TO 'web_user'@'localhost' IDENTIFIED


BY 'thepassword';

Part 2: Installing PostgreSQL on Fedora Core (skip MySQL)

This will install the PostgreSQL database server and the component required to write PHP scripts that
communicate with postgresql. We use yum to handle dependencies and gather all of the required
packages. For more information on PostgreSQL, see http://www.postgresql.org

1. Install PostgreSQL and the component that allows PHP to talk to PostgreSQL.

# yum -y install postgresql postgresql-server php-pgsql

2. Configure the new service to start automatically on boot

# /sbin/chkconfig –-level 345 postgresql on

# /sbin/service postgresql start

Note: when you start postgresql for the first time, it’ll initialize the database.

3. Start the postgresql interactive shell and create your first user and database.

# su - postgres \\The dash "-" is important!

2
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org A GOV Open Knowledge Access License Technical Publications


Linux LAMP PostgreSQL Install & Configure Apache, PHP, and MySQL PSQL on Linux v1.2

4. Next, issued the command, "psql template1", to enter the default postgresql database

-bash-3.2$ psql template1


Welcome to psql 8.1.11, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
template1=#

Note: "template1"is the database that is included by default with PostgreSQL.

5. Check the version of your postgresql:

template1=# select version();


version
--------------------------------------------------------------------
PostgreSQL 8.1.11 on i686-redhat-linux-gnu, compiled by
GCC gcc (GCC) 4.1.2 20070626 (Red Hat 4.1.2-14)
(1 row)
template1=# \q
-bash-3.2$

6. Now create dbase user "webadmin" and make him a superuser:

-bash-3.2$ createuser -P webadmin


Enter password for new role:
Enter it again:
Shall the new role be a superuser? (y/n) y
CREATE ROLE
-bash-3.2$

7. Next create the database "webdbase"

-bash-3.2$
-bash-3.2$ createdb -O webadmin webdbase
CREATE DATABASE
-bash-3.2$

8. Now connect into your newly created database:


-bash-3.2$ psql webdbase
Welcome to psql 8.1.11, the PostgreSQL interactive terminal.
Type: \copyright for distribution terms
\h for help with SQL commands
\? for help with psql commands
\g or terminate with semicolon to execute query
\q to quit
webdbase=#
3
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org A GOV Open Knowledge Access License Technical Publications


Linux LAMP PostgreSQL Install & Configure Apache, PHP, and MySQL PSQL on Linux v1.2

9. Logout of your dbase:

webdbase=# \q
-bash-3.2$ logout
[root@linuxc ~]#

10. Edit the postgres host based access (pg_hba) configuration file:

# vi /var/lib/pgsql/data/pg_hba.conf

11. Modify the local line to use "md5" based authentication rather than "ident sameuser". Please
review the PostgreSQL documentation before making this change and take the security

local all all md5

12. Restart the postgresql database service.

# /sbin/service postgresql reload \\restart postgresql

13. Log back into the server

# su – postgres

14. Test your connection.

# psql -U webadmin webdbase \\ or psql webdbase

15. Following the above steps, the database location on is /var/lib/pgsql/data.

16. Hooray! – Enjoy LAMP + PostgreSQL

Note: You may need to install Webmin from www.webmin.com to ease your server administration pain!

17. Stay tuned!

In the coming articles we will show how you use Apache, MySQL/PostgreSQL and PHP, to deploy Moodle
LMS, SugarCRM and Drupal.

-----------------------------------------------

Kefa Rabah is the Founder and CIO, of Serengeti Systems Group Inc. Kefa is knowledgeable in several fields
of Science & Technology, IT Security Compliance and Project Management, and Renewable Energy Systems.
He is also the founder of Global Open Versity, a place to enhance your educating and career goals using the
latest innovations and technologies.

4
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org A GOV Open Knowledge Access License Technical Publications


Linux LAMP PostgreSQL Install & Configure Apache, PHP, and MySQL PSQL on Linux v1.2

ICT202 - Linux Enterprise Infrastructure Engineering Diploma

This is an advance Linux course for IT professionals, Network Infrastructure


Engineers in enterprise business information technology (IT) strategy &
development. The goal of this course is to equip students and IT professionals with
advance Linux skills required in enterprise infrastructure planning, design,
development, implementation and deploying complex network infrastructure. In this
course you will learn how to install and configure Linux OS. Design & implement a
DNS master & slave servers for redundancy. Deploy virtual domains suitable for ISP
solution. Configure DHCP server; Deploy network defense security appliances and
Firewall solutions. Design & Install & Deploy Secure Apache Tomcat AS, LAMP.
Design & Implement OpenLDAP or OpenDS infrastructure for Single-Sign-On (SSO).
Deploy Sendmail, Postfix & Zimbra messaging systems. Install Email clients
Thunderbird & Evolution. Deploy JBoss & JPortal infrastructure, Liferay Portal
Enterprise. Integrate Samba with Windows Active Directory & Mac OSX
infrastructure for SSO. GlassFish & SAML on Linux, Deploy Moodle LMS. Deploy
SugarCRM. Upon completion of this course you will have gained advance knowledge
and skills at expert competency with capability to deploy complete medium
enterprise level network infrastructure solution. Or start your own ISP business or
Linux consultancy services. PREQ: BM103, BM200, CIS102, CIS105, CIS107,
CIS200, CIS202/CIS402, & CIS204.Donate and help others bridge the digital divide
Enhancing experiential education to all through eLearning in the 21st Century

5
© April 2007, Kefa Rabah, Global Open Versity, Vancouver Canada

www.globalopenversity.org A GOV Open Knowledge Access License Technical Publications

You might also like