Peter Elst

Flash Platform Consultant
  • Home
  • About me
  • Articles
  • Downloads
  • Contact me

iPod Touch - Apache and PHP 5.2.3

12 10 2007

When you’ve got Installer.app installed on your iPod Touch you’ll notice that it allows you to install Apache and a number of scripting languages (PHP, Perl, Python, Ruby).

That’s all well and good but getting it to run in on that local Apache install is another thing. Just managed to get it to work with PHP 5.2.3 so just follow along if you’re in the same situation:

1. Edit /etc/profile and update the line setting PATH to read as follows:

PATH="/bin:/sbin:/usr/bin:/usr/local/bin:/usr/sbin:/opt/iphone/bin"

2. Edit /etc/httpd/httpd.conf and add the following to the end of the file:

ScriptAlias /php /opt/iphone/bin
AddType application/x-httpd-php .php
Action application/x-httpd-php "/php/php-cgi"

2. Restart Apache by SSH’ing to the iPod Touch and running the following command:

apachectl restart

Now put your PHP files into the webroot (/Library/WebServer/Documents/) and access them by pointing Safari to http://127.0.0.1/<path_to_your_file>.php

I’m yet to try it with Perl and Ruby but that should just be a matter of adding another ScriptAlias to httpd.conf of your local Apache install. Enjoy!

« iPod Touch 1.1.1 opened up Bruce Chizen at Adobe MAX Chicago »



Actions

  • rss Comments rss
  • trackback Trackback

Informations

  • Date : 12 October 2007
  • Categories : General, Mac

53 responses to “iPod Touch - Apache and PHP 5.2.3”

15 10 2007
pekkis (21:34:42) :

Hi Peter,
I found your blog as I was searhing info to start PHP on iTouch. I did the things you said, but I couldn’t restart Apache with your command. Is it same if I reboot the iTouch?
I can’t get PHP working… :(

17 10 2007
D (13:45:13) :

Wicked! Exactly what I’ve been looking for! The iPod Touch and the iPhone must be the world’s sexiest portable web servers!

19 10 2007
remei (23:53:19) :

Thnx a lot! PHP on my iPhone is great. Now I’m working on an Liveblog for my Fon.

22 10 2007
Xypho (17:41:58) :

Hey thanks for this it really helped, I just installed Apache and PHP on my Ipod touch and it works great. I couldn’t get apache to restart so I did I reboot on the Ipod and that fixed the problem, later on going through the bins I noticed the last line “apachectr restart” should read “apachectl restart”

Thanks again! :)

23 10 2007
iPhone moblog (18:07:49) :

Thnx again! I use your introduction to build up my always-on-moblog under http://docpool.org/iphone. There is an addition to your setup: with the reverse ssh-tunnel you can hold your iPhone-server accessible even if you switch your network. It works fine for me in all networks Wifi or EDGE.

24 10 2007
Mit Blog: Webserver auf dem iPhone at iFUN.de/iPhone :: Alles zum iPhone (18:46:17) :

[...] euch hier eine Hand voll Tipps zum Aufsetzen eines eigenen iPhone-Webservers. Gerade die verlinkten Tipps zu PHP und dem, auch auf docpool eingesetzten, live-moblog sind gold- und natürlich auch [...]

31 10 2007
Ryan (00:26:25) :

Peter - thanks for the article, worked flawlessly on my touch.
Do you know how to get Perl working as well?

Thanks,
Ryan

6 11 2007
jj (22:43:14) :

Now if only someone could make a script linking to the ipods photo, and music library, i would make i extremely easy to share, i realize that the music part would be illegal to share, but all my purchased music wouldn’t play without my apple_id anyway so an easy, cool way to use do this would be awesome…

7 11 2007
Sam (00:19:59) :

Great Info!
Thanks

I am looking to configure ruby on ipHone Web Server as well please help.

thanks

13 11 2007
MEW (16:54:24) :

Great Info!
Thanks~!!!

13 11 2007
iPhone moblog (17:01:14) :

@jj: You only need an symbolic link from ~/Media… to /Library/WebServer/Documents/etc. Thats all.

14 11 2007
jj (05:58:19) :

except itunes won’t let me sync full size images to the iPhone, instead it uses
ithmb format.
see:
http://forums.ipodlounge.com/showthread.php?p=650968
and iTunes is also not so simple to link as iTunes also saves iTunes Music Library data file (in XML format)….

so a great deal of coding is needed…

15 11 2007
Leonardo (23:57:35) :

Is there any way to install MySQL in the iPod Touch or iPhone? I been searching some kind of clue but i found nothing. Perhaps someone knows how or can think how to install it. Thanks in advance.

