How I Set up Apache2 Web Server with Termux on Android

Photo by Daniel Korpai on Unsplash

Last week, I encountered some issues with my PC and had to do updates and in between this period was a lot of time wastage. In times like this, I reveled having that option that permits me to keep working while waiting. That it would enable me to continue other technical works whilst my PC does it regular upgrades. I quickly turned to Google.com to search for a solution. And I did find out that I could actually use my phone and this solution came up, use Termux, and Anlinux.

Termux, and Anlinux, provides you with an active Linux distro that runs from your mobile Android device. Incredibly, this presents a lot of useful possibilities, or so I learnt. It enables you somehow to keep up with the dynamics of being a developer these days.

So here in this personal documentation I would be sharing with you how to set it all up.

Here is how I setup up Apache2 HTTP Server on my mobile device:

Difficulty:

Medium (Not that hard for a Linux user)

Requirement

  • An Android platform newer than version 4.4/kitkat
  • Ability to Tether Wi-Fi Hotspot / be connected on same Wi-Fi as client PC or another Android
  • Internet connection on your Android Device
  • Termux app installed
  • Anlinux app Installed ( i.e. has termux as it key dependency)

Install Termux

Install Termux from google playstore

Open Termux

Open Termux and allow it to automatically install it core packages then allow necessary permissions

Notice : The Termux shell, looks quite similar to what you would have on Linux.

Hint: Termux packages are obtained and installed by

pkg install <package_name>

Install Anlinux ( Free / Donation-ware)

Anlinux is needed because it provides you the possibility of having a remote Desktop Environment through VNC Server. Although a Desktop Environment is optional if you are OK with just using Linux from the the terminal or CLI.

Install Anlinux from google playstore

Open Anlinux App

In all cases you will copy a “wget” command string , launch termux and paste the string and hit enter to download and install a package

  • Click to open the side-menu within the Termux app and scroll up to choose ` Dashboard`.
  • A new screen will open, look through and choose from there your preferred distro on Linux by the instructions within (Recommended you choose Ubuntu)

Copy the string to clipboard and launch Termux, paste the string into the Termux terminal and hit enter.

You would be prompted to start Linux Ubuntu after a success like this

$ ./start-ubuntu.sh

Install SSH

You may get back to Anlinux app again by hitting the home key on your phone and opening Anlinux one more time. -Similarly, you may choose SSH from the side menu

  • Copy wget string to clipboard
  • Launch Termux and paste and hit enter
  • At this point Ubuntu File System and Ubuntu kernel is installed on top of Termux, within Android file system.
  • As earlier mentioned you may enter into Ubuntu ,(if you’ve forgotten) 🙂 from Termux shell like, $ ./start-ubuntu.sh

Setting Apache2 HTTP Server

Now that we have setup Ubuntu Linux on Termux, for a clear clean start, clear screen or exit all sessions of previous activities

  • Start termux anew, then enter $ ./start-ubuntu.sh to enter into Ubuntu shell.
  • Use apt to install Apache2 like

root@localhost#: apt-get install -y apache2

  • Try to start apache2 like this

root@localhost#: apachectl start

  • Open a browser from your phone or any other device on the same network as you are , provided you know the IP distributed to your phone, you should browse tohttp://127.0.0.1:8080on same mobile phone and http://192.168.1.13:8080 on PC.
  • Note that your case might be different for the IP address to use when on PC.
  • It should show you the default Ubuntu’s Apache web server page or “It works”. ( It may work right off the bat, but if it doesn’t the next steps would be absolutely necessary)

Common issue

Should you find yourself receiving any errors from starting Apache Server you would need to do the following:

Next Steps

  • You would need to explicitly set ServerName for which you would need to have nano installed first to be able to open files in the next operation
  • Go ahead to install nano like this whilst still in Ubuntu sh, root@localhost#: apt-get install nano
  • Now you would need to nano into root@localhost#: nano /etc/apache2/apache2.conf and scroll down to where its commented Global Configuration and place below there ServerName localhost press ctrl +X to exit, and Y to save changes.
  • Secondly, you may want to make sure no android app is using port :8080, so go ahead audit your apps 🙂
  • If you still have issues, you may want to make a few changes to /etc/apache2/sites-available/000-default-site.conf Again root@localhost#: nano etc/apache2/sites-available/000-default-site.conf

Conclusion

The cool part is that you do not need to root your android device to be able to do any of this operations. Further more you can go ahead to install flask or django , php and wordpress, do Nodejs projects right from your mobile device. It’s also cool if you have Putty installed on your Windows PC, you could work right from your mobile device without running any Ubuntu distro, Emulator or Virtual machine on your PC.


You can take your projects with you everywhere you go, and it all stay comfy in your pocket. How cool could this be? 🙂

I hope you found this useful, do give it many claps, and do let me know if you were able to do this, if there is anything I can help with.

Updates

I may visit this article to make updates from time to time. Maybe to make it clearer if it isn’t now, would be happy to receive a feed back from you, and you may DM @huffypiet on twitter

Enjoy, keep on hacking! 🙂


Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *