Category: PHP7
Added: 23rd of October 2020
Viewed: 260 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
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