12/20/11

Running Mediawiki on Mac OS X using NGINX

This is a quick run down on getting Mediawiki running on Mac Os X utilizing brew and recipes for nginx (Engine X), MySQL, and PHP. 


This assumes you bothered to go through the brew installation process:
https://github.com/mxcl/homebrew/wiki/installation


Install nginx and MySQL
sudo brew install mysql nginx
While you are waiting prep the Mediawiki directory


Download and extract mediawiki
sudo mkdir -p /var/www/curl -s http://dumps.wikimedia.org/mediawiki/1.18/mediawiki-1.18.0.tar.gz  | sudo tar zxfv - -c /var/www/sudo ln -s /var/www/mediawiki-1-18.0 /var/www/mediawiki
*I like to keep track of what version I am on, hence the symlink

Install PHP
Use a non-standard PHP recipe to install PHP.


*This must be done after the previous brew command finishes. 
brew install https://raw.github.com/ampt/homebrew/php/Library/Formula/php.rb --with-mysql
Start php in fast cgi mode
sudo php-cgi -b /tmp/php-fcgi.sock 
Unfortunately this hasn't been merged in to the brew upstream. 


Configure MySQL
Some initial setup that you will need to perform before you can start the MySQL server.

Install the basic tables MySQL requires

/usr/local/bin/mysql_install_db --basedir=/usr/local/  --datadir=/usr/local/var/mysql/ 
*Since brew links these files in to your /usr/local it may look weird but rest assured they are easily removed using the brew package system. 

Start mysql

/usr/local/bin/mysqld

That's it for MySQL server it should now be running, the default password is nothing so keep this in mind.



Test it is running by connecting to the server locally
/usr/local/bin/mysql -u root 
Configure nginx


Edit /usr/local/etc/nginx/nginx.conf and add in the following server definitions:
server {
        server_name wiki.mine.org;
        root /var/www/mediawiki;

        client_max_body_size 5m;
        client_body_timeout 60;

        location / {
                try_files $uri $uri/ @rewrite;
        }

        location @rewrite {
                rewrite ^/(.*)$ /index.php?title=$1&$args;
        }

        location ^~ /maintenance/ {
                return 403;
        }

        location ~ \.php$ {
                include fastcgi_params;
                fastcgi_pass unix:/tmp/php-fcgi.sock;
        }

        location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
                try_files $uri /index.php;
                expires max;
                log_not_found off;
        }

        location = /_.gif {
                expires max;
                empty_gif;
        }

        location ^~ /cache/ {
                deny all;
        }

        location /dumps {
                root /var/www/mediawiki/local;
                autoindex on;
        }
}
Edit /usr/local/etc/nginx/fastcgi_params 


Under:
fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;


Add in:
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;


**If you do not do this you will see an error like: "No input file specified." when you try to go to the server.


Start NGINX
sudo /usr/local/sbin/nginx

Start up daemons and Configure
Throughout the doc there are some daemons that you need to start, I am will list them here again:


Mysql 
sudo /usr/local/bin/mysqld
NGINX
sudo /usr/local/sbin/nginx
PHP Fast CGI Support
sudo php-cgi -b /tmp/php-fcgi.sock 
Now point your browser at: http://localhost


That is it!!, perhaps if I am feeling up to it later I will write an article on plists so that all the daemons start automatically on reboot. 


Security Notes
This is the quick and the dirty. I am not add users, configuring things to run as non-admin accounts, and setting permissions on files properly. THESE ARE ALL THINGS YOU SHOULD DO!

6 comments: