Saturday, April 9, 2011

How To Run PHP File in Terminal

Usually we use browser to execute PHP file. What about running your PHP file in Terminal? Let's follow these steps:

# Make sure you install these package:
  • php5
  • libapache2-mod-php5
  • php-pear
  • php5-mysql
  • php5-pgsql
  • php5-cli (those five are dependency of php5-cli)
sudo apt-get install php5 libapache2-mod-php5 php5-cli php-pear
php5-mysql php5-pgsql
# Make a PHP test file echoing "Running PHP file via Linux terminal ... " and save it as myfile.php

# Run PHP file:
php myfile.php
# You will get this message:
PHP Deprecated:  Comments starting with '#' are deprecated in
/etc/php5/cli/conf.d/mcrypt.ini on line 1 in Unknown on line 0
# Open /etc/php5/cli/conf.d/mcrypt.ini with your favourite editor like vi or gedit. You will see the content of mcrypt.ini
# configuration for php MCrypt module
extension=mcrypt.so
# Replace sign '#' in the first line with ';'.

Run myfile.php once again and ta-daa... You will see
Running PHP file via Linux terminal ...
in the Terminal. Enjoy!

No comments: