Installing MySQL for PHP with MacPorts

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:

(more…)

2010-02-28 [, , ]
View Comments

Apache, PHP and MongoDB on Mac OS X 10.6 Snow Leopard

MongoDB (from “humongous”) is a scalable, high-performance, open source, schema-free, document-oriented database.

There’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 developer tools (found on the Snow Leopard install DVD) and MacPorts for this to all work.

(more…)

Remove startup scripts on Ubuntu

sudo update-rc.d -f script_name remove
2009-10-20 [, , ]
View Comments

Convert git repository to mercurial

Ensure that the mercurial convert extension is enabled:

nano ~/.hgrc

Inside that file add:

[extensions]
hgext.convert=

Save. Now do:

hg convert my-git-repo

This will create a new directory called my-git-repo-hg. This will appear empty at first, so do this:

cd my-git-repo-hg
hg checkout

All of your files will appear and you’re ready to go.

2009-10-17 [, , ]
View Comments

Enable PHP error logging

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
2009-07-14 [, ]
View Comments

PHP and nginx on Ubuntu: the easy way

I’ve now changed my slice from running lighttpd to nginx. Here’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
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

Make start-up script executable:

sudo chmod +x /etc/init.d/php-fastcgi

Launch PHP:

sudo /etc/init.d/php-fastcgi start

Launch at start-up:

sudo update-rc.d php-fastcgi defaults

That’s it. All installed and ready to go.

Test

In your server config, add the following:

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;
}

Restart nginx:

sudo /etc/init.d/nginx restart

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

<?php

phpinfo();

Visit the page in your browser and you should see the standard PHP info page. And you’re done.

Source: Aberration

2009-06-13 [, , , ]
View Comments

Applescript to shutdown in 15 seconds

set userCancelled to false

try
    set answer to display dialog "Backup complete. Shutting down in 15 seconds." giving up after 15
on error number -128
    set userCancelled to true
end try

if userCancelled then

else if gave up of answer then
    tell application "Finder"
        shut down
    end tell
end if
2009-05-28 [, , ]
View Comments