How to setup a Nginx Server (LEMP Stack)
Setup an Ubuntu Server with only the
- [x] Essential Services
- [x] SSH Server
Login as root
Lets start with an update
apt-get update apt-get upgrade
To secure your server a bit. Edit ssh and change the default port
Change ‘port 22’ to whatever port you wish to use then…
service ssh reload
(you can now login like this: ssh firstname.lastname@example.org -p portyouchose )
We now begin setting up the actual server components starting with MySQL
apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql
(you will be prompted to enter your password here: lets call that passwordA)
Now MySQL is installed lets configure for production use.
It my ask for the root password: enter passwordA which you entered above.
Do you want to change password: N
Remove Anonymous Users: Y
Disallow Root Login Remotely: Y
Remove test Database: Y
Reload Tables: Y
All done!! At Least with MySQL
During the installation of MySQL an apache server may have been setup.. since we want LEMP (we need to uninstall apache2 and install Nginx) do that with
service apache2 stop apt-get purge apache2 apache2-utils apache2.2-bin apache2-common apt-get autoremove
apt-get install nginx service nginx start
(you can do a ‘ifconfig’ to get ip address and test out server in your browser)
On to the last part. Installing PHP.
apt-get install php5-fpm
And configure it..
vim /etc/php5/fpm/php.ini # you may use nano if u wish (nano /etc/php...)
find ‘cgi.fix_pathinfo=1’ and replace with ‘cgi.fix_pathinfo=0’ – this makes PHP not ‘guess’ what urls users are trying to go to (added security)
and restart php
service php5-fpm restart
Well.. thats about it.. your html files are at /usr/share/nginx/www
For added security you can install denyhosts
apt-get install denyhosts
apt-get install phpmyadmin
Enjoy your new high performance and secure Nginx server.