17 11 2007
Leonardo (04:57:06) :

Hello. I’m having a problem when i’m not connected to the wireless network and only conected with edge. Perhaps is because i use the next file to get internet with edge:

function FindProxyForURL(url, host)
{
if (isInNet(myIpAddress(), “10.0.0.0″, “255.0.0.0″))
return “PROXY 200.40.246.2:3128″;
else
return “DIRECT”;
}

Please, can anybody help me with this? Thanks!

17 11 2007
iPhone moblog (17:02:54) :

@Leonardo: You mean, you like to use an automatical proxy configuration (PAC)? What is the problem exacly? Do you have access to a web page if you connected to edge or not?

17 11 2007
Leonardo (19:26:35) :

Thanks for your reply. Yes, that’s my proxy.pac file for browsing internet through the wap service. The thing is that when i’m in the edge network i get the 505 error when i want to access localhost and i think the problem could be because my proxy.pac config.

18 11 2007
iPhone moblog (01:54:56) :

@Leonardo: Ah! I’m not familiar with the PAC configuration, but I think you make a mistake in the if statement. This script says: if my adress is in local net, then use the proxy, otherwise request the page direct. What you like to have is: if the requested address in the local net, then go there direct, otherwise use the proxy 200.40.246.2:3128.

So, this probably will helps you:

function FindProxyForURL(url, host)
{
if (isInNet(myIpAddress(), “10.0.0.0″, “255.0.0.0″))
return “DIRECT”;
else
return “PROXY 200.40.246.2:3128″;
}

18 11 2007
Leonardo (18:36:39) :

Thanks again for your reply. I don’t know much what my config file means, but the thing is that it already works as i posted earlier. What i thought was that apache isn’t working because of the proxy config.

18 11 2007
iPhone moblog (19:29:31) :

@Leonordo: O.k. so you dont need more help? If you use an outside proxy, it is impossible to reach the web server local (on your iPod Touch or iPhone) running.

18 11 2007
Leonardo (22:01:30) :

That’s what i wanted to know, it’s impossible then. I thought it could be some extra coding in the config file so i could get to the local web server when i’m in the edge network; my mistake. Thanks for all.

19 11 2007
mls (00:05:12) :

There is rather huge problem with PHP on iPhone/iPod touch - bug in preg_replace function, which always returns empty string…

21 11 2007
Fransjo (02:24:13) :

Hello

I’ve got Apache and PHP working now, but where is php.ini located on the ipod Touch?

21 11 2007
iPhone moblog (02:30:13) :

There is no php.ini. But you can create one for yourself. In most cases it is more easy to set up the thinks you need in an included php file.

Do you use an reverse tunnel or dyndns, so that we can touch your touch?

21 11 2007
fransjo (02:33:38) :

hmmm ok … so like … you got one php.ini for me to start with hahaha?

“Do you use an reverse tunnel or dyndns” eh?

21 11 2007
iPhone moblog (02:59:33) :

Hey dude!

php.net says:

[ When php run as CGI ]
Place your php.ini file in the dir of your cgi’d php binary, in this case /cgi-bin/

21 11 2007
fransjo (03:04:00) :

hmm … well it turned out I had to place it in

/opt/iphone/lib/

I’ve written a little script to upload files to my iPod Touch and also download it from my iPod and of course delete them. This way I don’t have to open SSH ;-) … Well thnx for helping me ..

greets

21 11 2007
Leonardo (03:51:30) :

Fransjo, perhaps you should do some kind of tutorial to have the script you mention, it could really be useful :-).
Cheers.

21 11 2007
Illsley (23:20:31) :

I cant put my php files in the Documents folder! They all gets empty with filesize 0 when I upload them to the Touch, any ideas?

25 11 2007
Jonathan Furness (03:24:26) :

Hello Illsley

I’ve spent the last 2 hours trying to overcome this very problem with my iPod Touch. The error occurred whilst using SFTP - I used a few different clients, each with the same error.

I lacked information about the error, since the clients couldn’t report the exact error (sigh)

However, I have since discovered, the problem with uploading files is lack of available disk space on the Touch. I had to uninstall some packages to create room. What I’m not clear about is whether there is indeed a finite amount of space in the File System - perhaps this doesn’t extend to the 16GB? I see two partitions on the device, one 300MB and is full, and the other 15GB.

Does anyone know anything more about available disk space?

1 12 2007
wrs (09:35:21) :

Jonathan…

There are two partitions defined…
the 300 mb partition is where the OS lives…
the other 8+ gb is where your media usually goes…

unfortunately, the web root is inside the OS partition by default…

