Tools for web development
moses.aboiyar / 02.08.2020

How to set up a Linux distribution on your mobile for Dev

You can have your Linux server on your phone for mobile web development. If you don't have a laptop no problem, your phone can be your local web server environment with Apache2, PHP MySQL, NodeJS and more.

There are apps out there with all this Apache2, PHP and MySQL installed, but you don't have total control. This solution will have you install two apps but it's totally worth it.

You need to have knowledge of the command line.

  1. Download Termux and Anlinux apps from Play Store.

  1. Open Termux and type the command apt update then apt upgrade if the previous command response was packages are available for update.
  2. Open Anlinux, tap on the menu and select 'Run with Root Permission' menu item then click on copy for the next command that will install 'tsu' so we can run our Linux as root user.

  1. Go back to Anlinux menu and tap 'Dashboard' 

Then tap 'Choose' to select a Linux distribution from the popular ones.

For the purpose of this guide, select 'Debian' then tap copy, open Termux, paste and tap enter. After the installation type ./start-debian.sh hit enter and you're now in your Debian desktop environment.

You have successfully installed Debian desktop environment on your phone. It is minimal and can only be accessed through command line but it will work all the wonders of a Debian server. Anytime you restart your phone you open Termux and type the command ./start-debian.sh and you have your Debian server running. You can now install Debian packages you want or need like a text editor, Apache2, PHP, MySQL  NodeJS and more.

​​​​​​Let's install vim as our text editors with the following command

apt install vim

You can learn more about using vim here.

Vim is to enable us edit configuration and web files.

Then we install our Apache2 web server with the command 

apt install apache2

On your mobile, Apache2 cannot listen on port 80, so you'll have to change its listening port to any desired port like 8080. You'll have to edit the ports.conf file found in /etc/apache2/ports.conf with vim that we installed earlier. Enter the command below 

vim /etc/apache2/ports.conf

The file looks like the one below, I changed my port to 9420

ports.conf file

You can start your server using the command

service apache2 start

Then open your browser and go to localhost:port, in my case it's localhost:9420 or 127.0.0.1:9420

Apache2 default page

Apache2 webroot on Linux or Debian based distributions like Ubuntu are found at /var/www/html/

Next we install a MySQL database. Let's install the MariaDB server by using the command

apt install mariadb-server

After the installation we start the database server 

service mysql start

And secure the database using the command below. If you don't start the database server, the next command will fail at password entry

mysql_secure_installation

You'll be asked to enter root password, you don't have any yet so you hit enter. Answer yes for setting root password and the rest of the questions and your database server is secured.

Then we install PHP using the command

apt install php

Which will install either PHP version 7.2 or 7.3, you can install other PHP versions later.

Next is composer so we can be creating projects from packages directly without having to download and unzip. 

apt install composer

Next is NodeJS and NPM (node package manager)

apt install nodejs npm

That's it with the basic setup. NodeJS, NPM, and composer are optional but as you grow your web dev skills, you'll need them.