Archive

Posts Tagged ‘PHP’

Setting Up Ubuntu PHP 5.2, MySQL 5.1 and Apache 2 on a PS3

April 27th, 2009 Chris No comments

Recently I wanted a new development box/streaming media server for use around the house and for work.

After looking at the prices of all the main small form factor PC's or NAS boxes that would let me do this I could see that I was easily looking at £200-£250 minimum for the kind of setup I wanted to put together.

At the same time, I happened to notice that Sony actually support the use of Ubuntu as an alternative OS on the playstation 3 (or possibly Ubuntu Support the PS3 as an installation platform - whichever, it doesn't matter, the point is that some one does and it works!).

Now, an 80Gb PS3 is about £290 at the time of writing and has oodles of inbuilt support as a streaming media client, media storage and playback and a blue-ray player, as well as giving me the option to install a fully functional version of linux that will allow me to do whatever the hell I liked (RAM permitting).
So last weekend I bought one and, aside from playing games, I have just finished setting up Ubuntu 9.04 on it and I'm actually blogging this via firefox on the PS3 - woohoo :D

So what did I have to do to get this working?

Well the first thing to remember, if you've had a PS3 for a while and want to keep all your game saves, downloads, etc. is to back them up! There's an easy tool to do this in the system settings menu and I found having an external  USB HDD rather than a memory stick to hand was quite useful for this. Also you might want to sync your trophy collection with the Playstation Network Servers if you're interested in keeping that kinda stuff.

Once you've done your backups, you'll need to set aside a partition for the new OS to use.

To do this, oddly enough you have to use the format disk utility from system menu, as this where the partition management is also done. Basically you select the option and you'll get the choice of either giving the Guest OS 10 GB, and the PS3 the rest of the space, or the PS3 10GB and the Guest OS the rest of the space.

I chose to give the guest OS 10Gb and keep the PS3 holding the bulk of the space as I can see myself downloading a fair few games from the playstation network over the next couple of years. Also though this 10GB default setting isn't massive,  for my needs, as a system partition it's fine since I intend to run a 1TB data tank off the back of the PS3 to hold any other media.

Anyway, what seems to happen when you do this is that the PS3 re-formats the part of the disk allocated for all non-essential user data i.e. downloads and game saves and frees up a 10Gb chunk for the new OS.

At this point I'm pretty sure you get a prompt to insert the installation media for the new OS (if you don't just click through the options relating to guest OS's and it will pop up somewhere), so you then need to get (in my case as I'm using Ubuntu) the Ubuntu installation image for powerPC and PS3 and burn it to a CD. You can get Jaunty (9.04) here

Once you have the CD in hand, simply insert it into the PS3 and the install process will start as normal with any linux distro, allowing you to partition your allocated space and setup any basic system options - note however that the install may take quite a while due to the processing speed and allocated RAM of the PS3 - that said once installed Ubuntu seems to run pretty smoothly.

To get the linux side working you need to chose the default OS to use from the system settings menu i.e. PS3 or 'Guest OS' choosing the latter will fire up Ubuntu as normal on any standard PC. The PS3 will then always boot into Ubuntu unless you type 'game' at the boot prompt, which will reset the default OS to being the PS3's own OS.

Once Ubuntu has loaded all you need to do to install Apache, PHP and MySQL, is open up a terminal and type the following (Note: I'd install MySQL first as components of Apache and PHP seem to need the libs anyway):

$shell> sudo apt-get install mysql-server-5.1

$shell> sudo apt-get install apache2

$shell> sudo apt-get install php5

Note: for some reason the MySQL setup also requires you to setup postfix, I'm not sure why but I did this anyway as it prompted me to and having postfix active on this box is no bad thing really.

The last thing to do was to boot back into the PS3 and restore the backup up game files and resync the trophies and all is done...

So that's it. I now have a fancy pants gaming system, blue ray player, media server (when I setup twonky media) and a development box all for under £300 :D

In all, if you've installed linux before and are not afraid to click around the system settings of your PS3 the whole process is pretty straightforwards and self explanatory. That said, before I actually went the whole hog I did do a little bit of research and found the following sites which was quite handy to start with. The comments on some of the articles aren't great, and some are dated now, as doing what I've outlined above has seemed to work fine for me:

https://help.ubuntu.com/community/PlayStation_3

http://psubuntu.com/wiki/UbuntuVersions?show_comments=1#comments

Categories: Linux, PS3, Ubuntu Tags: , , , , , , ,

How to filter user submitted data easily in PHP?

August 18th, 2008 Chris 1 comment

How to filter user submitted data easily in PHP?

Posted using ShareThis

Firstly, as you can see this is my first post made as a direct result of using the ShareThis bookmarklet, which is pretty neat as it actually worked :)

Secondly and more importantly, I wanted to flag this up on my blog as it's something that quite often gets missed in PHP which is actually a very powerful tool.

As the author of the post above mentions, array_map() can be a useful function when sanitizing user data, but it has so many more uses too when dealing with the transformation of a data-set.

Basically a call such as $new_data = array_map('process_data', $old_data); will allow you to transform each element in the $old_data array to a new element in the $new_data array via the function called process_data.

What's more you can manipulate multiple data-sets in this way too by specifying multiple arrays, so long as process_data() can take in the arguments.

