Default Green Orange
Swifty's Blog
James Irving-Swift's portfolio and random blogging
RSS
  • Home Page Home
  • My CV

Quick Start guide to install LEMP server on Ubuntu 12.04 (Linux + Nginx + MySql + PHP )

Linux, Ubuntu 0 Comment »

I have seen some online guides about this but really was after one specific to Ubuntu 12.04. So here goes:

Step 1 – Installing Nginx

First we need to add the Nginx source

sudo add-apt-repository ppa:nginx/stable

Next, as we always do after adding a source, we need to update

sudo apt-get update

And now we install it

sudo apt-get install nginx

Next, we must start the Nginx service.

sudo /etc/init.d/nginx start

To check if it is successful, try going to http://localhost/ in your browser. If you see a Welcome to Nginx page, it has been successful.

Step 2 – Installing PHP5:

Install PHP and any required extensions

sudo apt-get install php5-cli php5-cgi php5-fpm php5-mcrypt php5-mysql

Edit the default Nginx site config (if you are not familiar with vim, try entering ‘nano’ instead)

sudo vim /etc/nginx/sites-available/default

The changes you will need to make are as follows:
1)

index index.html index.htm;

to

index index.html index.htm index.php;

2)

root /srv/http/nginx;

^this path may be different in your install, it doesn’t matter as we are changing it!
to:

root /var/www;

3) uncomment the following lines

 location ~ \.php$ {
     fastcgi_pass 127.0.0.1:9000;
     fastcgi_index index.php;
     include fastcgi_params;
  }

Now quit vim (‘:wq’) and restart the nginx service.

sudo /etc/init.d/nginx restart

If the folder /var/www/ doesn’t exist, create it

sudo mkdir /var/www/

Step 3 – Install MySQL

And finally,

sudo apt-get install mysql-server

Step 4 – Check it works!

Create a test file

vim /var/www/test.php

Add this line

<?php phpinfo();?>

Save and quit vim (:wq) and go to http://localhost/test.php in your browser.
If you see a page displaying all your PHP settings, then it works!


May 2nd, 2012  
Tags: LEMP, Linux, Mysql, nginx, Ubuntu



Ajax breaks in wordpress if back-end uses SSL

Development 0 Comment »

So you have a wordpress blog and you (or your client) want the wp-admin to use an SSL certificate, sounds great! However, any AJAX you use in your site has broken. I spent a while googling this issue when it happened to me and found a really easy fix; you need to change the variables in the get_admin_url() function to force the AJAX requestion to use http instead of https. Change it to look like:

get_admin_url(null,'','http');

I hope this helps a lot of people!


March 3rd, 2012  



Guide to WordPress Settings API

Development, Wordpress 0 Comment »

I have decided to explain how to use the WordPress Settings API after having pulled out most my hair whilst googling for a easy to understand explanation.

The reason I wanted to use the WordPress Settings API was because whilst making plugins, I found that my code for my options page was getting a little messy. I had also read, that if you use the Settings API, you don’t ever have to use the update_option() function.

Finally, being a WordPress API, I would like to think that this make my plugins a little more future-proof against wordpress upgrades.

Please note that in this walkthrough I am storing the options into an array.

So this is how it is done:

add_action('admin_menu', 'create_plugin_options_page');
add_action('admin_init', 'register_and_build_plugin_options');

function create_plugin_options_page() {
  //register the menu item
  add_menu_page('Plugins Option', 'Plugin Options', 'administrator', 'option-page-name', 'plugin_options_page');
}

function register_and_build_plugin_options(){
  //register the option value you will be using.
  //N.B. the second parameter must be the same as what you have named the option in your plugin activation
  register_setting('settings_option','plugin_settings', 'validate_option');
  add_settings_section('first_setting_section', 'Settings Section 1','section1_callback','option-page1');
  add_settings_field('setting_text','Text Field: ','text_field','option-page1','first_setting_section');
}

