tyler hoffman

my technological discoveries

Remove Apache2 - Install NGINX

So you want to remove Apache2 in favor of NGINX? You’ve come to the right place. This is a quick and to the point guide that should get you up and running with NGINX in no time. I am using Ubuntu 11.10 on a VPS, but this should work for most installations of Ubuntu. NOTE: This guide does not include how to install PHP. I did not need it so I did not end up installing it.


Remove Apache2

This first command will delete everything apache2 on the system. The second will delete the apache2 directory

1
2
$ sudo apt-get remove --purge apache2 apache2-utils
$ sudo rm -rf /etc/apache2

Install NGINX

The following commands will add NGINX’s repository so that you can install the most updated version.

1
2
3
$ sudo add-apt-repository ppa:nginx/stable
$ sudo apt-get update
$ sudo apt-get install nginx

If you get an error on the add-apt-repository command, execute the following command

1
$ sudo apt-get install python-software-properties

Configure NGINX

Last thing we will need to do is to go to the configuration file for NGINX. It is located in /etc/nginx/sites-available/default This section is only the first part of the config file.

/etc/nginx/sites-available/default
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
server {
  #listen   80; ## listen for ipv4; this line is default and implied
  #listen   [::]:80 default ipv6only=on; ## listen for ipv6

  root /path/to/website/dir;
  index index.html index.htm;

  # Make site accessible from http://localhost/
  server_name localhost;

  location / {
      # First attempt to serve request as file, then
      # as directory, then fall back to index.html
      try_files $uri $uri/ /index.html;
      # Uncomment to enable naxsi on this location
      # include /etc/nginx/naxsi.rules
  }

You will need to change lines 5 and 6. Line 5 will need the path to the directory of your website, and line 6 will be the types of index files located in the directory, whether they are index.php, .html, .htm etc.

To restart NGINX and make your changes take effect, the command to restart the service is necessary.

1
$ sudo /etc/init.d/nginx start

Enjoy

There you have it. The simplest guide I can make that shows how to uninstall Apache2 and install NGINX.