For example lets say we have process_data($item1, $item2, $item3) which manipulates $item1, $item2, $item3 to produce a single result.

If we need to perform this calculation on a bulk set of data we can do

$new_data = array_map('process_data', $array_of_item1, $array_of_item2, $array_of_item3);

Easy huh?

I still see people performing these transformations, calculations, whatever, using for, foreach and while loops which can be prone to failure under certain conditions, and are probably less efficient code than simply making this call.

So why don't more people use it?  I don't know, but maybe this post will help raise awareness!

Refactor My Code – I Wish I’d Thought of It!

August 15th, 2008 Chris 1 comment

refactormycode.com is a fledgling website setup as a project by French Canadian  Ruby Developer Marc-André Cournoyer and basically it's like a coding forum without the usual forum junk, style and obfuscation of content (forums for me are always a pain to use because of the tiers of information you have to go through).

It's a great looking website covering all the current major programming languages (at least when thinking of the web) and the idea behind it, though simple, seems to work really well.

Basically, you have some code that works, but you want to make it better, more efficient, or just tidier. So, you post your code sample and other people suggest changes. It's kind of like yahoo answers for developers or the comments foot of the PHP manual.

The code to be refactored, so far in the PHP section at least, has been of a reasonable standard i.e. that of at least intermediate developers, which is great as these services can tend to get flooded by newbies who don't know their $i++ from their ++$i :p and rapidly lose interest for me.

So far there are only a few PHP samples on there to comment on but I think, as the site begins to grow, there will be a wealth of well developed and critiqued code that serves as good examples or directly useable functionality.

So far I can't really fault it, other than making the "Best" link clearer by calling it "Best Refactorors"  or something similar, and providing some closed, or accepted answer(s) type functionality to stop a thread getting out of hand (it could be that this exists already but I just haven't seen it yet). Maybe even an option to download each refactoring as a plain text file could be useful.

So, to round up, as you can probably tell, I love this site and you can see my standing in the community in the foot of this page! Keep up the great work Marc and I hope your site develops in the way it deserves and gets the recognition it should!

PHP5 Universal File Download Class

August 12th, 2008 Chris No comments

After finding different hosting companies having wildly different policies when it comes to what's enabled and what isn't in PHP, I've built a generic file download class which should work in almost all situations.

This is the first version so there are some improvements to be made and if you download it, you'll see where some improvements may be made. I will be releasing another version when I've had time to do some further work on it. For now you can find the source code plus any community improvements here: http://www.refactormycode.com/codes/440-universal-file-download-class

I should also mention that this class has been cleaned of some application specific code, so if there's any disjointed bits I apologise - I have tried to deal with any discontinuities before posting but there may be something i've missed (this is also the reason for the bunch of if's in get_file() if you are to use this as is you may want to replace them with your own custom code).

Advanced Syntax-Hilighting Online Code Editors – A Wordpress IDE?

July 2nd, 2008 Chris No comments

When I write plugins for wordpress I like to do it on a test blog in a live environment.

Maybe not the best idea, but it's how I like to do it, and it also flags up any weird and wonderful restrictions to the development of the plugin as a result of my hosting company's security policy.

For a while now I've worked with just the plain old plugin editor that comes with wordpress, but this is cumbersome to say the least and as such I went looking for a syntax highlighting editor which I could (if necessary) convert into a plugin to (ironically enough) improve the plugin editor.

Turns out that there's quite a few good syntax highlighting online code editors available (list at the end of this post) and at least one neat one (CodePress)  has been converted to a wordpress plugin for theme editing and plugin editing.

This is a really great start, but there's a couple of things I'd really like to see to progress this work - If I have the time I'll do it myself, otherwise someone else reading this post may like to take it up!

Basically the current Codepress for wordpress plugin is missing (in my opinion) a few additional functions to create backups of the plugin or theme files you're working on, to an extent a rudimentary versioning system could and should be implemented within the editor.

There should be an option to package up the plugin you're editing and release it to the community/tie updates into the automatic plugin updater of 2.5

The current CodePress release is great but what would make it even greater would be code hinting when editing.

I don't know enough JavaScript to say whether or not this is possible but it would be cool for the editor to notice that you've just typed or started to type a PHP (or other language) function name, and provide you with a syntax hint for the function.

This would work (in my mind) by noticing the opening of ( and then checking what preceded it back to the last space or operator (*, ., /, etc.), then looking up this string from a function definition array and displaying a tooltip near where you are editing in the text area to remind you of the syntax - possibly with an autocomplete if you press enter.

I think the main problem with this is knowing where you are in the text area to display the div with the tool tip text in it in the right place. I know you can monitor where you are in a text area in terms of columns and rows, so surely if you know the location of the start of the text area and the size of the character in the text area and the co-ordinates of the cursor in the text area via row/column values you should be able to determine the optimal position for the <div>?

I think it would be really great to see that kind of functionality in any of the online code editors listed below on it's own let alone any other stuff such as versioning that I've already mentioned.

So there it is!

I probably will end up doing some work on the codepress plugin myself from a versioning point of view, but if any one else out there can figure out a way of doing the code hinting in JS that'd be fantastic!

Existing On line Code Editors:

Autosuggest example (could be used to provide the tool tip if the positioning is worked out): http://gadgetopia.com/post/3773

Wordpress plugins: