Friday, March 04, 2011

OpenBSD NC4200: Apache + PostgreSQL + PHP5 + P4A. Another interesting project.

Ok this is my current project. I'm exploring PHP now and because I only have a little knowledge on programming PHP, I need to use some sort of RAD / Visual tool to start building PHP website fast. I read that P4A - PHP For Applications - PHP RAD Framework is one of the tool that can be use so I'm exploring that now. So I need to build a OAPP (OpenBSD + Apache + PostgreSQL + PHP) environment on my 4.8. I would love a pre-built stack for this but AFAIK, there's none for OpenBSD. It's not a bad thing though because manual installation is better for my brain somehow.

1) Setting up Apache
OpenBSD have a custom Apache 1.3 installed by default. There's also Apache 2 package but I'll just focus with what's already there. To get the Apache running I just edit /etc/rc.conf.local and add:

httpd_flags=""

2) Setting up PostgreSQL
I installed these packages:
postgresql-server-8.4.4
postgresql-client-8.4.4
postgresql-docs-8.4.4

After installation, you can see the brief steps you need to take to enable PostgreSQL. I had problem using su - _postgresql because I kept getting wrong password. After searching for answer, I found a way for that.

2.1) Set password for _postgresql
# su
# passwd _postgresql


Then after the password for user _postgresql has been set, I can finally follow the brief tips for starting up PostgreSQL (which can also be read at /usr/local/share/doc/postgresql/README.OpenBSD).

# su - _postgresql
# mkdir /var/postgresql/data
# initdb -D /var/postgresql/data -U postgres -A md5 -W


You can follow the rest of the steps contained inside /usr/local/share/doc/postgresql/README.OpenBSD. I also read somewhere on the net that I need to edit /etc/rc.conf.local and add this line:

postgres_flags=""

2.2) Set up phpPgAdmin
I installed phpPgAdmin-4.2.3 package which will also install core php5 packages. I had a problem trying to log in to phpPgAdmin using postgres id which has been created earlier. After googling for answer, here's the way to do that. Edit the file /var/www/phpPgAdmin/conf/config.inc.php. Then edit/add the bolded text.

// Hostname or IP address for server. Use '' for UNIX domain socket.
// use 'localhost' for TCP/IP connection on this computer
$conf['servers'][0]['host'] = 'localhost';

// If extra login security is true, then logins via phpPgAdmin with no
// password or certain usernames (pgsql, postgres, root, administrator)
// will be denied. Only set this false once you have read the FAQ and
// understand how to change PostgreSQL's pg_hba.conf to enable
// passworded local connections.
$conf['extra_login_security'] = false;


Then after that I can log in using postgres id and manage the PostgreSQL database. There's also pgadmin3 program which uses wxWidget, a GUI program to manage PostgreSQL database.

3) Install PHP5
As I wanted to try out P4A - PHP For Applications - PHP RAD Framework, the relevant PHP5 packages I installed is:

php5-core-5.2.13p0
php5-pdo_pgsql-5.2.13p0
php5-pgsql-5.2.13p0

Installation is straightforward and there's brief description on how to enable PHP5 support + testing out PHP5.

4) Set up P4A - PHP For Applications - PHP RAD Framework
http://p4a.sourceforge.net/ have the nescessary files for the application. I downloaded p4a-3.8.1.zip from the site, unzip the package and rename the p4a-3.8.1 folder to p4a. After that I move the folder to /var/www/htdocs/. When I open up http://localhost/p4a/ using Firefox, I can see the P4A page. I'm currently having problem viewing the hello_world sample page correctly and I'm trying to find some answer for that. This RAD program is made for linux but I noticed there's OpenBSD user using it too. So I guess there's a way for me to get it to work correctly.

5) Install NetBeans + PHP plugins.
I installed NetBeans 6.9 from OpenBSD's package. I know NetBeans still have weird character issue on compiling Java codes but I'm not using NetBeans to write Java program. Instead, I want to use NetBeans to write PHP codes. So after I installed NetBeans from package, I installed PHP related plugins. After that, I wrote the hello_world sample P4A code which is available in the P4A website and wallah! It's working. I've also linked NetBeans with PostgreSQL and it's working fine.

So far, all is ok. I'm studying PHP bits by bits, slowly as a serious hobby rather than serious work. One thing for sure, this is a start. Later.

No comments: