What is it?

It’s mean PHP File can be execute as bash file and generate some action to my Linux Box.

What For?

I make php file executeable because I don’t have advantage experince to make bash file, but I know a little bit about PHP for access database and show it on web.

HowTo make it?

In this HowTo, I make example that PHP file access database (PostgreSQL), query some data from table, and save that data to another table. I run this PHP file on my Debian Server.

Install some packages

aptitude install php4 postgresql libapache2-mod-auth-pgsql
php4-pgsql php4-cli

Make PHP File

vi runphp.php

Add this line to the first line

#!/usr/bin/php4

And make you own script with PHP Syntax. You can see my example file here (rename it from .txt to .php). This file doing this following actions:

  • Connect to database (PostgreSQL).
  • Get some data from database.
  • Determine cost variable from that data with some function.
  • Insert usefull new data into another table.

Make It Execuable
Make sure this php file can be execuate by:

chmod +x runphp.php

Get Error?

First time I run this file, I get this following error:

Warning: pg_connect(): Unable to connect to PostgreSQL server: FATAL: ....

Don’t worry, this error can be happen because by default PostgreSQL support for php4 in Debian is not enabled yet in the configuration for the Apache2 SAPI. :D So type this command:

dpkg-reconfigure php4-pgsql
/etc/init.d/apache2 restart

That error should be fixed.

Run This File

Just type this command

./runphp.php

Well done and Good Luck

me, sUpricak3p

Related Posts: