Category: PHP7

Added: 23rd of October 2020

Viewed: 540 times

Running .php scripts from the terminal using Ubuntu

This tutorial works in Ubunbu, Kubuntu, Xubuntu, Lubuntu, Ubuntu Mate and other Ubuntu based distributions. The tutorial also works in Linux Mint and other Debian based distributions.

To install the latest version of PHP in Ubuntu or another Ubuntu based distribution enter the following command

sudo apt-get install php


It will install the latest version from the repository, in my case it installed php7, to check this I just entered the following command in the terminal

Enter php --version in the terminal to display the latest version

Next I created a new file on the desktop and entered the following code.
#!/usr/bin/php -q
<?php echo "Welcome to My Computer Tips"; ?>


And then saved the file as test.php

The first line of the code points to php interpreter which can be found in the bin directory
The second lines prints out a simple message, Welcome to My Computer Tips

So that you can run .php scrips from the terminal, we need to make the file executable.
To do this we use the chmod +x command.
chmod +x test.php


Then to run the .php script, enter the following
./test.php

Other Tips & Tutorials

PHP7

What version of .php are my hosts running

Posted: 3rd of December 2020

Views: 335

PHP7

Running .php scripts from the terminal using Ubuntu

Posted: 23rd of October 2020

Views: 540