You can have lots of fields in lots of sections. Important things to note when using add_settings_section, add_settings_field, register_setting:

  • The 3rd parameter of register_setting is a callback for validation. In the example above, I have a function (shown later) called validate_option which contains any required validation. This field is optional.
  • The 4th parameter of add_settings_field must correlate to a 1st parameter of add_settings_section
  • The 4th parameter of add_settings_section which should be the same as the 4th parameter of add_settings_field (‘option-page1′) is what you will later use to load this section by using the function do_settings_section();
  • The 3rd parameter of add_settings_section is a callback function. It can be a blank function if you want it to be.
  • The 3rd parameter of add_settings_field is a callback function that contains the input field that you want.
This is the callback function with input field:
function text_field(){
	  $optionValue = get_option('plugin_settings');
    $option = "";
    $option .= "
";
    echo $option;
}

You must name the field by the option name so it will save correctly, like I have done above with name=\”plugin_settings[text_field]\”.

Now finally, the function that brings it all together:

function plugin_options_page() {
?>
<div id="theme-options-wrap">
<h2>Plugin Title</h2>
<div><form action="options.php" method="post"> 
<p class="submit"><input class="button-primary" type="submit" name="Submit" value="<?php esc_attr_e('Save Changes'); ?>" /></p>

</form></div>
</div>
<div id="theme-options-wrap">
<h2>Plugin Title</h2>
<div><form action="options.php" method="post"> 
<p class="submit"><input class="button-primary" type="submit" name="Submit" value="<?php esc_attr_e('Save Changes'); ?>" /></p>

</form></div>
</div>
<?php
}

function validate_option($option){
    //put any validation on the options here.
    return $option;
}

function section1_callback(){}

function section2_callback(){
	$html = "An example of some text in the callback function";
	echo $html;
}

function text_field(){
	  $optionValue = get_option('plugin_settings');
    $option = "";
    $option .= "
<input id=\"text_field\" type=\"text\" name=\"plugin_settings[text_field]\" value=\"{$optionValue['text_field']}\"?-->";
    echo $option;
}

function select_field(){
    $options = get_option('plugin_settings');
    $items = array("Red", "Green", "Blue", "Orange", "White", "Violet", "Yellow");
    $html = "
    <select id="select_field" name="plugin_settings[select_field]">";
    foreach($items as $item) {
        $selected = ($options['select_field']==$item) ? 'selected="selected"' : ''; $html .= " <option selected="selected" value="$item">$item</option> ";
    }
    $html .= "</select>";
    echo $html;
}
function checkbox_field(){
    $optionValue = get_option('plugin_settings');
    $option = "";
    $option .= " <input type="\"checkbox\"" name="\"plugin_settings[checkbox_field]\"" value="\&quot;1\&quot;" checked="checked" />";
    echo $option;
}
function radio_field(){
    $optionValue = get_option('plugin_settings');
    $option = "";
    $option .= " <input type="\"radio\"" name="\"plugin_settings[radio_field]\"" value="\"value1\"" checked="checked" />Value1 ";
    $option .= " <input type="\"radio\"" name="\"plugin_settings[radio_field]\"" value="\"value2\"" checked="checked" />Value2 ";
    echo $option;
}

This will allow you to have a settings page that looks like:

Quite a Mouthful! However I hope this really helps for people trying to get to grips with API. Admittedly, I have written this partly as a response to lack of documentation on the API!

If you would like more help, I found this documentation helpful: http://www.presscoders.com/wordpress-settings-api-explained/


November 29th, 2011  



Ubuntu 11.04 first impressions

Ubuntu 0 Comment »

So Ubuntu 11.04 (Nutty Narwhal) is finally here, and so far it seems to be the release with the most amount of change since I started using Ubuntu 6.04.Unity Screenshot

The big change is the use of Unity instead of Gnome as the default environment, which seemed a bit of a shock as Gnome 3 has been released. I would assume that gnome 3 wasn’t ready early enough to develop in this release. However, I have heard you can manually install it and it works fine, except it breaks Unity!

