PHP is a popular programming language that is mainly used for web development and creating dynamic websites. It can also be used from the command line to run PHP scripts, test code, and build simple applications. You can install and use PHP in Termux to create, practice, and learn PHP using simple commands without having a computer.
Install PHP in Termux
Follow the commands below to install PHP in Termux. After the installation is complete, you can start writing and running PHP programs from the terminal.
Update Termux packages.
pkg update && pkg upgrade -y
Install PHP.
pkg install php -y
Check the installed PHP version.
php -v
PHP is now installed and ready to use.
Basic PHP Commands
Display the installed PHP version.
php -v
Show all available PHP modules.
php -m
Display PHP configuration information.
php -i
Check the PHP configuration file location.
php --ini
Run a PHP script.
php file.php
Execute a single line of PHP code.
php -r "echo 'Hello, World!';"
Check PHP syntax without running the file.
php -l file.php
Start the built-in PHP development server.
php -S localhost:8000
Display the PHP help menu.
php --help
Create Your First PHP Program
Create a new PHP file.
nano hello.php
Add the following code:
<?php
echo "Hello, World!";
?>
Save the file and run it.
php hello.php
The output will be:
Hello, World!
Create a Local PHP Web Server
You can also use PHP to create a local web server directly in Termux for testing websites.
Create a project folder.
mkdir mywebsite
Move into the folder.
cd mywebsite
Create the main web page.
nano index.php
Add this code:
<?php
echo "<h1>Welcome to My PHP Website</h1>";
?>
Start the local server.
php -S localhost:8000
Open your browser and visit:
http://localhost:8000
You will see your PHP page running on Android.
PHP in Termux Overview
PHP is one of the most popular programming languages for web development. By installing PHP in Termux, you can practice different PHP commands, run scripts, and improve your programming skills on your Android device without needing a computer.



