Execute Perl/PHP scripts from the command line

Executing PHP/Perl scripts from the command line is a very easy task. Executing scripts from the command line can be very useful when troubleshooting cron jobs.

For PHP, just use the php command:

root@web [/backup]# php /home/manus/public_html/phpscript.php
I am a PHP script ... :)
root@web [/backup]#

The code for the PHP script from our example:

<?php
echo "I am a PHP script ... :)";
?>

For Perl, we will use the perl command:

root@web [/backup]# perl /home/manus/public_html/perlscript.pl
Hi! I'm a PERL script.
root@web [/backup]#

The code for the Perl script from our example:

#!/usr/bin/perl
use strict;
use warnings;
print("Hi! I'm a PERL script.");

For specific command options run php -h and perl -h.

As you see, when using the commands without any options, the output will be printed on the terminal.

This Post Has 3 Comments

Leave a Reply