One way to get around this is to move your webroot to the media partition (/private/var),
then create a softlink to it from the original folder.

Something like this:

cd /Library
mv WebServer /private/var
ln -s WebServer /private/var/WebServer

I learned this trick from another forum for creating more room for your third party apps by moving the /Applications folder the same way…

Btw, my UNIX is a bit rusty now, so all you *nix gurus out there feel free to correct as needed…

1 12 2007
wrs (09:51:02) :

ok…correction to my last post…

The command for crating the symbolic link is actually as follows:

ln -s /private/var/WebServer WebServer

I had the arguments reversed before…this should be run from the /Library folder.

1 12 2007
Emile (10:10:25) :

Fransjo:

I am trying to do the same script to upload, deleted and download files but when uploading files I am getting 405 error: “The requested method POST is not allowed for the URL /upload.php.”

do you have any idea how to overcome this?

Thanks

18 12 2007
Garçon aka Martin Kopta » Blog Archive » links for 2007-12-17 (01:19:23) :

[...] Peter Elst » iPod Touch - Apache and PHP 5.2.3 When you’ve got Installer.app installed on your iPod Touch you’ll notice that it allows you to install Apache and a number of scripting languages (PHP, Perl, Python, Ruby). (tags: ipod iphone apache) [...]

19 12 2007
Apache and PHP 5.2.3 on iTouch? | David Bisset: Web Designer, Coder, Wordpress Guru (00:58:55) :

[...] Peter Elst shows how to get PHP 5.2.3 onto an iTouch. Do at your own risk, but bookmarking anyway. Looks like there’s a chance to get Perl, Python, Ruby, etc in your iTouch as well but would you really WANT to I wonder? Tags: Apache, iTouch, PHP [...]

2 01 2008
cgomez (03:54:55) :

Hi, may I ask you to write the example of what the scriptalias for perl should be?

I’d really appreciate it.

11 01 2008
Herve5 (23:08:05) :

php doesn’t install?
On my iTouch v1.2, where I already installed dozens of other packages (including Apache), the PHP install doesn’t go up to the end: download is OK, but then installation seems instant, there is no “cleaning up” phase, the iTouch doesn’t lock in the end, and in fact when I look again in installer.app installable packages PHP is still there (and nowhere in the “uninstall” section).
My interpretation is that there is a problem during this very precise installation process here. I suspected a lack of room on the touch (would this be explicitly stated?): I removed a big wedict dictionary, restarted the touch, retried: no way. I can install other packages, but not the php one.
What can I do?
is there some place where I could get php manually? (I fear there are lots of libraries?)
TIA!

12 01 2008
iPhone moblog (02:42:31) :

I think you have a problem with the space. In 1.1.2 they have limited the first partition. In /opt/iphone there is a lot of stuff if you install perl an php. There are some tipps on the net how to move the /Application folder and the /opt folder to /var/root and link the moved folder to the original locations.

12 01 2008
Herve5 (13:33:12) :

Thank you moblog!
I’m convinced too now -I just checked, thanks to your hint: the installer saturates /opt/iphone with just a 700K file and stops, and at this point the corresponding volume is filled. I’ll try the move you suggest.

btw, I’m quite impressed by your reactivity: this indeed is a sign a mobile blog is strikingly efficient!

Hervé

13 01 2008
Herve5 (12:20:40) :

… and yes it works :D

(I just moved /opt/iphone and created the associated link)

Thanks again!
Hervé

1 02 2008
dd (11:22:19) :

Hi,

damn I just upgraded to 1.1.3 with the installer and evrything work good so far, but
I havent deinstalled all apps befor upgrading. So I cannot start the apache because the httpd.conf file is missing, and I also cannot deinstall it, alway get this main script error.

How can I reset the installer.app config file to do clean installs?
thx

12 02 2008
hexcode (06:51:39) :

Ok, so any updates to this mighty fine post for us 1.1.3 users? As i see it /etc/profile isn’t there anymore… so no way to modify that file…

it worked on my 1.1.2 just fine but now my 1.1.3 is just a bit different.
any help would be appreciated, thanks

12 02 2008
David (14:16:57) :

@hexcode

I’m in the same boat (1.1.3) - I just created a file called “profile” in that location and copied the code from the top of that page into it. Next I restarted the phone for the changes to take affect - php seems to be working now.

13 02 2008
Vincent (16:40:39) :

Hmm, can’t get it to work on 1.1.3. I’ve did what you said but I just see the PHP code in Safari (as if PHP wasn’t installed). But I did! :o The strange this is, is that I had a profile file. I already tried it in 1.1.2 and it worked, but after my (Dev-Team)upgrade…

