I would not try to answer this question but rather have you visit some of these links
- http://www.wikivs.com/wiki/apache_vs_nginx#Performance
- http://wiki.dreamhost.com/Web_Server_Performance_Comparison
- http://www.thegeekstuff.com/2013/11/nginx-vs-apache/
If you could make sense of what was there and further intrested having your own HIGH PERFORMANCE webserver with awesome cost savings too, read on.
Step 1 : Selecting a reliable (Economical, FAST) server (Service Provider)
- I have made a small search of my own, you can start by clicking here.
- Register above - yes its just $5 (Approx ₹320) per month OR $60 (Approx ₹3,600) per year
- Comapre this with Shared Hosting plans with Go-Daddy etc
- Yes you have VPS at the cost of Shared Hosting
- Before you say i'm lazy and dont want the risk... DID I MENTION SSD
- Yes the Host I am recommending runs on Sold State Disks (aka Flash Hard Disks - read BLAZINGLY Fast)
Step 2 : Installation
- Assuming you have managed to sign up / and logged in via SSH
- Now paste the following Sequence of commands
sudo apt-get update
sudo apt-get install mysql-server php5-mysql
sudo mysql_install_db
sudo apt-get install nginx
sudo service nginx start
sudo apt-get install php5-fpm
- Well we first refreshed the package list, installed MySQL, nginX, php5
- You will be prompted to set a MySQL Root password - Be smart - Set It (Do remember or securely keep a note of it). You will still be prompted in a next step to change.
- Note : we have just installed the base software, not exactly fully configured / to work with each other or even secured our server.
Step 3 : Configuration / Securing
- Securing MySQL
sudo /usr/bin/mysql_secure_installation
Well please follow the instructions (say yes yes yes) to Remove Anonymous Users, Disable Remote Root Login, Remove Test Database and reload the Privilages to apply changes immidiately.
NOTE: If you were smart to set a good ROOT PASSWORD for MYSQL in the previous step - GOOD, no need to change it. But if you have something like your phone number or somthing very simple - better secure it.
- Checking if nginX is running
ifconfig eth0 | grep inet | awk '{ print $2 }'
You just see an (server's) ip address - works 99 % of the time if you started out with a fresh Ubuntu install (i.e. just OS, nothing else). useful for testing in the other non ideal senarios.
- Getting PHP to work with nginX
- with newer releases / Installs this is usually already done
In the file - /etc/php5/fpm/php.ini change cgi.fix_pathinfo=1 to cgi.fix_pathinfo=0 (Generally Line commented, just uncomment)
In the file - /etc/php5/fpm/pool.d/www.conf ensure the "listen=" value is listen = /var/run/php5-fpm.sock (Generally its already done)
Restart the PHP5-fpm Service -- sudo service php5-fpm restart
Note : Remember the path to php.ini file - when certian apps ask you to change some settings etc, this is where to go to.
- A little fix for nginX
- Nothing like a fix as such, but just configuring nginX('s) web folders, telling it to handle .php pages, create virtual hosts etc.
- If you have used Apache earlier - this is no different, Just Download my Reference configuration files (you can replace files on your server directly with mine, but do understand some minor changes that are needed)
The folder - /etc/nginx/sites-available/ contains all the available sites (virtual + default) and their configurations
The folder - /etc/nginx/sites-enabled/ contains symbolic links to files in the "sites-available" folder. PS: files/sites here are enabled
Restart nginX everytime you want changes in configuration enabled using - sudo service nginx restart
Note : Just to have our life simpler we can change the path to the web folder to /opt/apps/<my_fancy_site> to have all the virtual sites organised in one easily accessible place
- Upating the /etc/hosts file
- Other Instruction / How-to manuals tend to leave this out
- you updated the listen line to listen 80 myDomain.COM; in the virtual host file and now NginX does not (start) restart.
- well just add your IP and domain name into the hosts file
Making Life Simple (for the NEWBIES)
- Editing files
- Just use any text editor you are comfortable like nano , vi etc (google to find instrutions on usage, NOTE : since most of the files that we edit belongs to root, ensure to prefix sudo before opening files)
- Changing permissions
- We have not yet created users and still wroking as root / added users to the www-data group, we do end up often where php cannot write files (like running a update in your favourite CMS etc.
- chown -R <user/group> folder Ex. chown -R www-data /opt/apps/www
- yes the -R means recursive.
- Creating Symbolic links
- Remember i did mention Symbolic Links for virtual hosts in nginX folder earlier ...
- ln -s <link to existing file/folder path> <the symbolic file/folder path> Ex. ln -s /etc/nginx/sites-available/mysite /etc/nginx/sites-available/mysite
- Deleting Files / Directories
- Delete Files : rm <file name>
- Remove Directory (with its contents) : rm -rf <directory name>
- move file : mv