How we run php script using Linux bash?
php file test.php
test.php
contains:
<?php echo "hello\n" ?>
Show activity on this post. Put that at the top of your script, make it executable ( chmod +x myscript. php ), and make a Cron job to execute that script (same way you'd execute a bash script). You can also use php myscript.
A PHP script can be executed from the command line even without having any web server software installed. To run the PHP script from the command line you should just have a PHP CLI (PHP Command Line Interface) installed on your system.
From the command line, enter this:
php -f filename.php
Make sure that filename.php both includes and executes the function you want to test. Anything you echo out will appear in the console, including errors.
Be wary that often the php.ini for Apache PHP is different from CLI PHP (command line interface).
Reference: https://secure.php.net/manual/en/features.commandline.usage.php
First of all check to see if your PHP installation supports CLI. Type: php -v
. You can execute PHP from the command line in 2 ways:
php yourfile.php
php -r 'print("Hello world");'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With