Configure Nginx for Codeigniter

Recently I was experimenting with unmanaged VPS servers for a new project. To work locally I generally use Apache2 in Fedora but after studying some articles about the efficiency of Nginx I wanted to give it a try. So I installed Nginx v1.4.6 in Ubuntu server edition.

Just like other Ubuntu packages install it by typing sudo apt-get install nginx in terminal , before the installation you should run a system update to avoid compatibility issues.

nginx+codeigniter

As you know Codeigniter is a php based web application development framework, installation of php is also required to get started. To save time it’s better to install php along with some essential modules. Below there is a list of modules I have installed.

Essential PHP Modules:

  • PHP5-MYSQL
  • PHP5-GD
  • PHP5-CURL
  • PHP5-XMLRPC

To get a full list of available php modules in Ubuntu repository try aptitude search php5- command and choose from them according to your purpose.

Now comes the most tricky part, unlike Apache2 , Nginx does not able to handle php requests as it was developed to handle static content. With a application called PHP-FPM all the requests can be forwarded from server to PHP. Up to this part everything was very easy for me, but also after installing PHP5-FPM I was still getting error from server. In search of a quick fix, I Googled  with the error code Nginx was showing.

There were some mis-configuration in server configuration file. I tried a lots of config files from different websites to solve the issue but results were not fruitful. Finally after some experiments and trial and errors I got a config that was able to run Codeigniter without any issue. (Mod_rewrite rules also work fine). If you are facing same kind of trouble with Nginx try the following configuration with necessary modifications( like change the domain name & directory location) and share your feedback with me.

For more server related guides, visit daily.

Leave a Comment