Have you ever wanted to create your own portable server? Whether you’re learning web development and want to host your own HTML files on your iPhone, or whether you just want to play around with a server without being restricted to using a laptop or a computer to install MAMP, your iPhone can do it for you. So, if this is something you’re interested in, we’ve got you covered with all the important information you’ll need. Here is how you can run a simple web server on iPhone.
Run a Simple Web Server on iPhone and iPad
Running a server on your iPhone isn’t a difficult job at all. In fact, it’s really quite straightforward. All you need is a simple, free app, and that’s pretty much it. Obviously, since this is a simple web server, it won’t have all the bells and whistles you’ll get with something like a XAMP or MAMP installation on your laptop or PC. However, it can do the basics and do it well. So, let’s jump right in.
As always, you can use the table of contents below to navigate through this article.
Requirements for Running a Web Server on iPhone
Apart from an iPhone, all you need to run a web server, is a Linux shell environment. There are a couple you can use, but we are going to use the iSH Shell app (free).
Create a Simple Web Server on iPhone with iSH Shell
- First, install the iSH Shell app (free) on your iPhone and launch the app.
- Now, we will install Python 3 on the iPhone via the shell. Just type in the command mentioned below.
apk add python3
- Once Python 3 is installed on your iPhone, you’re ready to create the server. Enter the command given below to start a web server on your iPhone.
python3 -m http.server
- Next, you should see the “Serving HTTP on 0.0.0.0 port 8000” message at the bottom. Besides, you will also get a popup saying something like, “iSH would like to find and connect to devices on your local network. This is required for connecting to localhost and using the ping command” Tap OK in the popup menu to proceed.
- Next up, you can connect the web server from either the same device or another. If you want to connect to the iOS/iPadOS web server from the same device (localhost), just point any web browser to the following address.
- In order to connect to the iOS/iPadOS web server from another device on the same network, point any web server to the below address.
Note: In the command above, you will have to replace “device-ip-address” with the IP address of your iPhone. You can find your iPhone’s IP address by heading to Settings -> WiFi -> Tap on your WiFi name -> IP Address.
How to Add Your HTML Files to Your iPhone Server
Now that we’ve created a server, you may be wondering where and how to add your HTML files, right? Well that’s easy as well. Just follow the steps below.
Note: We are assuming you already have created the HTML file you want to serve through your iPhone’s web server. If you haven’t you can create an HTML file on your Mac or PC and then follow the steps below.
- On your iPhone, launch the Files app. Tap on the three dot icon on the top-right and tap on ‘Edit’.
- Enable the toggle next to iSH, and then tap on ‘Done’.
- From your Mac (or PC), send the file to your iPhone and place it within iSH -> root.
Note: The file should be called index.html.
Now, you can visit the IP address “http://iphone-ip-address:8000” from another device connected to the same WiFi network and your HTML file will be displayed.
How to Stop Your iPhone Server
Once you’re done using your iPhone for creating the server, and playing around with HTML files in it, you should also stop the server. Fortunately, doing that is very simple. Here’s how.
- In the iSH Shell app where the server is running, tap on the control icon (up arrow) in the toolbar. Then, press ‘Z’ on the keyboard.
- That’s it, iSH Shell will inform you that the server has been stopped.
Run a Web Server on iPhone with iSH and Python
Well, that’s how you can create your own simple web server on your iPhone, place your custom HTML files on your iPhone, and visit them from other devices on the network. To be fair, you can start port-forwarding from your router for your iPhone’s IP address and access your server from outside your local network as well, but that’s beyond the scope of this article. Plus, it opens up your network to unwanted access, so make sure you only do that if you know what you’re getting into. That said, what do you think about running a web server on iPhone? Let us know in the comments below.