Friday, July 12, 2013

/usr/bin/env: php: No such file or directory

/usr/bin/env: php: No such file or directory

If you are getting this error, it means php is not installed or the file is corrupted.
Install it using
$ sudo apt-get install php5-cli
If you are still getting the error, Install all php packages using
$ sudo apt-get install php5 $ sudo apt-get install libapache2-mod-php5

Error: rpmdb open failed

YUM Error :  rpmdb open failed

To remove this error, Run these commands.

First clean up downloaded yum cache.
# yum clean all
Now remove all db files
# rm -f /var/lib/rpm/__db*
Rebuld the rpm database
# rpm --rebuilddb
Update yum
# yum update
OR
Method - II
# rm -f /var/lib/rpm/__db.[0-9][0-9]* # rpm --quiet -qa

If you get the error
rpmdb: write: 0xvendor-id, product-id: No space left on device
after running above commands. Check space in your filesystem.

Friday, June 28, 2013

Run php script on command line in Linux

Run php files on terminal :

First make sure you should have following packages installed on your system.
  • php5 
  • libapache2-mod-php5
  • php5-cli
Method : I
Now run the script on the terminal
# php /path/of/the/phpfile.php
Disadvantage :
If your php file in the xampp and if it requires database connectivity, the file will not be run successfully because it will not be able to connect to database. It will try to connect to default mysql server. It does not connect to xampp's mysql server. You will have to change the socket path to connect to xampp's mysql server.

Method : II
You have another way to run php files on terminal but you should be able to run them successfully on your browser.
I mean, you should have a web-server (apache) and a database-server (mysql) on your system. Now the same way you run your php file on browser, we can run it on terminal too.

Suppose you can run your php file using following url in your browser.
http://localhost/project-directory/phpfile.php

Run following command on terminal.
# wget http://localhost/project-directory/phpfile.php
Disadvantage :
The disadvantage of this method is, every time when you run the command , it downloads the php file in current directory where you run the command.

Advantage :
Method Ist's disadvantage is Method IInd's advantage.