PHP in Termux – Installation & Usage Commands

PHP is a popular server-side programming language used to create dynamic websites and web applications. It is widely used in web development because of its simplicity and compatibility with web servers like Apache and Nginx. You can easily install PHP and run PHP scripts directly on your Android device for learning and testing purposes. Here’s what you can do with PHP in Termux:

  • Run and test PHP scripts on your Android device.
  • Create dynamic websites and web applications.
  • Start a local PHP development server.
  • Practice backend web development without a PC.
  • Combine PHP with Nginx or Apache servers.
  • Learn PHP programming and server-side scripting.

Installation Commands

Update and upgrade packages.

pkg update && pkg upgrade

Install PHP in Termux.

pkg install php

Check PHP version.

php -v

Usage Commands

Run a PHP file.

php filename.php

Start PHP local server.

php -S 127.0.0.1:8080

Start PHP server on another port.

php -S 127.0.0.1:9090

Create a simple PHP file.

echo '<?php
echo "
<!DOCTYPE html>
<html lang=\"en\">
<head>
<meta charset=\"UTF-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">
<title>PHP Local Server</title>
<style>
*{
margin:0;
padding:0;
box-sizing:border-box;
font-family:Arial,sans-serif;
}

body{
background:#0f172a;
color:white;
display:flex;
justify-content:center;
align-items:center;
min-height:100vh;
padding:20px;
}

.container{
width:100%;
max-width:700px;
background:#111827;
border-radius:16px;
padding:30px;
box-shadow:0 0 20px rgba(0,0,0,0.4);
text-align:center;
}

h1{
font-size:2.2rem;
margin-bottom:15px;
color:#38bdf8;
}

p{
font-size:1rem;
line-height:1.7;
color:#d1d5db;
margin-bottom:20px;
}

.status{
display:inline-block;
padding:10px 20px;
background:#22c55e;
color:white;
border-radius:8px;
font-weight:bold;
margin-bottom:20px;
}

.info-box{
background:#1e293b;
padding:20px;
border-radius:12px;
text-align:left;
margin-top:20px;
}

.info-box h2{
margin-bottom:10px;
color:#facc15;
}

.info-box ul{
padding-left:20px;
color:#cbd5e1;
}

.footer{
margin-top:25px;
font-size:0.9rem;
color:#94a3b8;
}

code{
background:#0f172a;
padding:3px 8px;
border-radius:6px;
color:#38bdf8;
}
</style>
</head>
<body>

<div class=\"container\">
<h1>PHP Local Server Running</h1>

<div class=\"status\">Server Active</div>

<p>
Your PHP local server is successfully running on Termux.
You can now test PHP files, web projects, and practice web development directly on your Android device.
</p>

<div class=\"info-box\">
<h2>Server Information</h2>
<ul>
<li>Server: PHP Built-in Server</li>
<li>Host: <code>127.0.0.1</code></li>
<li>Port: <code>8080</code></li>
<li>Status: Running</li>
</ul>
</div>

<div class=\"footer\">
Created for PHP in Termux Learning & Testing
</div>
</div>

</body>
</html>
";
?>' > index.php

Run the created PHP file.

php test.php

Edit PHP file.

nano filename.php

Open PHP interactive shell.

php -a

Check loaded PHP modules.

php -m

Find PHP configuration file location.

php --ini

Show detailed PHP information.

php -i

Check PHP syntax errors in a file.

php -l filename.php

Run PHP script in background.

php filename.php &

Install PHP extensions.

pkg install php-apache php-fpm

Check installed PHP extensions.

php -m | sort

Create PHP info page.

echo "<?php phpinfo(); ?>" > info.php

Check which process is using port 8080.

lsof -i :8080

Open local PHP server in browser.

http://127.0.0.1:8080

Stop running PHP server or process.

pkill php

Stop PHP local server manually.

CTRL + C
READ ALSO  Termux Commands List - Latest | PDF | 2026

Leave a Comment