Saturday, August 29, 2009

Installing and setting up phpPgAdmin

In this blog, I'll discuss on how to setup phpPgAdmin. But before going any further where can phpPgAdmin be used? PhpPgAdmin is a counter part of phpMyAdmin. If phpMyAdmin is the web admin user interface managing MySQL server then phpPgAdmin is for PostgreSQL. PhpPgAdmin was created to ease the administration of PostgreSQL. Below are the requirements needed to build the admin.

Requirements:

- PHP installed
- PostgreSQL installed (for instruction on how to install postgreSQL server see http://www.designmagick.com/article/2/Starting-Out/Installing-PostgreSQL)

- if you are running CentOS distro or the like then you can just do yum to install all of these needed packages.

Note: by default the installation of Postgres creates user postgres with no password (postgres by default is the superuser for PostgreSQL).

Here are the steps to take to be able to make phpPgAdmin running:

1. Download phpPgAdmin

# cd /usr/src/
# wget http://downloads.sourceforge.net/project/phppgadmin/phpPgAdmin%20%5Bstable%5D/phpPgAdmin-4.2.2/phpPgAdmin-4.2.2.tar.gz?use_mirror=nchc

2. Extract the package

# tar xvzf phpPgAdmin-4.2.2.tar.gz

3. Rename the folder and move folder to the web server document root (assuming your document root is at /var/www/html)

# mv phpPgAdmin-4.2.2 /var/www/html/phpPgAdmin

4. You should be able to browse phpPgAdmin on browser

http://xxx.xxx.xxx.xxx/phpPgAdmin/

5. Notice that what ever you put you always get "Login Failed". To correct that edit config.inc.php (located at /var/www/html/phpPgAdmin/conf/config.inc.php), set $conf['extra_login_security'] to false for now.

from

$conf['extra_login_security'] = true;

to

$conf['extra_login_security'] = false;

6. Do also the changes as follow on config.inc.php

from

$conf['servers'][0]['host'] = '';

to

$conf['servers'][0]['host'] = 'localhost'; // this is to allow tcp login

7. Now login to phpPgAdmin using username postgres without password

8. Create a user with password. (Another admin since it is advisable to use other super user account to avoid hack).

9. Once a new admin user has been created. Logout from the phpPgAdmin.

10. Edit the postgreSQL configuration (pg_hba.conf) to set md5 authentication for all connecting client via tcp. (By default all created user are trusted even without authentication). Do the changes as follow.

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

from

host all all 127.0.0.1 255.255.255.255 trust

to

host all postgres 127.0.0.1 255.255.255.255 trust
host all all 127.0.0.1 255.255.255.255 md5

save the file and restart postgresql

# service postgresql restart

11. Edit again the config.inc.php and do the changes as follow:

# vi /var/www/html/conf/config.inc.php

from

$conf['extra_login_security'] = false;

to

$conf['extra_login_security'] = true;

12. Now you should be able to login using the new admin account created with password. Postgres super user will always be denied to login on phpPgAdmin for security reason.

All should be working fine from this point. You now have a running phpPgAdmin. I hope this helps for those who are establishing their PostgreSQL web admin. Cheers, Take care and God Bless!!!!

Tuesday, August 18, 2009

Doing FTP in PHP

I had an issue during a development of one of my projects. One of the modules deals with FTP'ing files from one server to another. My script was able to login with no issues but I wondered why it was not able to write or ftp_put anything. I googled for few hours finding out how to overcome this issue that I have and came over with these links...

http://www.php.net/manual/en/function.ftp-pasv.php
http://us.php.net/manual/en/function.ftp-put.php#73168

Both of these links tell that you have to use ftp_pasv to set the ftp connection in passive mode. Meaning the ftp connection will be initiated from the client instead from the server. Also take note that ftp_pasv should be done immediately after calling the ftp_login.

Here is the comment I read there which gave or shed me the light for succesfully getting around with my problem.

"If you are having timeouts uploading a file, even very small files, you might have a look at ftp_pasv()

And don't forget to do it after your ftp_login();"

The sample code below shows how to do it.

$file = 'somefile.txt';
$remote_file = 'readme.txt';

// set up basic connection
$conn_id = ftp_connect($ftp_server);

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on
ftp_pasv($conn_id, true);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo
"successfully uploaded $file\n";
} else {
echo
"There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

I hope this experience that I had and I shared with you will help you out fixing issues doing FTP in PHP. Thanks, Cheers and God Bless!!!!

Tuesday, August 4, 2009

Silky Heart

Every hour of the day
Whenever I think about you
This impatient feelings
Just overflow

It would be easier if I just tell you that I love you
But when you appear in front of me
my personality stands up and interferes

I can usually pull through with my assertiveness
That's just the way I am
But no matter how hard I try, I can't break the wall that's between us

I want you to realize my feelings
That's why I always gaze at you with the message of...
"I love you"
With all of my courage!

My heart made of silk feels like it's about to rip apart
After meeting you, I finally realized
That I'm really clumsy when it comes to love
My scars from love that I've almost forgotten
Have started to ache all of a sudden
someday, like how I normally would...
I must tell you that I love you, or
else I'll become even weaker

If I say ‘I love you’, then I can be at ease
The truth is, even though I know that
When I sound it out, you seem to leave me

I wonder, what do you think
Of me?
At our current distance we’re merely friends, right?

I just might be whitewashing it
But I don’t want to get hurt, it’s just that alone…
Or so I persuaded myself
And I just ran away

If my flimsy silky heart
Gets hurt this time, then I’m sure
I won’t be able to love anyone ever again
The splitting sound that echoes in my chest
Is at the bottom of my memories, I’m sure
The sewing kit that I forgot to put away
On that day should be around somewhere…