How to Run a Simple Web Server on iPad or iPhone
Want to run a simple web server off of an iPad or iPhone? If you have iSH linux shell running in iOS then you can easily start and run a simple web server directly from an iPhone or iPad. By running iSH and starting a web server with python 3 you can then serve either HTML files or a directory listing to the same device via localhost, or to anyone on the same network with the iOS devices IP address. This is obviously not going to be as fully functional or featured as running apache or nginx, but if you want to geek around with a simple local html development environment or serve something via http from an iPhone or iPad, it’ll do the trick. Plus, it’s just plain cool.
How to Run a Web Server on iOS with iSH and python
- Install iSH on the iPhone or iPad as directed here if you haven’t done so already, otherwise launch iSH
- At the iSH command line in iOS, enter the following syntax and hit return:
- When you see the ‘Serving HTTP on 0.0.0.0 port 8000’ message, now you’re ready to connect the web server from either the same device or another:
- To connect to the iOS web server from the same device (localhost), point any web browser to:
- To connect to the iOS web server from another device on the same network, point any web browser to:
python3 -m http.server
http://127.0.0.1:8000
http://DEVICE-IP-ADDRESS:8000
Replacing ‘DEVICE-IP-ADDRESS’ with the IP address of the device running iSH and the python web server, you can find the iOS devices IP address in Network Settings if needed. (Example screenshot shows the iOS device IP of 192.168.1.10)
Pretty cool, right?
You’ll probably want to put some basic index.html file at the present working directory where you’re running the python server from. If you don’t have a simple index.html file in the current working directory on the iOS device where the python command is being run, then a simple directory listing is shown instead.
While the simple web server is running, you’ll see standard logging information appear in the iSH terminal window, showing access times, dates, IP addresses, GET and PUSH requests, 404 errors, and other typical access log information.
We’re obviously going with the python3 web server command here, but you can also use the Python 2 instant web server if you’d prefer, since both python2 and python3 are available on iSH.
Anyway, while the isn’t a particularly practical solution to web hosting or web development and you likely won’t be using this for anything too serious, it’s still fun and interesting as a proof of concept for us geekier folks. Perhaps one day we’ll get some easy web server setup in the iOS world like MAMP for Mac, but until then the solutions are fairly limited and most web workers and developers will continue to be using ssh to connect to a web server for the time being.
If you know of any other interesting or geeky solutions for setting up a web server or web sharing natively with an iOS device, share with us in the comments!
Very cool! Thanks. One issue: the server (python3) is running on my iPad – because I can successfully access it from other household computers. However, I can’t access it from the iPad itself where it is running.
http://127.0.0.1:8000 < local host (iPad)
http://192.168.1.14:8000 < from other computers
Ideas?
How to do in other way? I put python server on PC and I want to download something from it into iPhone.
cURL -O ? wget ?
And where is home directories when using iSH or a-shell or other iOs terminal?
Is it even possible?
Useless. Why? Because there is no Ctrl on the iOS keyboard, and your app does not provide a Ctrl key either.
Great…. ^^
For anyone that is stuck with this issue, the ctrl key access is provided by the second button in from the left on top row of the iSH keyboard, it looks likes a ^. To get for example ctrl+c to stop the webserver, all that has to be done is press that button and then c . This will do the same as pressing ctrl+c on a physical keyboard and stop the server.
Hope this helps!
You have to instal Python3
Apk add python3
And then install the server
Unfortunately, when I ran python3 -m http.server I got a python3: not found message. Any thoughts?
Try to install again, worked for me
In order to access it from a WAN i believe that you should open the port in your home router, while it’s difficult to open the same port if you were on 3g/4g env.
This is a fast comment as i’m searching for a solution to my problem
Have a good day
I’ve tested and it’s working fine when accessing the web server within LAN but not from WAN (Internet). What do I need to do in order to allow the web server to be access via WAN?
Thank you for this tutorial.
I like this a lot!
Question 1: How safe is this? I would like to try this, but without someone getting access to my phone’s gallery, messages, email etc.
Question 2: Would it be possible to put .jpg files stored on the same iphone on the website?
Question 3: Could you host a custom domain name in this way? Xyz.com, instead of the ip
Withing 2 minutes of trying this, my IDS software picked up IP’s from Russia and China trying to hack it!
This is fascinating but what I would really like would be a full LAMP and LEMP setup contained within an app on iPad and iPhone. MAMP for Mac is similar.
Geekatude score? 10!
WOW, this is very cool. Is there any way to link or access filed stored in icloud, google drive etc from the command line?
Very cool! And ‘app add nano’ gets you and easier to use editor than ‘ed’.
My iPad may now get more traffic than osxdaily.com!! 🤡