Positive things I have noticed from Unity already have been:

  • I did not have to play with any settings at all for my dual monitors, however with gnome 2 I remember spending ridiculous amounts of editing various conf files else finding the right drivers so that I could use two monitors with different resolutions.
  • A much lighter interface, mainly as most programs seem to integrate with Unity’s Mac-like toolbars, however I get disappointed when some programs don’t follow the theme very well (i.e. Netbeans and Chrome!)
  • My system icons magically tidied themselves during the upgrade, and more seemed to get included into the messaging menu. My old toolbar was starting to become a mess and this is a much welcomed change.

So far my only complaints would be:

  • System settings are in the most ridiculous place! Go to shutdown and you will see them!
  • I prefer the new menu as I no longer need Gnome-Do, however, the Places menu from gnome 2 was so useful for all my shortcuts.

So without any doubt Unity is the big change in this release, however there have been other changes.

I now have libreOffice, I don’t know what was wrong with OpenOffice but I like OpenOffice! Maybe I’m just being closed minded and just need to actually give libreOffice a chance!

Rhythmbox is no longer the default music player, instead Banshee is, and I must admit, that even though Rhythmbox is plain and boring, I like it’s shear simplistic user interface and I don’t think that Banshee feels as polished.

I have noticed a few changes since upgrading from 10.10. Mainly that flash seems to run so much better. I had stopped using Grooveshark as it would crash every couple or songs and I couldn’t full-screen HD videos and vimeo and youtube, however, 11.04 seems to have fixed this.

Also it seems to that multitasking is less painless and application switching happens more fluidly.


May 4th, 2011  
Tags: Natty Narwhal, Ubuntu, Unity



Magento Developer’s Paradise 2010

Development, Magento 0 Comment »

About 2 and a half months ago, my boss told me that I was to go on a business trip to learn more about Magento. I thought: “Ugh, I’m going to lose a weekend and have to do lots of driving, this is going to be dreadful”.
This thought quickly vanished when I was told that the conference was in Majorca!
So after an easy flight there my colleague and I arrived at a large and pleasant hotel. We had been expecting that we would be sharing a room so were pleased when we were given separate room and then all-inclusive bands on our wrists!
When people are all-inclusive, its amazing how generous they are at offering drinks!
So after having located our rooms and dropped off our bags we thought we would go to the bar and starting introducing ourselves as the conference would be starting with an hour or two.
Even though we had a great view of the pool, it was raining so we couldn’t make the most of that, but it was still warm and I didn’t care, the novelty of being in Majorca still hadn’t worn off!
There was a large variety of lectures. The keynote lecture by Yoav Kutner was excellent I found Ashley Schroder’s lecture on plugin development especially interesting as this something I am keen to learn. The other lectures that really grabbed my attention was Phillippe Humeau’s ‘Make Magento Run Like an Antelope’ which had me writing down pages of notes.
From this conference, I feel that the most important thing I have taken away is that to develop with Magento, you must understand Zend first. It is for this reason that I have started to really make the time to understand Zend.
The Conference was a great opportunity for meeting others in the same field of work. I was surprised that we English were a minority, the majority was very definitely German however I met people from the US, Belgium, Sweden, France, Spain and even New Zealand (just to name a few).
Given the chance, I would very happily go again and I congratulate the Magento Team who organised this event.

(Thank you to C3Media.co.uk for allowing me to use their images).


October 31st, 2010  



Filtering custom posts by more than one Taxonomy

Development, Wordpress 0 Comment »

With WordPress now able to use custom post types, I have asked on forums if anyone new how to filter by more than one taxonomy. I originally tried using

 query_posts('cat=6,5') 

and other similar commands but have no luck.

To resolve this I came up with the following solution:

First I create two custom fields on the page which I named taxonomy1 and taxonomy2.
I then added the following code:

 <?php
