Sumedh

How to install, configure Apache, Php, Postgresql on Linux.



Summary - Installing configuring Apache, Php and Postgres.
Published - Apr 02/2006
Last Updated - Aug 02/2009
Author - Sumedh
Note - This tutorial assumes that you know how to compile and install a program from its source.




Download and install Postgres.

1) Switch to the root user.
2) Download Postgresql source from http://www.postgresql.org/download
3) Extract Postgresql to any folder of your choice.
./configure
make
make install
4) Create a new user called postgres.
mkdir /usr/local/pgsql/data
chown postgres /usr/local/pgsql/data
su - postgres
/usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data
/usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data
/usr/local/pgsql/bin/createdb test
/usr/local/pgsql/bin/psql test
Download and install Apache.
5) Download Apache source from http://httpd.apache.org
6) Extract Apache to any folder of your choice.
7) Configure and install Apache.
./configure --prefix=/usr/local/apache --enable-so --enable-rewrite
make
make install
Download and install Php.

8) Download Php source from http://www.php.net/downloads.php
9) Extract Php to any folder of your choice.
10) Configure and install Php.
./configure --with-apxs2=/usr/local/apache/bin/apxs --with-pgsql
      Note - Dont forget --with-pgsql
make
make install
Configure Php.ini.

11) Copy php.ini or php.ini-dist from the folder where you extracted php to /usr/local/lib

12) Go to /usr/local/lib folder and open the php.ini-dist file in any simple text editor like emacs.
13) Find 'extension=php_pgsql.dll' in the file and remove the ' ; ' before that line.

Configure Apache.

14) Open the httpd.conf file in /usr/local/apache/conf folder in any simple text editor.
15) Make sure the following line is there in the LoadModule list, if it is not there add it.
LoadModule php5_module modules/libphp5.so
16) Find the AddType application section and add or uncomment the following lines.
AddType application/x-httpd-php .php .php3 .phtml
AddType application/x-httpd-php-source .phps
17) In the User/Group list, edit or add these lines.
User postgres
Group daemon
Test Apache and Php.

18) Start Apache, you will need sudo access.
/usr/local/apache/bin/apachectl start
19) Go to /usr/local/apache/htdocs. This is the default folder where Apache puts it html files.
20) Create a new php file called index.php
21) Copy paste the following lines in that file.
<?php
  phpinfo();
?>
22) After saving it open http://localhost/index.php in Firefox
      Dont tell me that you dont use firefox :)



      If you see a page similar to the one given below then you have installed php correctly.
      Scroll down till you see pgsql. Congrats you have configured php with postgres.

       Php options              pgsql options
Click on the thumbnail to get a bigger image
      Note - If you cannot see the php information page, try restarting apache.


Copyright © 2002 - 07 Sumedh K