Any advice on this one?

6 03 2008
Joe (00:07:22) :

Hi,

I installed Apache and PHP on my iPod Touch, and modified the HTTP daemon config.
Apache runs well, but it doesn’t seem to recognize the PHP extension.
I also remarked that the alias /icons points to a folder that is not created on my iTouch : /usr/share/httpd/icons
Indeed, I don’t have a httpd folder under share !

I tried to uninstall / reinstall Apache, but still no httpd folder there…
Any ideas ? Or a listing of all the files installed by Apache, so that I can see what else is missing on my iPod…

Thanks !

6 03 2008
David (00:14:41) :

Hi Joe,

Can you try looking for the folder in /private/etc/ ?

Cheers
Davd

6 03 2008
Joe (02:11:44) :

David,

I’ve got an httpd folder in /private/etc , but it only contains 5 config files and no subfolder.

But I just saw that Apache’s error_log (in /private/var/log/httpd) kept increasing since I installed Apache, with the same errors every 10 seconds :

[Thu Mar 6 00:30:04 2008] [alert] httpd: Could not determine the server’s fully qualified domain name, using 127.0.0.1 for ServerName
[Thu Mar 6 00:30:04 2008] [crit] (48)Address already in use: make_sock: could not bind to port 80

So I stopped added a line in httpd.conf for ServerName (127.0.0.1), and the same in resolv.conf, and… now PHP seems to works !

But I still have the second error (port 80 already used)… So I checked the running processes, and I saw there was 3 instances of httpd : one was run by root user, and the 2 others by “nobody” !
I could kill both, but one keeps coming back (with a new PID) whenever I kill it !

According to my iPod’s Sysinfo app, the httpd run by user root uses /bin/sh as shell, but the one run by user “nobody” uses /usr/bin/false !

If I stop Apache with apachectl stop, the httpds keep coming back some seconds later…

There’s something I don’t understand here… It’s been many years since I last used as much Unix commands :-))

And I still don’t understand where’s Apache’s “icons” folder ! :-D

11 03 2008
Thomas (12:28:47) :

That works perfectly.

Does anyone know how to get SQLite 3 to work?
SQLite 2 is included, - but I really ned SQLite 3

7 04 2008
Ryan (21:32:32) :

Thank you very much — worked great!

10 04 2008
Ali (11:08:46) :

how to download PFP on iphone plz let me know and from wher i can downalod php

23 04 2008
@eventtrack » Blog Archive » iPod Touch and PHP native? (20:41:50) :

[...] out on my 8GB iPod Touch. I loaded both Apache and PHP on the iPod Touch, did a few edits (check here) and there you go PHP running on the iPod [...]

14 06 2008
shedali » Blog Archive » Home server (15:09:19) :

[...] 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 over your internet connection - [...]

5 07 2008
kyle (01:17:51) :

im on an ipod and can’t see all of what i need to put in the PATH. Can someone post a comment with it?

5 07 2008
kyle (01:39:44) :

never mind

Leave a comment

You can use these tags : <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>





Conferences

Flash on the Beach Speaker

Training Partners

multimediacollege

SkillsMatter

Badges

Alltop, confirmation that I kick ass

  • Categories

    • AIR RSS category feed
    • Ajax RSS category feed
    • CSS RSS category feed
    • Eclipse RSS category feed
    • Events RSS category feed
    • Flash RSS category feed
    • Flash Lite RSS category feed
    • Flex RSS category feed
    • Gadgets RSS category feed
    • General RSS category feed
    • JSFL RSS category feed
    • Mac RSS category feed
    • Open Source RSS category feed
    • PHP RSS category feed
    • Podcasts RSS category feed
    • Publications RSS category feed
    • Rants RSS category feed
    • Reviews RSS category feed
    • Thought of the Day RSS category feed
    • Training RSS category feed
    • Twitter RSS category feed
    • Video RSS category feed
  • Resources

    • Matthew David
    • Stefan Richter
    • Mario Klingemann
    • Chafic Kazoun
    • Sam Robbins
    • Rich Tretola
    • Jon Williams
    • Guy Watson
    • Scott Barnes
    • LordAlex Leon
    • Serge Jespers
    • Robert M. Hall
    • Marco Casario
    • Owen van Dijk
    • Josh Tynjala
    • Branden Hall
    • Jesse Warden
    • Edwin van Rijkom
    • Darron Schall
    • Peter Hall

     
     

    Adobe Community Expert

    See my profile on LinkedIn



    Harz Ferienwohnung Suchmaschinenoptimierung Geschenkideen Harz Ferienwohnung Pagerank Webkatalog Webhosting