constant stream of curated content
 Array
(
    [id] => u9Tm
    [id_url] => 
    [cat_id] => kwgM
    [user_id] => seb
    [date] => 2012-07-19 04:52:00
    [kind] => memo
    [access] => 9
    [title] => Setup your AppleTV 2 as a webserver
    [content] => The Apple TV 2 is probably the Apple product which has the most potential for customization.

A product who operate with flash memory, always powered on, and always connected, with an unix based os: it was tempting to turn it to a web server... and the results are quite impressive.

Firstly, it is obviously necessary to jailbreak the Apple TV, using Seas0npass (evasi0n can also do that). Please note that if you have an Apple TV 3, it is not possible to jailbreak it, you can stop reading this post here.

Then (and this is a bit off topic), I advise you to install ATV Flash Black, which is usually free (unless you go to a well known bay located in Sweden). This wonderful package will install you on the home screen a Media application, which lets you watch all movie formats via afp and smb shares.

This is obviously much more clean than installing this disgusting crap of XBMC. After all, you do not buy an Apple TV for a rotten interface running on a buggy and painfully slow software, isn't it?

Well, the bracket is closed, we are ready, your Apple TV 2 is jailbroken, ssh access is operational and you know its IP address (if not, go to settings> network).

Do not be fooled by the length of this tutorial, it will only take 20 minutes.

[size=1.5] 1 - Secure SSH a minimum [/size]

Like all iThings, the passwords of the two users [b]root[/b] and [b]mobile[/b] are set to "alpine". We cannot leave it like that.

So, on your computer in your favorite ssh console, type:
[pre]ssh root@(ip)[/pre]Type alpine to log in and[pre]passwd[/pre] Then type twice an old good very secure password, and then we will also the change the one for mobile, so[pre]su mobile[/pre]retype alpine and [pre]passwd[/pre] it will ask you again alpine, then twice again the same password, choose a different one if possible.

[size=1.5] 2 - Install everything needed for a web server[/size]

As we do not want to saturate the ram of our Apple TV, we will not install MySQL. By the way it is very complicated to use it in this environment, since our version of php does not support it, so we will use SQLite.

ssh as root on your Apple TV, then [pre]apt-get update[/pre] to get the most recent versions.
Then [pre]apt-get install lighttpd php sqlite3 nano[/pre]
Required packages will be installed, now let set this up.

[size=1.5] 3 - Check that everything is well prepared to start at boot[/size]

I will not give great details about launchd in this post, it should be the topic of a separate tutorial.

So, now ssh: [pre]cd /Library/LaunchDaemons
ls[/pre] You will likely have no file containing near or far "lighttpd" in its title, which means that nothing is configured.

In this case [pre]nano net.lighttpd.plist[/pre] and copy the contents of the following file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
        <key>Label</key>
        <string>net.lighttpd</string>
        <key>OnDemand</key>
        <false/>
        <key>Program</key>
        <string>/usr/sbin/lighttpd</string>
        <key>ProgramArguments</key>
        <array>
                <string>/usr/sbin/lighttpd</string>
                <string>-f /etc/www/lighttpd.conf</string>
                <string>-D</string>
        </array>
</dict>
</plist>

ctrl + x to exit and y to save.

[size=1.5]4 - Configure lighttpd[/size]

Check that the lighttpd.conf file is on /etc/www/
If this is not the case, [pre]find / -name lighttpd.conf[/pre] create www in the etc folder by [pre]mkdir /etc/www[/pre] then move the file [pre]mv (old location)/lighttpd.conf /etc/www/[/pre]
We will now create a folder that will contain the http directory in the root directory of the mobile user: [pre]mkdir /private/var/mobile/Media/Sites[/pre]
You can now check your config by [pre]nano /etc/www/lighttpd.conf[/pre]
check the following lines:

server.document-root = /private/var/mobile/Media/Sites/
index-file.names = ( "index.php","index.html")

also check that #dir-listing.activate = "enable"
is commented with a # to avoid displaying the contents of directories.

Then configure FastCGI for PHP:

fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/tmp/php-fcgi.sock",
"bin-path" => "/private/var/stash/bin/php-cgi",
"max-procs" => 1,
"bin-environment" =>
( "PHP_FCGI_CHILDREN" => "2",
"PHP_FCGI_MAX_REQUESTS" => "1000" ))))

then ctrl + x to close and y to save.

[size=1.5]5 - Configure php [/size]

This is much more simple, we will do the bare minimum:

[pre]nano /usr/lib/php.ini[/pre]
and make sure that your file looks something like this:

upload_max_filesize = 14M
post_max_size = 14M
max_execution_time = 240
session.auto_start = 1
expose_php = off

[size=1.5]6 - Prepare a small test (optional)[/size]

Of course there is still no html or php file in our "Sites" folder, you can add them by installing netatalk or pure-ftpd, we do not need a tutorial for this.

If you really have nothing in your Sites directory, you can do a small test to verify that everything works fine: [pre]nano /private/var/mobile/Media/Sites/index.php[/pre]
And copy the following line:


ctrl+x and y

[size=1.5] 7 - We can start[/size]

Everything is done, we can now ask launchd to kindly start lighttpd.
[pre]launchctl load /Library/LaunchDaemons/net.lighttpd.plist
launchctl start net.lighttpd[/pre]

Just to check that everything is well, do a "ps aux" and check that there is a lighttpd process.

You can now type in your browser http://(ip address of the apple tv)

[size=1.5] 7 - In case of error[/size]

If it does not work (and therefore the process lighttpd is not running when you check via "ps aux"), your config may be moldy or php crashes miserably.

First try to manually start lighttpd:
[pre]/usr/sbin/lighttpd -f /etc/www/lighttpd.conf -D[/pre] You can check error messages and you can correct what is wrong.

