How to Execute a PHP File Using Linux

The Hypertext PreProcessor (PHP) was originally developed as a scripting language to be embedded into HTML webpages. However, it also functions perfectly well as a general purpose scripting language for automating system tasks in Linux.

Instructions

    • 1

      Open a terminal. How this is done varies with each version of Linux. However, in most versions there is a link in the main menu that opens the terminal. It may be called "terminal," "shell" or "BASH."

    • 2

      Type the following command into the terminal:

      php -f file.php

      Replace "file.php" with the file name of the PHP script you would like to run.

    • 3

      Replace the "-f file.php" flag with "-a" if you would like to put PHP in interactive mode. This mode allows it to receive code directly from the standard input of the terminal, rather than from a file. This can be combined with Unix pipes and redirection commands to have greater flexibility in which PHP file is run in a larger shell script.

Related Searches:

References

Comments

Related Ads

Featured