Skip to content

Instantly share code, notes, and snippets.

Last active March 27, 2024 18:18
Show Gist options
  • Star 37 You must be signed in to star a gist
  • Fork 10 You must be signed in to fork a gist
  • Save vilkoz/73588f8a7b9122a93c369502d61fd922 to your computer and use it in GitHub Desktop.
Save vilkoz/73588f8a7b9122a93c369502d61fd922 to your computer and use it in GitHub Desktop.
setup http server on android with termux

Setting up http server on android with termux

Setting SSH server

To be able to make all procedures without pain you should have physical keyboard or just install ssh server and connect to your device shell from computer.

Folow this guide to setup ssh server.

Installing needed stuff

As bunch of utilites that you can expect in general linux distro is not preinstalled with termux you need to do following:

Update packages

pkg update
pkg upgrade

And install following (that will take ~250Mb):

pkg install autoconf automake bison bzip2 clang cmake coreutils diffutils flex gawk git grep gzip libtool make patch perl sed silversearcher-ag tar

Installing and configuring apache2

In this and further steps you will need to acces the /etc folder, but in termux it is hidden in /data/data/com.termux/files/usr/etc/, so I suggest you to make link.

ln -s /data/data/com.termux/files/usr/etc/ ~/etc

Install is a simple part

pkg install apache2

You can configure it if you need in ~/etc/apache2/httpd.conf.

Now you can run apache2 server by simple httpd (by default it will run on

Installing php

pkg install php php-apache

According to archwiki page included with php-apache will only work with mod_mpm_prefork.

  • In ~/etc/apache2/httpd.conf comment following line:
#LoadModule mpm_worker_module libexec/apache2/
  • Add following line in the start of section with LoadModule instructions
LoadModule mpm_prefork_module libexec/apache2/

To enable PHP, add these lines to ~/etc/apache2/httpd.conf:

  • Place this at the end of the LoadModule list:
LoadModule php7_module libexec/apache2/
AddHandler php7-script .php
  • Place this at the end of the Include list (this will be at the end of file):
Include etc/apache2/extra/php7_module.conf

That file doesn't exist yet, so just create empty file, to load apache2 properly touch ~/etc/apache2/extra/php7_module.conf

To test if php works:

  • Create index.php file with arbitrary content
echo "<?php phpinfo();?>" > ~/../usr/share/apache2/default-site/htdocs/index.php
  • Restart apache2 server
killall httpd; httpd
  • Verify PHP output (you will need to install curl, if you haven't already)
Copy link

Me pasa lo mismo el archivo libphp7 no existe

Copy link

Luis-Licea commented Aug 21, 2021

I did not have, so I followed the instructions according to what @hisyamzayd wrote.

However, I ran into two errors.

  • I needed to manually run touch data/data/com.termux/files/usr/etc/apache2/extra/php_module.conf to create the file.

  • I also got an error about a corrupted file, so I removed it using rm /data/data/com.termux/files/usr/var/run/apache2/

  • Trying to restart apachectl and httpd manually did not work. Everything worked after I restarted tmux.

Copy link

awencheww commented Sep 14, 2021

My error is that any ".php" file saved to "htdocs" folder does not recognized as php script. It is plain text or html.
I follow this instruction above
and modify with this comment by
but except for this line -> AddHandler php-script.php
It shows an error that AddHandler needs two argument and the correct is
-> AddHandler php-script .php
Correct Syntax: AddHandler handler-name extension [extension] ...

AddHandler cgi-script .cgi
AddHandler php-script .php

More details here
-> Apache Module mod_mime

Copy link

motebaya commented Jul 27, 2022

nice sir, but where i can write .htaccess file for setup every my site folder? . bcause i only find one configuration file on dir


i try write a .htaccess file and save it to this.


but it's not working.

Copy link

CelestialReaver commented Aug 25, 2022

Do this for the install:

pkg install php7-apache

That will install php7 and modules for Apache.

Besides that, instructions work for me.

Copy link

IPTRAIN commented Feb 13, 2023

~ $ pkg install php7-apache
Checking availability of current mirror:
[*] ok
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package php7-apache

:-( 1:

Many thanx to [redfox805] php (instead php7) works!

Copy link

I installed Termux on a tablet because I'm taking a course on Linux system administration at Open classroom. I wanted to have a terminal to follow this course.
The problem I encountered was the following errors:

$ touch ~/etc/apache2/extra/php7_module.conf
$ echo "<?php phpinfo();?>" > ~/../usr/share/apache2/default-site/htdocs/index.php
$ killall httpd; httpd
httpd: no process found
httpd: Syntax error on line 66 of /data/data/com.termux/files/usr/etc/apache2/httpd.conf: Cannot load libexec/apache2/ into server: dlopen failed: library "/data/data/com.termux/files/usr/libexec/apache2/" not found
$ curl
curl: (7) Failed to connect to port 8080 after 3 ms: Couldn't connect to server

Copy link

Screenshot_2023-12-12-12-13-58-571_com termux-edit

Copy link

BlockSats commented Dec 12, 2023

I didn't put it at the end, does it really matter?

Screenshot_2023-12-12-12-16-00-897_com termux-edit

Copy link

Normally I think I've done everything correctly

Copy link

BlockSats commented Dec 12, 2023

I made this change :

LoadModule php7_module libexec/apache2/

AddHandler php7-script.php

LoadModule php_module libexec/apache2/

AddHandler php-script.php

And now I have :
$ echo "<?php phpinfo();?>" > ~/../usr/share/apache2/default-site/htdocs/index.php
`$ killall httpd; httpd`

httpd: no process found
AH00534: httpd: Configuration error: No MPM loaded.

Copy link

vikramisdev commented Feb 13, 2024

Hellooo, i just follow exactly as what this instruction said and unfortunately there is some few errors and i just fix it. I ask permission to give the solution through this comment 🙏

First, change

LoadModule php7_module libexec/apache2/

AddHandler php7-script.php


LoadModule php_module libexec/apache2/

AddHandler php-script.php

Second, change




I did this because is not existed and i try with existing file

it worked, but it shows the php content in plain text format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment