Contributed by jose on from the helping-everyone dept.
The following is a description of my steps for setting up PHP and PostgreSQL under a chroot'ed Apache environment. This how-to is intended for those new to web-based apps or those who have used PHP and MySQL and would like to try out PostgreSQL as an alternative.
Before I get flamed for "the info is already out there- why do we need another how-to?" The overwhelming tutorials focus on MySQL and most that I came across for PostgreSQL either had older data, didn't address the chroot Apache issues or were not really geared for the beginner audience.
With that said, here's what I did to get things running..." Read on for Robert's instructions.
" 1. Set up a generic OpenBSD 3.3 install without "X-windows system" support. For more information on the minimum install files required:
http://www.openbsd.org/faq/faq4.html
2. Install the following packages:
- postgresql-7.3.2.tgz
- postgresql-docs-7.3.2.tgz
- php4-core-4.2.3p1.tgz
- php4-pgsql-4.2.3.tgz
#pkg_add -v ftp://ftp.openbsd.org/pub/3.3/OpenBSD/packages/i386/postgresql-7.3.2.tgz(note: remember to use mixed case)
Or you can grab packages from one of the many mirrors to load balance off the main site :-)
For more details about adding packages:
http://www.openbsd.org/ports.html
3. Post package configuration- most of this is posted on the screen after the package additions are complete but here's a summary.
Create your php.ini file:
#cp /usr/local/share/doc/php4/php.ini-dist /var/www/conf/php.iniMake Apache "aware" of the PHP installation and activate the database extension:
#/usr/local/sbin/phpxs -s #/usr/local/sbin/phpxs -a pgsqlThis will make some modifications to the Apache configuration file to load the appropriate PHP modules when Apache is started. Verify the following line is "uncommented" in /var/www/conf/httpd.conf:
LoadModule php4_module /usr/lib/apache/modules/libphp4.soIn order for Apache to call PHP to parse web pages, we must add the following file-extension association line as well:
AddType application/x-httpd-php .php .html4. Setup the database admin user and group accounts:
# useradd -c "Postgresql Admin User" -g =uid -m -d /var/postgresql -s /bin/sh postgresql
5. Create the database data folder and initial environment:
#su - postgresql $mkdir /var/postgresql/data $initdb -D /var/postgresql/dataPostgreSQL won't let you to anything without being logged in as this user.
6. Create the unix socket folder:
$mkdir /var/www/tmpBy default the database would try to write socket info to /tmp but since Apache will be chroot'ed to /var/www, /var/www/tmp "apears" to be /tmp in a web application scenario.
As far as permissions are concerned, I assigned full permissions to the postgresql account and group, read/list to world and owner deletion only (numerically represented as 1755). Many how-to guides say to set liberal 777 permissions but the above was the most restrictive setting that did not result in errors for me.
7. On the subject of the unix socket folder, open the database configuration file /var/postgresql/data/postgresql.conf and "uncomment" and edit the line:
unix_socket_directory = '/var/www/tmp'
8. Setting Apache and PostgreSQL to start at boot:
I know there are many ways to skin a cat but here's what I did...
Create a rc.conf.local file if you don't have one:
#touch /etc/rc.conf.localAdd the following line to section 1:
httpd_flags=""(note: that's no space and double quotes)
The above will override the httpd_flags=NO in /etc/rc.conf
And the following line to section 3:
shlib_dirs="$shlib_dirs /usr/local/lib/postgresql"This makes the system "aware" of the database libraries on startup.
In /etc/rc.local I added the following to start PostgreSQL:
su -l postgresql -c "/usr/local/bin/pg_ctl start -D /var/postgresql/data -l /var/postgresql/logfile -o '-D /var/postgresql/data'" echo -n 'postgresql'
9. To shutdown the database gracefully add the following to /etc/rc.shutdown:
if [ -f /var/postgresql/data/postmaster.pid ]; then su -l postgresql -c "/usr/local/bin/pg_ctl stop -m fast -D /var/postgresql/data" rm -f /var/postgresql/data/postmaster.pid fi(note: 2nd line is word wrapped to the 3rd line)
10. Changes to the /var/www/conf/php.ini file:
I secured persistent database connections because I have read it can cause reliability issues (maybe someone can comment on their experience)
[Postgresql] pgsql.allow_persistent = OffTo save state between web pages in my application I set
[Sessions] session.auto_start=111. Reboot and ensure everything started properly with top or ps
#topShould see the httpd and postgresql running under their respective users.
12. Test that PHP initialized with Apache:
#touch /var/www/htdocs/info.phpType the following:
<?php phpinfo(); ?>And try to pull up that web page from another computer. You should get a pretty detailed report about the Apache and PHP installation configuration if it worked.
13. Verify that PostgreSQL create unix socket files properly:
Look in /var/www/tmp and you should see something like this:
.s.PGSQL.5432 .s.PGSQL.5432.lock14. The above steps are all that I did and it worked great for me. I am running a small test application and have had no issues so far.
For those of you thinking about trying an alternative to PHP/MySQL, the php database commands for PostgreSQL are strikingly similar to those used for MySQL. For the basic database function, don't be turned off due to extensive learning of new commands because there isn't.
It was my intention to help people get setup. Actually writing a PHP/PostgreSQL application is beyond the scope but the following have plenty of information:
http://www.apache.org/
http://www.php.net/
http://www.postgresql.org/
"
Wow, nice notes! Thanks for the help.
(Comments are closed)
By Anonymous Coward () on
Comments
By Anonymous Coward () on
By Anonymous Coward () on
By haynes horne () hphorne@yahoo.com on mailto:hphorne@yahoo.com
how can user www access the db server without being also user postgresql? openBSD notes are explicit about retaining the www user account for httpd. but my www group reads daemon and my postgresql group reads postgresql. where's the catch?
By Anonymous Coward () on
By Anonymous Coward () on
You might mention that the default Postgresql database user does not have a password after install, and setting one might not be such a bad idea. The database user account used by PHP perhaps should be an account without Postgresql superuser rights i.e. not have the right to create other database users.
Comments
By rwx () on
Comments
By Anonymous Coward () on
mention things like these.
By Anonymous Coward () on
By jim () on
Comments
By Anonymous Coward () on
LoadModule "modules/mod_python.so" to httpd.conf.
You need to set up .htaccess on the directory containing your scripts but thats about it.
Check the docs on http://www.modpython.org/ for more info.
By Anonymous Coward () on
By KryptoBSD () KryptoBSD@uncompiled.com on http://www.uncompiled.com
Glad to see some change.
By kvh () on
1. The ftp address should be ftp.openbsd.org/pub/OpenBSD/3.3/...
2.Step 5 it should be made explicit when you exit su
3. I didn't have a /etc/rc.conf.local with newly installed 3.3, so there are no sections in it.
4. Add at the end of the lines for the /etc/rc.local code
5. Don't do a touch at #12, use an editor.
Other than that it is great...
Comments
By kvh () on
By ac () on
By Anonymous Coward () on
By Anonymous Coward () on
By Anonymous Coward () on
When I figure that out, I think I will write a cookbook.
By Anonymous Coward () on
Warning: open(/tmp/sess_989368bd65448f70985379600fae56b8, O_RDWR) failed: Permission denied (13) in Unknown on line 0
Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0
Comments
By hillfieldhonest () on
currently,/var/www/tmp's permission is set to 1755 as instruction.
I also need your help! thanks!
By hillfieldhonest () on
worked fine with following modification in php.inf
before
session.save_path = /tmp
after
session.save_path = /var/www/tmp
If there is any other way to make it work,
please share your experience. Thanks.
Comments
By Anonymous Coward () on
Well it works here and makes logical sense.
By anonymous () alexlee@charter.net on mailto:alexlee@charter.net
After modifying 'session.save_path' to '=/var/www/tmp', I got error messages like :"Warning: open(/var/www/tmp/sess_85ce0bdcdd89f34933d2825d342e2b13, O_RDWR) failed: No such file or directory (2) in Unknown on line 0
Warning: Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/www/tmp) in Unknown on line 0"
Any suggestion where I should look into ? Thanks.
By Marc Herren () maildrop@dj-submerge.ch on mailto:maildrop@dj-submerge.ch
Can someone explain me how I can compile it myself ( diden't found the src neither )
Thanks
Marc
By Varyag () on
By Newbie that's lost () twoodbury@profitware.com on mailto:twoodbury@profitware.com
pgsql: could not connect to server: No such file or directory
Is the server running locally and accepting connections on Unix domain socket "/tmp/.s/PGSQL.5432"?
createdb: database creation failed
the postgres help says that the server isn't started properly... however it's there when i click top... and there's nothing in the tmp directory like the directions say there should be...
any clues as to where i've gone wrong???
thanks
-lost Newb
Comments
By sailor () sailor@happysailor.com on mailto:sailor@happysailor.com
Are we missing something here? :-/
Comments
By sailor () sailor@happysailor.com on mailto:sailor@happysailor.com
postgresql searched /tmp/ rather than /var/www/tmp/ for .s.PGSQL.5432 + *.lock.
dirty solution:
cd /var/www/tmp/
ln -s /var/www/tmp/.s.PGSQL.5432 /tmp/
ln -s /var/www/tmp/.s.PGSQL.5432.lock /tmp/
Comments
By R. Senthil Kumar (59.92.46.191) senthil.kumar@softenger.com on