nginx as webserver

A very good alternative to Apache is nginx. It’s gaining popularity and is being used on big sites such as Facebook. I have decided to use Apache instead of nginx, because it is much more simpler to configure. Caching plugins require some extra configuration or they will not even work. You are most welcome to try to modify the nginx settings to work with caching plugins, especially Quick cache that is working really great with the Raspberry weather plugin.

If you have already installed Apache, you are all set, skip this step to avoid trouble!
Start with updating your dependencies if you forgot to do that in the beginning – apt-get update. After all gets loaded, its time to install the required packages. You will be installing nginx and some php5 packages which are essential. Type in apt-get install nginx php5-fpm php5-cgi php5-cli php5-common php5-mysql. Next install MySQL server with apt-get install mysql-server mysql-common mysql-clientAfter everything gets installed, you need to start up the nginx service. Do that by service nginx start. The service should get started correctly and now you need to check if all is working. Open up a browser on your computer and type in the IP of the Raspberry Pi. If you do not know the IP, it is displayed if you type in ifconfig. When the page opens, you will hopefully get a html page with some text, that nginx is up and running. Now comes the configuration part that I mentioned previously. Modify the default file which holds some settings for your homepage nano /etc/nginx/sites-available/default. For starters, go to the line below  root /usr/share/nginx/www;.     Support for php files needs to be added, add index.php after index.html. Do not change anything else in that line. You should see some # symbols, which represent comments. You will be removing some of them next. Use search to find a line starting with  pass the PHP scripts  and go two lines below, to the  location ~ \.php$ { . This block will be used in your configuration, so remove the # symbol. Remove  the same symbol for the next line fastcgi_split_path_infoMove down until you get to the line which starts with fastcgi_pass unix. Remove the comment here and also in the lines starting with fastcgi_index and include fastgi_params. Please do not forget to uncomment the closing curly brace. Almost done, just the part that denies access to .htaccess files awaits us. Uncomment the lines that start with location ~ /\ followed by deny all; and lastly the closing curly brace. Save the file and exit by pressing ctr+x and saving the file. The new changes are still not in place, you have to restart the service. Type in service nginx restart. Okay, last step, you are done with the hard part. You need to navigate to cd /usr/share/nginx/www. This directory holds the contents that are displayed on the internet. Create a test file with nano test.php. Now you need to put in some php code to test everything out. The file needs to contain <?php phpinfo(); ?>. Again, go to your browser with the IP of the Raspberry Pi. After the IP add /test.php for example After the page loads, you will be presented with some php information. That means all is working and you can move on ahead. If you’re planning on using WordPress, do not forget to take ownership of the folder that contains WordPress files. You do that with the sudo chown -R www-data:www-data /usr/share/nginx/www/ command. It is also good if you enable pretty permalinks on your website. To do that, you need to modify the configuration a little bit. Search the configuration for try_files $uri $uri/ /index.html; and change it to try_files $uri $uri/ /index.php?q=$uri&$args;. After that you can enable permalinks with /%postname%/.