afurlan's blog

/^random (nerd|geek)? posts$/

Nginx and PhpLdapAdmin

Monday, May 24, 2010 - No comments

I usually run Apache in my web servers, it works pretty well but spends too much memory for that. So I decided to give a try to the Nginx and for now, I'm really impressed about its preformance.

I don't intend to present Nginx at this post, but if you want to know more about it (and IMHO, you should) go to its official documentation. I'm going to show how to configure the PhpLdapAdmin and Nginx but not how to install the PHP itself. So I'll presume you currently have PHP working on Nginx but if you don't, take a look at here to know how to do that using the spawn-fcgi.

Let's start installing the PhpLdapAdmin and the PHP5 module to connect to the LDAP server. If you're using Debian/Ubuntu, all new software are just an "aptitude install" of distance from you, so let's install them:

$ aptitude install phpldapadmin php5-ldap

Now we can start the PhpLdapAdmin on Nginx configuration itself... You can use the PhpLdapAdmin under a specific domain or use it as a standalone application. If you want to install the PhpLdapAdmin under a specific domain, you should create a new virtual host named example.com as follows:

$ vim /etc/nginx/sites-available/example.com
server {
    server_name example.com;
    listen 80;

    # document root
    root /usr/share/phpldapadmin/htdocs;
    index index.php index.html index.htm;

    # application: phpldapadmin
    location ~ \.php$ {
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root/$fastcgi_script_name;
            include fastcgi_params;
            fastcgi_param HTTPS on;
    }

    # logging
    error_log /srv/example.com/nginx/log/error.log;
    access_log /srv/example.com/nginx/log/access.log;
}

Or if you want to install the PhpLdapAdmin as a standalone application, you should create a new virtual host as follow:

$ vim /etc/nginx/sites-available/example.com
server {
    server_name example.com;
    listen 80;

    # document root
    root /srv/example.com/nginx/www;
    index index.php index.html index.htm;

    # application: phpldapadmin
    location /phpldapadmin {
            alias /usr/share/phpldapadmin/htdocs;
            index index.php index.html index.htm;
    }
    location ~ ^/phpldapadmin/.*\.php$ {
            root /usr/share;
            if ($request_filename !~* htdocs) {
                    rewrite ^/phpldapadmin(/.*)?$ /phpldapadmin/htdocs$1;
            }
            fastcgi_pass 127.0.0.1:9000;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME $request_filename;
            include fastcgi_params;
    }

    # logging
    error_log /srv/example.com/nginx/log/error.log;
    access_log /srv/example.com/nginx/log/access.log;
}

And now, we can just enable the new virtual host and restart Nginx:

$ cd /etc/nginx/sites-enabled
$ ln -s ../ldap.example.com
$ /etc/init.d/nginx restart

No, this blog isn't running over nginx (yet). It's a Python (Django) application, so I want to migrate it ASAP and test a new setup based on Nginx + Gunicorn following a recomendation of Osvaldo Santana... but for now, that's all. :)

As always: if you found some english bug, warn me and I'll be glad to fix it. :)

Comments

Trackbacks