• Home
  • blog
  • The Android Elephpant – Laravel on your Android Phone?

The Android Elephpant – Laravel on your Android Phone?

It was not that long ago that Christopher Pitt wrote an excellent article about writing and running PHP code on an iPad. After reading it, I thought to myself “It would be really cool to do the same on Android”: being able to write and edit code on the fly, for example while traveling, and not having to take the laptop everywhere. So I’ve decided to do some research and see what I could come up with.

Android Elephpant

For this article, you can use any type of Android device. I’ve done it on my phone, but an Android tablet with a Bluetooth keyboard would probably be the ideal setup.

There are a couple of different shell apps for Android. For this tutorial we will use one called Termux.


Termux combines both a powerful terminal emulation and an extensive Linux package collection. It is also completely free and easy to use.

After installing Termux from the Play Store, the first thing to do is to run the apt update command. As per the documentation: “This command needs to be run initially directly after installation and regularly afterwards to receive updates.”

Now for the fun part. The first two commands I want to talk about are the apt list and apt list --installed commands. The first one will list all the available packages for Termux. We can see that it has support for a lot of different programming languages, text editors and has some useful utility packages like zip, tar and so on. The second command will list all the installed packages. As we can see Termux already comes with some packages like apt and bash pre-installed.

My goal when testing Termux was to see if I could assemble a proper* PHP development environment, so I started by installing a text editor. I prefer Vim, but there are some more options available, like Emacs and Nano. Vim has a bit of a learning curve to it, but it gets very comfortable when you get past the basics of it. You can get Vim with the apt install vim command.

If you want to learn more about vim, there’s this very good article or, alternatively, after installing it, type vimtutor to use the built-in tutorial.

If you are testing this on your Android phone, running vim will bring the first set of problems. How can I hit the Escape button? Termux has a large list of shortcuts that be used to simulate the buttons that are not available on the Android keyboards:

Volume Up+EEscape key
Volume Up+TTab key
Volume Up+1F1 (and Volume Up+2 → F2, etc)
Volume Up+0F10
Volume Up+BAlt+B, back a word when using readline
Volume Up+FAlt+F, forward a word when using readline
Volume Up+XAlt+X
Volume Up+WUp arrow key
Volume Up+ALeft arrow key
Volume Up+SDown arrow key
Volume Up+DRight arrow key
Volume Up+L(the pipe character)
Volume Up+U_ (underscore)
Volume Up+PPage Up
Volume Up+NPage Down
Volume Up+.Ctrl+ (SIGQUIT)
Volume Up+VShow the volume control

Now that we have our editor up and running, it’s time to install the packages we’ll need: PHP, Git and Composer.

apt install php
apt install git

This will install the latest PHP and Git packages.


For Composer, we need to do a little bit of extra work. We need to go to the Composer download page and use the instructions for the command line installation:

php -r "copy('', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '55d6ead61b29c7bdee5cccfb50076874187bd9f21f65d8991d46ec5cc90518f447387fb9f76ebae1fbbacf329e583e30') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

This will download the installer, verify it, run it and delete it. If everything went well, we should be able to run Composer from Termux.


Now that we have all of our tools installed, we should test if our PHP installation is running correctly. For that, let’s do a simple phpinfo() test. Let’s create a new folder and test our PHP installation.

mkdir test
cd test
echo "<?php phpinfo();" > index.php
php -S localhost:8080

This will create a new folder and then create an index.php file with the phpinfo() command inside of it. I’m echoing it directly into the file, but you can use Vim to do it. Finally, we are using the PHP server to serve it to our localhost. When accessing localhost:8080 in our browser we should see something like this:


We now have Composer for dependency management, and git for version control. But I know what you’re thinking: “we just made a simple phpinfo test, what about the rest?”.

Continue reading %The Android Elephpant – Laravel on your Android Phone?%