PHP File Executeable

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

Share and Enjoy:

These icons link to social bookmarking sites where readers can share and discover new web pages.
  • bodytext
  • del.icio.us
  • StumbleUpon
  • Reddit
  • Facebook
  • BlinkList
  • BlogMemes
  • co.mments
  • description
  • Furl
  • Ma.gnolia
  • NewsVine
  • RawSugar
  • Shadows
  • Simpy
  • Slashdot
  • Spurl
  • Technorati
  • YahooMyWeb
  • Google
 

Related Posts


No Responses to “PHP File Executeable”  

  1. No Comments
Posting Your Comment
Please Wait

Yes, leave a comment here!

There was an error with your comment, please try again.