If the problem is php, debug is shoed by a [pre]cat /var/log/syslog[/pre] to check the error messages on the console.



Then, if you are still motivated, we can [url=http://www.daryo.com/seb/element/postfix-on-appletv2-the-missing-app-to-create-a-full-home-server,E4Wh]also configure a mail server.[/url]
    [language] => en
    [url] => 
    [clicks] => 
    [is_promoted] => 0
    [user] => seb
    [feed] => Technologie
    [feedUrl] => https://daryo.com/category/technologie
    [source] => _internal_
    [userUrl] => https://daryo.com/user/seb
    [mission] => init
)
by seb - 2012-07-19 04:52
The Apple TV 2 is probably the Apple product which has the most potential for customization.

A product who operate with flash memory, always powered on, and always connected, with an unix based os: it was tempting to turn it to a web server... and the results are quite impressive.

Firstly, it is obviously necessary to jailbreak the Apple TV, using Seas0npass (evasi0n can also do that). Please note that if you have an Apple TV 3, it is not possible to jailbreak it, you can stop reading this post here.

Then (and this is a bit off topic), I advise you to install ATV Flash Black, which is usually free (unless you go to a well known bay located in Sweden). This wonderful package will install you on the home screen a Media application, which lets you watch all movie formats via afp and smb shares.

This is obviously much more clean than installing this disgusting crap of XBMC. After all, you do not buy an Apple TV for a rotten interface running on a buggy and painfully slow software, isn't it?

Well, the bracket is closed, we are ready, your Apple TV 2 is jailbroken, ssh access is operational and you know its IP address (if not, go to settings> network).

Do not be fooled by the length of this tutorial, it will only take 20 minutes.

1 - Secure SSH a minimum

Like all iThings, the passwords of the two users root and mobile are set to "alpine". We cannot leave it like that.

So, on your computer in your favorite ssh console, type:
ssh root@(ip)
Type alpine to log in and
passwd
Then type twice an old good very secure password, and then we will also the change the one for mobile, so
su mobile
retype alpine and
passwd
it will ask you again alpine, then twice again the same password, choose a different one if possible.

2 - Install everything needed for a web server

As we do not want to saturate the ram of our Apple TV, we will not install MySQL. By the way it is very complicated to use it in this environment, since our version of php does not support it, so we will use SQLite.

ssh as root on your Apple TV, then
apt-get update
to get the most recent versions.
Then
apt-get install lighttpd php sqlite3 nano

Required packages will be installed, now let set this up.

3 - Check that everything is well prepared to start at boot

I will not give great details about launchd in this post, it should be the topic of a separate tutorial.

So, now ssh:
cd /Library/LaunchDaemons
ls
You will likely have no file containing near or far "lighttpd" in its title, which means that nothing is configured.

In this case
nano net.lighttpd.plist
and copy the contents of the following file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.lighttpd</string>
<key>OnDemand</key>
<false/>
<key>Program</key>
<string>/usr/sbin/lighttpd</string>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/lighttpd</string>
<string>-f /etc/www/lighttpd.conf</string>
<string>-D</string>
</array>
</dict>
</plist>

ctrl + x to exit and y to save.

4 - Configure lighttpd

Check that the lighttpd.conf file is on /etc/www/
If this is not the case,
find / -name lighttpd.conf
create www in the etc folder by
mkdir /etc/www
then move the file
mv (old location)/lighttpd.conf /etc/www/

We will now create a folder that will contain the http directory in the root directory of the mobile user:
mkdir /private/var/mobile/Media/Sites

You can now check your config by
nano /etc/www/lighttpd.conf

check the following lines:

server.document-root = /private/var/mobile/Media/Sites/
index-file.names = ( "index.php","index.html")

also check that #dir-listing.activate = "enable"
is commented with a # to avoid displaying the contents of directories.

Then configure FastCGI for PHP:

fastcgi.server = ( ".php" =>
( "localhost" =>
( "socket" => "/tmp/php-fcgi.sock",
"bin-path" => "/private/var/stash/bin/php-cgi",
"max-procs" => 1,
"bin-environment" =>
( "PHP_FCGI_CHILDREN" => "2",
"PHP_FCGI_MAX_REQUESTS" => "1000" ))))

then ctrl + x to close and y to save.

5 - Configure php

This is much more simple, we will do the bare minimum:

nano /usr/lib/php.ini

and make sure that your file looks something like this:

upload_max_filesize = 14M
post_max_size = 14M
max_execution_time = 240
session.auto_start = 1
expose_php = off

6 - Prepare a small test (optional)

Of course there is still no html or php file in our "Sites" folder, you can add them by installing netatalk or pure-ftpd, we do not need a tutorial for this.

If you really have nothing in your Sites directory, you can do a small test to verify that everything works fine:
nano /private/var/mobile/Media/Sites/index.php

And copy the following line:


ctrl+x and y

7 - We can start

Everything is done, we can now ask launchd to kindly start lighttpd.
launchctl load /Library/LaunchDaemons/net.lighttpd.plist
launchctl start net.lighttpd


Just to check that everything is well, do a "ps aux" and check that there is a lighttpd process.

You can now type in your browser http://(ip address of the apple tv)

7 - In case of error

If it does not work (and therefore the process lighttpd is not running when you check via "ps aux"), your config may be moldy or php crashes miserably.

First try to manually start lighttpd:
/usr/sbin/lighttpd -f /etc/www/lighttpd.conf -D
You can check error messages and you can correct what is wrong.

If the problem is php, debug is shoed by a
cat /var/log/syslog
to check the error messages on the console.



Then, if you are still motivated, we can also configure a mail server.