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.
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
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 127.0.0.1:8080).
pkg install php php-apache
According to archwiki page libphp7.so
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/mod_mpm_worker.so
- Add following line in the start of section with LoadModule instructions
LoadModule mpm_prefork_module libexec/apache2/mod_mpm_prefork.so
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/libphp7.so
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)
curl 127.0.0.1:8080/index.php
Hello,
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/libphp7.so into server: dlopen failed: library "/data/data/com.termux/files/usr/libexec/apache2/libphp7.so" not found
$ curl 127.0.0.1:8080/index.php
curl: (7) Failed to connect to 127.0.0.1 port 8080 after 3 ms: Couldn't connect to server