$taxonomy1 = get_post_meta($post->ID, "taxonomy1");
$taxonomy2 = get_post_meta($post->ID, "taxonomy2");

//this is an sql query to find all posts containing two taxonomies
$sql_query = "SELECT * FROM (
			SELECT wp_posts.ID FROM `wp_posts`
				JOIN wp_term_relationships ON wp_posts.ID=wp_term_relationships.object_id
				JOIN wp_terms ON wp_term_relationships.term_taxonomy_id=wp_terms.term_id
					WHERE slug = '".$taxonomy1[0]."'
			UNION ALL
			SELECT wp_posts.ID FROM `wp_posts`
				JOIN wp_term_relationships ON wp_posts.ID=wp_term_relationships.object_id
				JOIN wp_terms ON wp_term_relationships.term_taxonomy_id=wp_terms.term_id
					WHERE post_type = 'tiles' AND slug = '".$taxonomy2[0]."'
		) AS results

		GROUP BY results.id HAVING COUNT(*) = 2";

	$newresults = $wpdb->get_results($sql_query);			

	$ArrayOfIDs = array();

	foreach($newresults as $newresult){
		array_push($ArrayOfIDs, $newresult->ID);
	}

	query_posts(array('posts_per_page'=>'900','post_type' => 'tiles','post__in' => $ArrayOfIDs));
?>

The idea behind this code is that the mysql query returns the post IDs of the posts that correspond to the two taxonomy filters and then the foreach loop pushes those into an array of IDs ($ArrayOfIDs) which is then used in the query_post function.

Feedback would be much appreciated on other ways that I could have resolved this issue or also how I could improve this code.


October 7th, 2010  



New ventures with Electric Studio

Websites 0 Comment »

Since July 31st I have left STFC and join Electric Studio. I have taken on the role as a web developer and it seems I shall be leaving any Perl coding behind and focusing mainly on PHP.

I am now working with the wordpress engine and shall be developing plugins. I am also updating the company’s bespoke systems and shall soon be learning about Magento.

I am also having to brush up my jquery skills which seems to be happening very quickly! I am constantly amazed at what is possible with jquery and the amount of libraries available.

Finally, I am now working on a pure linux setup! This makes the working day far more pleasant!


September 24th, 2010  
Tags: Electric Studio, jQuery, Magento, PHP, Wordpress



Mailtalk.ac.uk Launched!

Mailtalk, Websites 0 Comment »

Screenshot of the new Mailtalk websiteAt last, JISCMail’s sister service has a launched the new website. I finished this website last week and before launch date, the JISCMail team helped me with the testing.

This website runs off the same back end as JISCMail however the CSS was changed to make the site noticeably different yet easy to move updates from JISCMail to Mailtalk.

For technical details of how the back end works to the JISCMail website please see my previous posting.

Mailtalk also needed rebranding with the aid of a new logo. So I loaded up GIMP and started coming up with some ideas to put around the team. Some ideas went down well, others not so much! However, eventually I came up with the colour scheme of using red, white, grey and black and decided that the logo, to make it simple, should stick to two colours. After coming up with a rough draft, I added a web 2.0 look to it and end up with the logo on the right.


July 6th, 2010  
Tags: CSS, Logo, Mailtalk



JISCMail.ac.uk launched!

JISCMail, Websites 0 Comment »

