How to install NGINX + PHP 5.3 on FreeBSD.


I've not managed so far to get completely rid of php, so here's a simple reminder about how to install php on NGINX, for FreeBSD. Nothing hard, but that's worse to have the piece of configuration somewhere !

# update the ports
$ portsnap fetch update

# install php5 port
$ make config-recursive -C /usr/ports/lang/php5-extensions
$ make package-recursive -C /usr/ports/lang/php5-extensions

# install nginx
$ make config-recursive -C /usr/ports/www/nginx-devel
$ make package-recursive -C /usr/ports/www/nginx-devel

Now we have all the dependencies installed, we need to configure a bit the server.

That's a simple thing in fact, but it could be good to have something that will work without effort over time.

Here's a sample of my configuration:

server {
    server_name ndd;
    set $path /path/to/your/files;
    root   $path;

    location / {
        index  index.php;

    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
      access_log        off;
      expires           30d;

    location ~ .php$ {
        fastcgi_param  SCRIPT_FILENAME  $path$fastcgi_script_name;
        fastcgi_pass   backend;
        include fastcgi_params;

upstream backend {

And that's it !

Vous pouvez également télécharger cet article en pdf.