An iPhone Powered Apache Web Server with PHP
A week or so ago, I went ahead and decided to do my “first” hacking of the iPhone. I went to the JailBreakMe.com website and followed the simple instructions and the Installer.app which is basically a “one touch” utility to install 3rd party apps and Linux ports such as PICO and a terminal program.
I was a bit surprised to find a port of Apache 1.3.37 and PHP 5.2.3 in the repository, so I went ahead, installed them both and with a little configuration using PICO (after installing and logging in through SSH), got a functional webserver with PHP support.
I created a PHPINFO() page which shows the extensions that are activated by default, which are pretty much just the core PHP functions and started thinking what to do with it…
Of course I could use it for impromptu testing of code from anywhere, showing simple mockups offline to clients one-on-one, and other things like that, but it wasn’t enough for me…
I put the thoughts on the backburner for a few days, last night I figured I’d try something new.
Here goes…
Apache/PHP was working so I decided to go ahead and copy a full PHP site with full graphics and a PHPMail script on it.
To get this all over to the phone, I TARred up just the most necessary files, filtering out anything not directly referenced (limited amount of memory on the phone for this type of stuff).
Then I FTP’ed, using NCFTP installed from the Installer.App repository, into the machine that had the TAR, downloaded and unTARred it into Apache’s document folder (/Library/WebServer/Documents).
At that point, once all the files were in the correct place and so forth, I hit the website directly on the phone (http://127.0.0.1) and it came right up and was rather speedy. I then hit it from a workstation on the same WiFi network using the DHCP assigned IP and it came up perfectly.
Ok, so far so good, the website comes up just fine locally and remotely, lets take it a few steps further.
I decided to, from work today, to VPN using PPTP built into the iPhone into my DD-WRT router at home (It has a static IP) and then proceed to port forward port 80 from the external IP to the Internally assigned VPN IP of the iPhone. Then I proceed to add a DNS entry for it…
I also VPNed into the DD-WRT over EDGE and it worked just fine as well. Of course it was MUCH slower, but still worked fine.
It really was this easy to do something that I don’t think has ever been done before with a cellphone.
NOTE: Apache was setup to just start 1 httpd instance and I believe a max of 7, which slowed stuff down a lot with a graphical site, so I set it from 1 to 10.
If anyone has questions, feel free to leave a comment and I’ll reply as soon as I can.
thanks for the tips, got it working on my iPod Touch
any idea why “preg_replace” is not working?? Always returns null string…
$str = “this is a test”;
$str = preg_replace( ‘/is/’, “is not”, $str );
print $str;
I haven’t used preg_replace, so I’m not sure. I know at my day job last week, I was trying to use the “gregoriantojd” function and it just WOULD NOT work. After a bit of research, the calendar functions ended up not being compiled into PHP. After a quick recompile, it worked fine. Might be a similar issue.
I know the Apache/PHP for the iPhones is pretty minimal feature-wise.
The regexp functions are pretty basic, however. If I give bad parameters for the function, it complains as it should, implying that the function really is there… just not working. There’s probably a compile time setting that is set differently from all of the other installs of PHP that I’ve tried this on.
hello im using dd-wrt im wondering if u can make howto how to setup vpn on iphone and settings on dd-wrt.. or if u can email the settings so i can setup my
Can you please tell me how you configured PHP in the httpd.conf? i didnĀ“t get it working, always getting Internal Server Error…heres my config from now:
Options ExecCGI
AllowOverride None
ScriptAlias / /opt/iphone/bin/
Action php-script /php
AddHandler php-script .php
I stupidly upgraded to 1.1.2 and my phone is wiped… It wasn’t that hard though, it’s all out there on the net, just google around. I’m sure you found my site with Google, you’ll find a more detailed instructional elsewhere I’m sure…
Thanks for the visit to the site though.
Is there any way to run Mysql server on IPHONE?
I don’t think MySQL has been ported yet, although It would be nice…
I am trying to set up PHP and Apache on my Ipod Touch. I have the apache working, but I do not know where to set up the PHP. I get a “Method not allowed” error when I submit a form through POST to a PHP page.
I installed SSHD onto my phone and SSHed into it and followed instructions posted on other websites…
There is a little configuration that has to be done to get Apache and PHP working together nicely…
Sorry I can’t be of more help, but it’s been a while since I did this and since then I’ve upgraded to 1.1.4 and am no longer jailbroken.
Good luck.
How do I make my iphone without cell service into a wifi web server?
You can Google around about activating it without service, then you only need to JailBreak it (again Google), and install the Apache web server using the installer.app … As stated above, it is good to install the SSH Daemon on it to configure it.
Hi
I tried to install Apache and PHP on my iPhone using installer/app but they were not there.
I knew they were supposed to be in network and development but I didn’t find them. Any idea?
Thats superb, you can essentially take a portable web server anywhere! Or if you were a chef could have a mysql databse of recipes and carry them around in your pocket!
[...] with a computer can run an apache server and serve up web pages. In fact, anyone with an ipod touch or iphone can do the same! even with php which opens the way for people to serve up dodgy content [...]
I wish there was a light weight MySQL for the iPhone. (I haven’t looked lately) It would definitely open the door for a really cool apps. I believe SQLite is already on the phone, but that’s a big learning curve for those of us who are most used to MySQL. Of course you can just simply write a remote app to access it via EDGE or WiFi.
I have written a small online iPhone app for Real Estate Agents/Brokers that I’m tweaking for public use.
I tried to install the tiff from jailbeakme site, the safari just frozen and one question mark appear, then I use desktop browser to link the file url, it is /files/y.tiff, my antivirus software report backdoor alert.
Dude, this article is way old… JailBreakMe.com I don’t think works anymore for any of the new versions of the iPhone. I haven’t used it since version 1.1.1 and now we are on 2.1
The method used to originally jail break the phone was a “malformed” TIFF file that IS technically a “backdoor” into the phone. That’s why it got flagged in your AV program.
Google around elsewhere and you’ll find the current software used to Jailbreak iPhones.
Hi,
I have ipod touch (2.1) and I have jailbroken it (using quickpwn).
I want to install apache and php on the device, but i cannot find the packages in the installer (i am using installer 4 beta).
I have tried to add several other repos in the sources, but havent been able to find the packages in any of them.
What should I do?
Can anyone tell me some repo which has those packages, so that i can add it.
thanks & regards,
[...] de lighttpd aan de praat te krijgen maar snap nix van de configuratie nodig om e.e.a. te starten. Hier staat een handleiding voor een apache install maar die werkt (volgens mij) alleen op pre 2.1 [...]
Just wanted to add that Pocket PC (Windows Mobile) 2002 Phones could use a Microsoft made HTTPD server software from the SDK that supported ASP server-side scripting and ADOCE database access..and that was way back in 2001, 7 years ago ;)
Hi All,
novemberbrain27:
I’ve got the same problem - where the hell is Apache or PHP?, I’m using Installer 4.0b10-3 and can’t find them anywhere!
I did find and install Lighttpd however and after a lot of fu%&!^*ing around I have managed to get that working. Now if only I can get PHP & SQLite cranking!
If anybody knows how to install php onto IPhone without all the compiling stuff, or the whereabouts of PHP in Installer or Cydia, could you please let us wannabe hackers know!
YesWeCan:
I hava HTC Universal now running Windows Mobile 6.1. I agree with you wholeheartedly - I’ve have Microsoft HTTPD serving up asp pages connected to pocket access databases & PocketHPH running php pages connected to sqlite databases - been doing so for a number of years now!
Come on IPhone, pull your finger out! You have the hardware/OS to do it!, Steve Jobs, what’s with the lame Bluetooth support!
Many thanks to all you hard working developers, jailbreak app makers & 3rd party repomen!