Weather Specific Backgrounds on Ubuntu with Apache, PHP, Cron and Weather.com

It has long been a goal of mine to create a system for my laptop which allows my background to mimic the weather where I live (Durham, NC). When it is raining outside, I want a background of rain. When it is sunny, the sun.

So, here is a basic step-by-step guide I used to cobble this together.

1. Install Apache on Ubuntu.

* JTirrell below makes a good point for those who don’t already need Apache: “Why install apache at all? php5-cli and just run the php file like a script.”

Open up a terminal and type in the following, being sure to use your password after entering in the command. Afterwards, you should now be able to open up http://localhost/ in your browser.

sudo apt-get install apache2

2. Install PHP

Open up a terminal and type in the following, being sure to use your password after entering in the command. You will now have PHP installed with your Apache build.

sudo apt-get install php5 libapache2-mod-php5

3. Create Directory /var/www/backgrounds

This is the directory which will store your backgrounds and the code necessary to generate the background.

4. CHMOD 666 Directory /var/www/backgrounds

This is necessary so that your system can write the background.jpg file whenever the weather status updates.

5. Create the file /var/www/backgrounds/maker.php with the following code

This is the PHP file that grabs the current weather based on your zip code, grabs the relevant background image and overwrites background.jpg with it.

6. Switch your Zip Code with Yours and Save

Make sure you switch the zip code unless you want your background to only mimic the weather in Durham, NC 🙂

7. Create Backgrounds to Match The Common Weather.com Statuses

…and Save Them to the /var/www/backgrounds folder. Make sure that you…

Resize them to your resolution

Save them with the Exact, Case Sensitive name of the status (like “Partly Cloudy.jpg”)

Some examples are below.

8. Set Background to /var/www/background.jpg in Ubuntu

This is the background image that gets regenerated every 5 minutes based on the status at Weather.com for your zip code.

9. Set Cron Job to Run maker.php Every 5 Minutes

5 * * * * wget -rvc http://localhost/backgrounds/maker.php > /dev/null

Thats it! Whenever you have an internet connection and your Cron job is running, you will have a background that mimics the current weather!

No tags for this post.