INSTALL PHP IN TERMUX
Introduction
Termux is a
powerful terminal emulator for Android that provides a Linux-like environment
without requiring root access.
It allows users to run various Linux commands, install packages, and even
develop web applications using programming languages like PHP.
In this guide, we will explore how to install PHP in Termux, create and run PHP
files, and even serve HTML pages using PHP s built-in server.
This is perfect for those who want to develop and test PHP scripts on their
Android devices.
Step 1: Install
Termux
Before installing
PHP, you need to have Termux installed on your Android device.
Download and Install Termux
Before installing PHP, you need to have Termux installed on your Android device.
1. Open the
Google Play Store or an alternative store like F-Droid.
2. Search for Termux and install it.
3. Open the app, and you will see a terminal interface.
Step 2:
Update Termux Packages
Before installing PHP, it
is recommended to update Termux s package list to ensure you get the latest
versions of software.
Run the following command in Termux:
pkg update && pkg upgrade -y
- `pkg update` updates the package
lists.
- `pkg upgrade -y` upgrades all installed
packages.
Step 3: Install PHP in
Termux
Once Termux is updated, you
can install PHP by running:
pkg install php -y
This command:
- Downloads and installs PHP in Termux.
- Installs necessary dependencies required to run PHP scripts.
After installation, you can check if PHP is installed by running:
php -v
If PHP is installed correctly, you will see output displaying the PHP
version.
Step 4: Creating and
Running a PHP File
Creating a Simple PHP File
Now that PHP is installed, let's create a simple PHP script.
Use the nano text editor to create a new PHP file:
nano index.php
2. Type the following PHP code:
php
<?php
echo "Hello, Termux!";
?>
3. Save the file by pressing CTRL + X, then Y, and finally Enter.
Running the PHP File
To execute the PHP file, run:
php index.php
You should see the following output:
Hello, Termux!
Step 5: Running a
Local PHP Server
PHP comes with a built-in
development server, which allows you to serve HTML and PHP files as a local
website.
To start a server in Termux, use:
php -S localhost:8080
Now, open your mobile browser and visit: `http://localhost:8080`.
Step 6: Running an
HTML File in Termux
1. Use nano to create an
HTML file:
nano
index.html
2. Click The PDF Download Button To HTML Code:
3. Save the file and access `http://localhost:8080/index.html` in your browser.
Step 7: Running PHP
and HTML Together
Place both `index.php` and
`index.html` in the same directory and start the PHP server.
Then, visit:
- `http://localhost:8080/index.html` (for HTML file).
- `http://localhost:8080/index.php` (for PHP file).
Step 8: Additional PHP
Features in Termux
Installing Additional PHP
Modules
Install additional PHP modules using:
pkg install php-gd php-curl php-mbstring php-xml
-y
Checking Installed PHP Modules
To check which PHP modules are installed, run:
php -m
Step 9: Running a PHP
Framework in Termux
Installing Composer
pkg install composer -y
Now, you can install and use Laravel, CodeIgniter, or other PHP frameworks in
Termux.
Step 10:
Stopping the PHP Server
To stop the running PHP
server in Termux:
- Press CTRL + C in the Termux
terminal.
Conclusion
By following this guide, you have successfully:
Installed PHP in Termux.
Created and executed PHP scripts.
Served HTML and PHP files using PHP s built-in web server.
Installed additional PHP modules.
Learned how to manage PHP frameworks like Laravel.
With Termux, you can now develop and test PHP applications directly on your
Android device.