My biggest project yet is live since Tuesday morning. I have been wanting to do a site that is content heavy for a while as most of my previous sites have been quite small for the likes or artists or DJs. JISCMail is a service the is based on LSoft’s Listserv to run mailing lists and is the National Academic Mailing List Service.
This project has allowed me to play with various frameworks that I had not used before. The first framework that I used was josh clayton’s blueprint which I found fantastic. Blueprints meant that I did not have too worry about floating dividers, setting a size for a container nor create classes for warning, error and success messages.
Another CSS framework to I used was Lwis.net’s drop down menu. I have always found that CSS drop down menus are ridiculously time consuming to make especially if you want you menu to be compatible with all browsers.JISCMail.ac.uk Screenshot
I was also introduced to the Zend Lucene php framework which allowed me to index all the files in my site. Indexing a site was something that I was unfamiliar with. I did find very frustrating to come up with a way to index the files as it was something I addressed towards the end of making the site. However, after finding a couple of good tutorials online I soon had indexed every page. Once the files where indexed, making a search page was very easy, allowing me to easily search exact matches or phrases.
When I started this site I had only ever made the most minimalistic of javascript scripts. However since the making of this site I have become quite accustomed to using jquery and also implemented an html editor with thanks to ECKditor. CKEditor really impressed me as it took so little time to implement and could edit XHTML (something I did not find any other web based HTML editor could).


April 21st, 2010  
Tags: Blueprint, CKEditor, JISCMail, Josh Clayton, jQuery, listserv, Zend Lucene



Moving house has caused a lack of blogging!

Just for fun, Random 0 Comment »

I was just watching Californication in which I saw Hank Moody blogging and realised that I have not blogged in a while.

I’ve been so busy with moving house and when I’ve not been moving I seem to have found myself playing lots more Xbox than usual. I have realised that now I’m at the age of 24, I do not need to go out every Friday and Saturday and drink enough that I can’t remember the going ons of the night before!

By going out less I thought I would get bored so I subscribed with LoveFilm so I could have a constant decent turnover of games. I have to admit, this was such a good idea. I have rent some excellent games such as Batman Arkham Asylum and Mirror’s Edge but at the same time I have rented one real shocker, Prototype.

Unfortunately due to the move of house, I am now without internet (uploading this on my blackberry!) This means that I have no Xbox Live and I’m missing my party chat times so much!

Hopefully I will have internet soon and will be blogging properly again soon.


March 28th, 2010  



Previous Entries
  • Search

  • Calendar

    May 2012
    M T W T F S S
    « Mar    
     123456
    78910111213
    14151617181920
    21222324252627
    28293031  
  • My Twitter

    • @louistheroux this is why i have disconnected my landline! The only use for my telephone line is broadband 2 days ago
    • i wondering if my copy of Max Payne 3 will have arrived when i get home this evening. My fingers are crossed so hard! #MaxPayne3 3 days ago
    • @bbc606 what about newcastle??? :-P 3 days ago
    • @PowPowell I have been playing halo wars and guardian of light to pass the time. Might play max Payne one this eve! 4 days ago
    • Am starting to get really impatient for Max Payne 3! 4 days ago
  • Categories

    • Development
    • Development
    • JISCMail
    • Just for fun
    • Linux
    • Magento
    • Mailtalk
    • Mutiny
    • Random
    • Thomas Murr Art
    • Ubuntu
    • Websites
    • Wordpress
  • Archives

    • May 2012
    • March 2012
    • November 2011
    • May 2011
    • October 2010
    • September 2010
    • July 2010
    • April 2010
    • March 2010
    • SN205662 Samsung digital camera
    • SN205661 Samsung digital camera
    • SN205660 Samsung digital camera
    • SN205658 Samsung digital camera
    • SN205659 Samsung digital camera
    • SN205657 Samsung digital camera
    • SN205656 Samsung digital camera
    • SN205655 Samsung digital camera
    • SN205654 Samsung digital camera
    • SN205653 Samsung digital camera
    • SN205651 Samsung digital camera
    • SN205652 Samsung digital camera
    • SN205650 Samsung digital camera
    • SN205649 Samsung digital camera
    • SN205648 Samsung digital camera
    • SN205644 Samsung digital camera
    • SN205625 Samsung digital camera
    • SN205639 Samsung digital camera
    • SN205626 Samsung digital camera
    • SN205636 Samsung digital camera
Copyright © 2012 Swifty's Blog Skin beauty products
XHTML CSS Log in