<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>david winter &#187; php</title>
	<atom:link href="http://davidwinter.me.uk/articles/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://davidwinter.me.uk</link>
	<description>you were expecting someone else?</description>
	<lastBuildDate>Mon, 28 Jun 2010 20:37:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Installing MySQL for PHP with MacPorts</title>
		<link>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/</link>
		<comments>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/#comments</comments>
		<pubDate>Sun, 28 Feb 2010 13:38:02 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=162</guid>
		<description><![CDATA[In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a WordPress theme and plugin on my local machine. Here are the few steps I used: sudo port install mysql5-server sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist sudo -u _mysql mysql_install_db5 sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ [...]]]></description>
			<content:encoded><![CDATA[<p>In my other howto, I installed Apache, PHP and MongoDB. I now need to setup MySQL so that I can develop a WordPress theme and plugin on my local machine. Here are the few steps I used:</p>

<p><span id="more-162"></span></p>

<pre><code>sudo port install mysql5-server
sudo launchctl load -w /Library/LaunchDaemons/org.macports.mysql5.plist
sudo -u _mysql mysql_install_db5
sudo chown -R _mysql:_mysql /opt/local/var/db/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/run/mysql5/ 
sudo chown -R _mysql:_mysql /opt/local/var/log/mysql5/
</code></pre>

<p>I then add the following aliases to make it easy to start, stop and restart MySQL:</p>

<pre><code>mate ~/.bashrc

alias mysql-start="sudo /opt/local/share/mysql5/mysql/mysql.server start"
alias mysql-restart="sudo /opt/local/share/mysql5/mysql/mysql.server restart"
alias mysql-stop="sudo /opt/local/share/mysql5/mysql/mysql.server stop"

source ~/.profile
</code></pre>

<p>You can then use the following to start MySQL:</p>

<pre><code>mysql-start
</code></pre>

<p><em>Note: I had errors when I first tried starting MySQL. This was because I&#8217;d installed a version of MySQL previously from the official site and it was conflicting. Removing the old version of MySQL did the trick &#8211; instructions <a href="http://tomkeur.net/39/how-to-remove-mysql-completely-mac-os-x-leopard.html">here</a>.</em></p>

<p>When you start the server, it&#8217;s best to set the <code>root</code> user password:</p>

<pre><code>mysqladmin5 -u root password mysupersecretpassword
</code></pre>

<p>Then to setup PHP to work with MySQL:</p>

<pre><code>sudo port install php5-mysql
</code></pre>

<p>Then update the php.ini file:</p>

<pre><code>sudo nano /opt/local/etc/php5/php.ini
</code></pre>

<p>And ensure this line is in there:</p>

<pre><code>mysql.default_socket = /opt/local/var/run/mysql5/mysqld.sock
</code></pre>

<p>Restart Apache, and then you&#8217;re all set.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/02/28/installing-mysql-for-php-with-macports/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache, PHP and MongoDB on Mac OS X 10.6 Snow Leopard</title>
		<link>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/</link>
		<comments>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/#comments</comments>
		<pubDate>Sat, 02 Jan 2010 13:12:13 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[mongodb]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=152</guid>
		<description><![CDATA[MongoDB (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database. There&#8217;s a lot of buzz brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the Xcode [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.mongodb.org/display/DOCS/Home">MongoDB</a> (from &#8220;humongous&#8221;) is a scalable, high-performance, open source, schema-free, document-oriented database.</p>

<p>There&#8217;s a lot of <a href="http://delicious.com/search?p=mongodb&amp;chk=&amp;context=popular|&amp;fr=del_icio_us&amp;lc=">buzz</a> brewing about it, so I wanted to give it a try with PHP on my development Mac. The following is how I went about installing Apache, PHP and MongoDB on Snow Leopard. You must have installed the <a href="[http://developer.apple.com/tools/xcode/">Xcode</a> developer tools (found on the Snow Leopard install DVD) and <a href="[http://www.macports.org/">MacPorts</a> for this to all work.</p>

<p><span id="more-152"></span></p>

<p>First, let&#8217;s install Apache:</p>

<pre><code>sudo port install apache2
</code></pre>

<p>Nice and simple. Now we can move onto PHP:</p>

<pre><code>sudo port install php5 +apache2 +pear
</code></pre>

<p>To enable PHP for Apache:</p>

<pre><code>cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
</code></pre>

<p>I like to make some alias commands for starting, restarting and stopping Apache:</p>

<pre><code>mate ~/.bashrc

alias apache-start="sudo /opt/local/apache2/bin/apachectl start"
alias apache-restart="sudo /opt/local/apache2/bin/apachectl restart"
alias apache-stop="sudo /opt/local/apache2/bin/apachectl stop"

source ~/.bashrc
</code></pre>

<p>Now we can make a few changes to the Apache config so that we can use our Sites directory:</p>

<pre><code>sudo mate /opt/local/apache2/conf/httpd.conf
</code></pre>

<p>I&#8217;m using Textmate here (<code>mate</code>), but you can use any editor you wish, like <code>nano</code>.</p>

<p>Change the <code>DocumentRoot</code>:</p>

<pre><code>DocumentRoot "/Users/davidwinter/Sites"
</code></pre>

<p>Then update the <code>&lt;Directory&gt;</code> path to the updated <code>DocumentRoot</code> path.  </p>

<pre><code>&lt;Directory "/Users/davidwinter/Sites"&gt;
</code></pre>

<p>We also want to enable <code>index.php</code> as a directory index file:</p>

<pre><code>&lt;IfModule dir_module&gt;
    DirectoryIndex index.html index.php
&lt;/IfModule&gt;
</code></pre>

<p>And then add the PHP mime type:</p>

<pre><code>&lt;IfModule mime_module&gt;
    ...
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps
&lt;/IfModule&gt;
</code></pre>

<p>Now we need to setup the <code>php.ini</code> file:</p>

<pre><code>sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini

sudo mate /opt/local/etc/php5/php.ini
</code></pre>

<p>My <a href="[http://php.net/manual/en/timezones.php">timezone</a> is for London:</p>

<pre><code>date.timezone = Europe/London
</code></pre>

<p>Now we can get onto installing MongoDB (this will install the latest stable version as of time of writing &#8211; 1.2.1): </p>

<pre><code>sudo port install mongodb
</code></pre>

<p>And then the PHP MongoDB extension:</p>

<pre><code>sudo pecl install mongo
</code></pre>

<p>You&#8217;ll need to add the extension to the bottom of your <code>php.ini</code> file:</p>

<pre><code>sudo mate /opt/local/etc/php5/php.ini

extension=mongo.so
</code></pre>

<p>Now startup Apache using the <code>alias</code> created earlier:</p>

<pre><code>apache-start
</code></pre>

<p>If you create a file in your Sites directory, called <code>test.php</code>, and add the following to it:</p>

<pre><code>&lt;?php phpinfo(); ?&gt;
</code></pre>

<p>Then visit the page in your browser; <a href="http://localhost/test.php">http://localhost/test.php</a></p>

<p>You can then scroll down the page and you should see a section titled &#8216;mongo&#8217;. This means the extension is working!</p>

<p>Now we need to startup MongoDB:</p>

<pre><code>mkdir -p ~/data/db
mongod --dbpath ~/data/db/
</code></pre>

<p>Almost there, now a simple MongoDB test in PHP:</p>

<pre><code>&lt;?php
// Connect:
$connection = new Mongo();
// Select database:
$db = $connection-&gt;my_db;
// Select collection:
$films = $db-&gt;films;

$frwl = array(
    'title' =&gt; 'From Russia With Love',
    'year' =&gt; 1963,
    'actor' =&gt; 'Sean Connery'
);
// Save array to collection:
$films-&gt;insert($frwl);

$gf = array(
    'title' =&gt; 'Goldfinger',
    'year' =&gt; 1964,
    'actor' =&gt; 'Sean Connery',
    'girl' =&gt; 'Pussy Galore'
);

$films-&gt;insert($gf);

// Count documents in collection:
if ($films-&gt;count()): ?&gt;
&lt;table&gt;
    &lt;tr&gt;
        &lt;th&gt;Title&lt;/th&gt;
        &lt;th&gt;Year&lt;/th&gt;
        &lt;th&gt;Actor&lt;/th&gt;
        &lt;th&gt;Girl&lt;/th&gt;
    &lt;/tr&gt;
    &lt;?php foreach ($films-&gt;find() as $film): ?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;?php echo $film['title']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['year']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['actor']; ?&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?php echo $film['girl']; ?&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php endforeach; ?&gt;
&lt;/table&gt;
&lt;?php endif;
?&gt;
</code></pre>

<p>Very exciting stuff. More to follow.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2010/01/02/apache-php-and-mongodb-on-mac-os-x-10-6-snow-leopard/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Enable PHP error logging</title>
		<link>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/</link>
		<comments>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/#comments</comments>
		<pubDate>Tue, 14 Jul 2009 20:02:03 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/</guid>
		<description><![CDATA[In php.ini: display_errors = Off log_errors = On error_log = /var/log/php-errors.log Make the log file, and writable by www-data: sudo touch /var/log/php-errors.log sudo chown www-data:www-data /var/log/php-errors.log]]></description>
			<content:encoded><![CDATA[<p>In php.ini:</p>

<pre><code>display_errors = Off
log_errors = On
error_log = /var/log/php-errors.log
</code></pre>

<p>Make the log file, and writable by www-data:</p>

<pre><code>sudo touch /var/log/php-errors.log
sudo chown www-data:www-data /var/log/php-errors.log
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/07/14/enable-php-error-logging/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP and nginx on Ubuntu: the easy way</title>
		<link>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/</link>
		<comments>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/#comments</comments>
		<pubDate>Sat, 13 Jun 2009 19:31:08 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[nginx]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=139</guid>
		<description><![CDATA[I&#8217;ve now changed my slice from running lighttpd to nginx. Here&#8217;s the simplest way, in around 6 commands, to get PHP up and running via FastCGI. Install and setup Install PHP 5: sudo aptitude install php5-cgi Install nginx: sudo aptitude install nginx Create PHP 5 FastCGI start-up script: sudo nano /etc/init.d/php-fastcgi Inside, put: #!/bin/bash BIND=127.0.0.1:9000 [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve now changed my slice from running lighttpd to nginx. Here&#8217;s the simplest way, in around 6 commands, to get PHP up and running via FastCGI.</p>

<h2>Install and setup</h2>

<p>Install PHP 5:</p>

<pre><code>sudo aptitude install php5-cgi
</code></pre>

<p>Install nginx:</p>

<pre><code>sudo aptitude install nginx
</code></pre>

<p>Create PHP 5 FastCGI start-up script:</p>

<pre><code>sudo nano /etc/init.d/php-fastcgi
</code></pre>

<p>Inside, put:</p>

<pre><code>#!/bin/bash
BIND=127.0.0.1:9000
USER=www-data
PHP_FCGI_CHILDREN=15
PHP_FCGI_MAX_REQUESTS=1000

PHP_CGI=/usr/bin/php-cgi
PHP_CGI_NAME=`basename $PHP_CGI`
PHP_CGI_ARGS="- USER=$USER PATH=/usr/bin PHP_FCGI_CHILDREN=$PHP_FCGI_CHILDREN PHP_FCGI_MAX_REQUESTS=$PHP_FCGI_MAX_REQUESTS $PHP_CGI -b $BIND"
RETVAL=0

start() {
      echo -n "Starting PHP FastCGI: "
      start-stop-daemon --quiet --start --background --chuid "$USER" --exec /usr/bin/env -- $PHP_CGI_ARGS
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}
stop() {
      echo -n "Stopping PHP FastCGI: "
      killall -q -w -u $USER $PHP_CGI
      RETVAL=$?
      echo "$PHP_CGI_NAME."
}

case "$1" in
    start)
      start
  ;;
    stop)
      stop
  ;;
    restart)
      stop
      start
  ;;
    *)
      echo "Usage: php-fastcgi {start|stop|restart}"
      exit 1
  ;;
esac
exit $RETVAL
</code></pre>

<p>Make start-up script executable:</p>

<pre><code>sudo chmod +x /etc/init.d/php-fastcgi
</code></pre>

<p>Launch PHP:</p>

<pre><code>sudo /etc/init.d/php-fastcgi start
</code></pre>

<p>Launch at start-up:</p>

<pre><code>sudo update-rc.d php-fastcgi defaults
</code></pre>

<p>That&#8217;s it. All installed and ready to go.</p>

<h2>Test</h2>

<p>In your server config, add the following:</p>

<pre><code>location ~ \.php$ {
    fastcgi_pass    127.0.0.1:9000;
    fastcgi_index   index.php;
    fastcgi_param   SCRIPT_FILENAME /var/www/nginx-default$fastcgi_script_name;
    include         fastcgi_params;
}
</code></pre>

<p>Restart nginx:</p>

<pre><code>sudo /etc/init.d/nginx restart
</code></pre>

<p>Create a file in your web root (in the example above, /var/www/nginx-default/test.php):</p>

<pre><code>&lt;?php

phpinfo();
</code></pre>

<p>Visit the page in your browser and you should see the standard PHP info page. And you&#8217;re done.</p>

<p>Source: <a href="http://tomasz.sterna.tv/2009/04/php-fastcgi-with-nginx-on-ubuntu/">Aberration</a></p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/06/13/php-and-nginx-the-easy-way/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Authentication with CodeIgniter</title>
		<link>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/</link>
		<comments>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/#comments</comments>
		<pubDate>Sat, 21 Feb 2009 17:37:52 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[codeigniter]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=127</guid>
		<description><![CDATA[Here&#8217;s how I do some basic authentication for a controller in CodeIgniter. It basically consists of creating a new class that extends the default Controller class. You then sub-class this on any controller that requires authentication. Create your authentication controller in system/application/libraries and call it MY_Controller.php. It&#8217;s important that you prefix the controller name with [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s how I do some basic authentication for a controller in <a href="http://codeigniter.com/">CodeIgniter</a>. It basically consists of creating a new class that extends the default <code>Controller</code> class. You then sub-class this on any controller that requires authentication.</p>

<p><span id="more-127"></span></p>

<p>Create your authentication controller in <code>system/application/libraries</code> and call it <code>MY_Controller.php</code>. It&#8217;s important that you prefix the controller name with <code>MY_</code>, or whatever you have specified <code>$config['subclass_prefix']</code> as in your configuration.</p>

<pre><code>&lt;?php

class MY_Controller extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this-&gt;load-&gt;library('session');
        if (!$this-&gt;session-&gt;userdata('loggedin'))
        {
            header('Location: /sessions/login');
        }
    }
}
</code></pre>

<p>This basically checks if the session data for <code>loggedin</code> is set to <code>true</code>. If not, it&#8217;ll redirect the user to the <code>/sessions/login</code> URL. This means we have to create a basic controller to handle the sessions.</p>

<pre><code>&lt;?php

class Sessions extends Controller
{
    public function __construct()
    {
        parent::__construct();
        $this-&gt;load-&gt;library('session');
    }

    public function login()
    {
        $this-&gt;load-&gt;view('header');
        $this-&gt;load-&gt;view('sessions/login');
        $this-&gt;load-&gt;view('footer');
    }

    public function authenticate()
    {
        $this-&gt;load-&gt;model('user', '', true);
        if ($this-&gt;user-&gt;authenticate($this-&gt;input-&gt;post('username'), $this-&gt;input-&gt;post('password')))
        {
            $this-&gt;session-&gt;set_userdata('loggedin', true);
            header('Location: /');
        }
        else
        {
            header('Location: /sessions/login');
        }
    }

    public function logout()
    {
        $this-&gt;session-&gt;unset_userdata('loggedin');
        header('Location: /');
    }
}
</code></pre>

<p>The <code>login</code> view is a basic form with fields for <code>username</code> and <code>password</code> that submits to <code>/sessions/authenticate</code>. This controller then loads the user model and checks that a user with the username and password exists. If so, it sets the session data for <code>loggedin</code> to <code>true</code> and redirects the user back to the default controller. If not, it takes the user back to the login page.</p>

<p>Then to implement the authentication in a controller, simply do:</p>

<pre><code>&lt;?php

class SecretPlace extends MY_Controller
{
...
</code></pre>

<p>It&#8217;s a good idea to <a href="http://codeigniter.com/user_guide/libraries/sessions.html">store your session data in your database</a> and encrypt your cookies with <code>$config['sess_encrypt_cookie'] = TRUE;</code> in <code>config.php</code>. That way people won&#8217;t be able to snoop around and try to trick your application into thinking they&#8217;re authenticated.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Quick lighttpd, PHP, iMagick setup on Ubuntu 8.10 Intrepid</title>
		<link>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/</link>
		<comments>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 17:17:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/</guid>
		<description><![CDATA[Install lighttpd: sudo aptitude install lighttpd Install PHP and ImageMagick: sudo aptitude install php5-common php5-dev php5-mysql php5-sqlite php5-cgi php5-curl php5-gd php-pear libmagick9-dev Install iMagick: sudo pecl install imagick Press enter on prompt. Add the following to the bottom of /etc/php5/cgi/php.ini: extension=imagick.so Then: sudo lighttpd-enable-mod fastcgi sudo /etc/init.d/lighttpd reload]]></description>
			<content:encoded><![CDATA[<p>Install <code>lighttpd</code>:</p>

<pre><code>sudo aptitude install lighttpd
</code></pre>

<p>Install <code>PHP</code> and <code>ImageMagick</code>:</p>

<pre><code>sudo aptitude install php5-common php5-dev php5-mysql php5-sqlite php5-cgi php5-curl php5-gd php-pear libmagick9-dev
</code></pre>

<p>Install <code>iMagick</code>:</p>

<pre><code>sudo pecl install imagick
</code></pre>

<p>Press enter on prompt.</p>

<p>Add the following to the bottom of <code>/etc/php5/cgi/php.ini</code>:</p>

<pre><code>extension=imagick.so
</code></pre>

<p>Then:</p>

<pre><code>sudo lighttpd-enable-mod fastcgi
sudo /etc/init.d/lighttpd reload
</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2009/01/17/quick-lighttpd-php-imagick-setup-on-ubuntu-810-intrepid/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A simple PHP delicious REST example with pecl_http</title>
		<link>http://davidwinter.me.uk/articles/2008/11/24/a-simple-php-pecl_http-example-with-delicious/</link>
		<comments>http://davidwinter.me.uk/articles/2008/11/24/a-simple-php-pecl_http-example-with-delicious/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 21:39:27 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[delicious]]></category>
		<category><![CDATA[example]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[pecl_http]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[rest]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=119</guid>
		<description><![CDATA[&#60;?php $username = 'your_username'; $password = 'your_password'; $url = "https://$username:$password@api.del.icio.us/v1/posts/recent"; $request = new HttpRequest($url, HTTP_METH_GET); $response = $request-&#62;send(); print $response-&#62;getBody(); ?&#62; You&#8217;ll probably need to view the source in your browser to see the output. The second argument isn&#8217;t required in this call, because HttpRequest defaults to a GET request anyway, but it&#8217;s just helpful [...]]]></description>
			<content:encoded><![CDATA[<pre><code>&lt;?php

$username = 'your_username';
$password = 'your_password';
$url = "https://$username:$password@api.del.icio.us/v1/posts/recent";

$request = new HttpRequest($url, HTTP_METH_GET);
$response = $request-&gt;send();
print $response-&gt;getBody();
?&gt;
</code></pre>

<p>You&#8217;ll probably need to view the source in your browser to see the output.</p>

<p>The second argument isn&#8217;t required in this call, because <code>HttpRequest</code> defaults to a <code>GET</code> request anyway, but it&#8217;s just helpful to see where you can specify the different HTTP methods. The others being, post, put and delete.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2008/11/24/a-simple-php-pecl_http-example-with-delicious/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install pecl_http for PHP</title>
		<link>http://davidwinter.me.uk/articles/2008/11/24/install-pecl_http-for-php/</link>
		<comments>http://davidwinter.me.uk/articles/2008/11/24/install-pecl_http-for-php/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 21:33:41 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[macports]]></category>
		<category><![CDATA[osx]]></category>
		<category><![CDATA[pecl_http]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=117</guid>
		<description><![CDATA[You will probably want to ensure that curl supports https before getting underway: curl -V Check that the output contains https: &#62;: curl -V curl 7.19.2 (i386-apple-darwin9.5.0) libcurl/7.19.2 OpenSSL/0.9.8i zlib/1.2.3 Protocols: tftp ftp telnet dict http file https ftps Features: Largefile NTLM SSL libz If it doesn&#8217;t: sudo port deactivate curl sudo port install curl [...]]]></description>
			<content:encoded><![CDATA[<p>You will probably want to ensure that <code>curl</code> supports <code>https</code> before getting underway:</p>

<pre><code>curl -V
</code></pre>

<p>Check that the output contains <code>https</code>:</p>

<pre><code>&gt;: curl -V
curl 7.19.2 (i386-apple-darwin9.5.0) libcurl/7.19.2 OpenSSL/0.9.8i zlib/1.2.3
Protocols: tftp ftp telnet dict http file https ftps 
Features: Largefile NTLM SSL libz
</code></pre>

<p>If it doesn&#8217;t:</p>

<pre><code>sudo port deactivate curl
sudo port install curl +ssl
</code></pre>

<p>Once you have <code>curl</code> with <code>https</code> support:</p>

<pre><code>sudo pecl install pecl_http
</code></pre>

<p>If you followed my previous <a href="/articles/2008/11/22/php5-lighttpd-and-imagick-on-mac-os-x-leopard/">howto</a>, you&#8217;ll want to move the module to the location specified in your <code>php.ini</code> file:</p>

<pre><code>sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20060613/http.so /opt/local/lib/php/extensions
</code></pre>

<p>Restart <code>lighttpd</code> and then you&#8217;ll be good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2008/11/24/install-pecl_http-for-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install PHP5, lighttpd and Imagick on Mac OS X Leopard</title>
		<link>http://davidwinter.me.uk/articles/2008/11/22/php5-lighttpd-and-imagick-on-mac-os-x-leopard/</link>
		<comments>http://davidwinter.me.uk/articles/2008/11/22/php5-lighttpd-and-imagick-on-mac-os-x-leopard/#comments</comments>
		<pubDate>Sat, 22 Nov 2008 19:51:23 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[imagick]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[mac]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=101</guid>
		<description><![CDATA[It&#8217;s a little tricky getting a nice clean install of PHP5 for OS X 10.5. The packages that I always used to depend on over at Entropy don&#8217;t seem to work anymore. At least not for Leopard. A great shame. I&#8217;m now switching to lighttpd for my development server, so have come up with the [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s a little tricky getting a nice clean install of <a href="http://www.php.net">PHP5</a> for OS X 10.5. The packages that I always used to depend on over at <a href="http://www.entropy.ch/software/macosx/php/">Entropy</a> don&#8217;t seem to work anymore. At least not for Leopard. A great shame.</p>

<p>I&#8217;m now switching to <a href="http://www.lighttpd.net">lighttpd</a> for my development server, so have come up with the following recipe to install PHP5 and the great <a href="http://www.php.net/imagick">Imagick</a> extension for image manipulation.</p>

<p><span id="more-101"></span></p>

<p>Follow these instructions at your own risk! They worked fine on my setup but I can&#8217;t guarantee they will for you.</p>

<ol>
<li>Install <a href="http://developer.apple.com/technology/xcode.html">Xcode</a>.</li>
<li>Install <a href="http://www.macports.org/">MacPorts</a>.</li>
<li><p>Now update MacPorts:</p>

<pre><code>sudo port selfupdate
</code></pre></li>
<li><p>Install lighttpd:</p>

<pre><code>sudo port install lighttpd
</code></pre>

<p>Install the startup item and copy the default configuration file:</p>

<pre><code>sudo launchctl load -w /Library/LaunchDaemons/org.macports.lighttpd.plist
sudo cp /opt/local/etc/lighttpd/lighttpd.conf.default /opt/local/etc/lighttpd/lighttpd.conf
</code></pre></li>
<li><p>Now we install PHP with the FastCGI, MySQL and Pear variants.</p>

<pre><code>sudo port install php5 +fastcgi +mysql5 +pear
</code></pre>

<p>In order for this to work, I had to disable the port <code>perl5.8</code> by using the following command:</p>

<pre><code>sudo port deactivate perl5.8
sudo port activate perl5
</code></pre>

<p>Then run the command again and it should succeed:</p>

<pre><code>sudo port install php5 +fastcgi +mysql5 +pear
</code></pre></li>
<li><p>Copy over the default PHP configuration:</p>

<pre><code>sudo cp /opt/local/etc/php.ini-dist /opt/local/etc/php.ini
</code></pre></li>
<li><p>Now open up the PHP configuration file:</p>

<pre><code>sudo mate /opt/local/etc/php.ini
</code></pre>

<p>Add the following line to the file:</p>

<pre><code>cgi.fix_pathinfo=1
</code></pre>

<p>Find <code>extension_dir = "./"</code> and replace it with:</p>

<pre><code>extension_dir = "/opt/local/lib/php/extensions"
extension=imagick.so
</code></pre></li>
<li><p>Edit the lighttpd configuration file:</p>

<pre><code>sudo mate /opt/local/etc/lighttpd/lighttpd.conf
</code></pre>

<p>Ensure that the following is uncommented:</p>

<pre><code>fastcgi.server = ( ".php" =&gt;
    ( "localhost" =&gt;
        (
            "socket" =&gt; "/var/run/lighttpd/php-fastcgi.socket",
            "bin-path" =&gt; "/opt/local/bin/php-cgi"
        )
    )
)
</code></pre>

<p>And also make lighttpd run as the user <code>www</code>:</p>

<pre><code>server.username = "www"
server.groupname = "www"
</code></pre>

<p>Add the following if you want to be able to use your <code>Sites</code> directory in your home directory. I also changed the default document root to the OS X default:</p>

<pre><code>server.modules += ("mod_userdir")
userdir.path = "Sites"
userdir.basepath = "/Users/"
server.document-root = "/Library/WebServer/Documents"
</code></pre>

<p>Ensure that <code>"mod_fastcgi",</code> is uncommented.</p></li>
<li><p>Now we need to setup a few directories, and make the user <code>www</code> the owner for them:</p>

<pre><code>sudo mkdir /var/run/lighttpd
sudo mkdir /var/log/lighttpd
sudo chown www:www /var/run/lighttpd
sudo chown www:www /var/log/lighttpd
</code></pre></li>
<li><p>Now install ImageMagick:</p>

<pre><code>sudo port install imagemagick
</code></pre></li>
<li><p>Now we need to download the Imagick PHP module. I was hoping this would be as easy as <code>sudo pecl install imagick</code>, however I got an error for that, and so a manual build and install of the module is necessary:</p>

<pre><code>curl -O http://pecl.php.net/get/imagick-2.2.1.tgz
tar xvfz imagick-2.2.1.tgz
cd imagick-2.2.1/
phpize
./configure --with-imagick=/opt/local
make
sudo make install
sudo cp /opt/local/lib/php/extensions/no-debug-non-zts-20060613/imagick.so /opt/local/lib/php/extensions
</code></pre></li>
</ol>

<p>And finally, you can then run LightTPD with the following. The <code>-D</code> flag tells lighttpd not to run in the background&#8211;you don&#8217;t need to use it:</p>

<pre><code>lighttpd -f /opt/local/etc/lighttpd/lighttpd.conf -D
</code></pre>

<p>You should then be able to visit a PHP file in your browser to test that it works. A simple test file would be:</p>

<pre><code>&lt;?php
$img = new Imagick('pic.jpg');
$img-&gt;rotateImage('#fff', 45);
header('Content-type: image/jpeg');
echo $img;
?&gt;
</code></pre>

<p>This is just a simple Imagick rotate on an image.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2008/11/22/php5-lighttpd-and-imagick-on-mac-os-x-leopard/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>lighttpd and PHP on CentOS 5</title>
		<link>http://davidwinter.me.uk/articles/2008/06/22/lighttpd-and-php-on-centos-5/</link>
		<comments>http://davidwinter.me.uk/articles/2008/06/22/lighttpd-and-php-on-centos-5/#comments</comments>
		<pubDate>Sun, 22 Jun 2008 15:34:14 +0000</pubDate>
		<dc:creator>David</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[centos]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[lighttpd]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://davidwinter.me.uk/?p=96</guid>
		<description><![CDATA[Here&#8217;s a quick run down on getting lighttpd and php running on CentOS 5. yum install lighttpd lighttpd-fastcgi php mkdir /var/run/lighttpd touch /var/run/lighttpd/php-fastcgi.socket chown -R lighttpd:lighttpd /var/run/lighttpd/ vim /etc/php.ini Add in php.ini the following; cgi.fix_pathinfo = 1. Save and close the file. Now open up /etc/lighttpd/lighttpd.conf. Uncomment the following line "mod_fastcgi", from the server.modules option. [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a quick run down on getting <a href="http://www.lighttpd.net/">lighttpd</a> and <a href="http://php.net">php</a> running on <a href="http://www.centos.org/">CentOS 5</a>.</p>

<pre><code>yum install lighttpd lighttpd-fastcgi php
mkdir /var/run/lighttpd
touch /var/run/lighttpd/php-fastcgi.socket
chown -R lighttpd:lighttpd /var/run/lighttpd/
vim /etc/php.ini
</code></pre>

<p>Add in <code>php.ini</code> the following; <code>cgi.fix_pathinfo = 1</code>. Save and close the file.</p>

<p>Now open up <code>/etc/lighttpd/lighttpd.conf</code>. Uncomment the following line <code>"mod_fastcgi",</code> from the <code>server.modules</code> option. Then ensure that the following is uncommented:</p>

<pre><code>fastcgi.server  = ( ".php" =&gt;
    ( "localhost" =&gt;
        (
            "socket" =&gt; "/var/run/lighttpd/php-fastcgi.socket",
            "bin-path" =&gt; "/usr/bin/php-cgi"
        )
    )
)
</code></pre>

<p>Save the file. Now create a test file, <code>/srv/www/lighttpd/index.php</code> and just include <code>&lt;?php phpinfo(); ?&gt;</code>. Now open your <a href="http://getfirefox.com">favourite browser</a> and visit <a href="http://localhost/index.php">http://localhost/index.php</a>. You should be greeted with a friendly PHP page, and you&#8217;re set to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://davidwinter.me.uk/articles/2008/06/22/lighttpd-and-php-on-centos-5/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
