CentOS - Installing Nginx via yum

Nginx is a popular lightweight server for those who do not need the bulk and extra services that Apache may offer.

This article will look at installing Nginx on a CentOS Slice using the 'yum' package manager.


Yum

Using the inbuilt package manager to install packages is a great idea as it solves dependency issues and you are assured of any security updates if, and when, they occur.

However, one drawback can be that it is rare for a version upgrade to be placed into the repositories. As such, it is possible for a newer version of an application to be released and not be placed into the repository.

EPEL

To install Nginx using yum we will need to include the EPEL (Extra Packages for Enterprise Linux) repository. This repository was developed by the Fedora community to provide extra add-on packages for Fedora-based Redhat Enterprise Linux and it's other compatible offspring such as CentOS.

One thing to keep in mind when adding extra repositories is that many include newer versions of packages that are readily available through the standard channels. This can cause problems as packages can be automatically upgraded and cease to function as expected.

I want to make it clear that the EPEL repository is purely complimentary and only provides additional packages that are otherwise unavailable through the default repositories.

Versions

Using yum in conjunction with the EPEL repository, CentOS will install Nginx version 0.6.33.

However, at the time of writing, the latest stable version of Nginx is 0.6.34. You can check the latest versions and change logs at the main nginx site.

Which one you choose is, of course, entirely up to you.

If you decide you would rather have a later version of Nginx than the one the EPEL repository provides, then please refer to the sister article (link on the way) which will take you through the process of installing Nginx from source.

Installation and Dependencies

Let's begin by installing the EPEL repository:

sudo rpm -Uvh http://download.fedora.redhat.com/pub/epel/5Server/x86_64/epel-release-5-3.noarch.rpm

Installing nginx using Yum is now incredibly simple, thanks to EPEL, as it involves one command:

sudo yum install nginx

As this will be the first package we install using EPEL, we will be asked to import the EPEL gpg-key.

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6
Importing GPG key 0x217521F6 "Fedora EPEL <epel@fedoraproject.org>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL
Is this ok [y/N]:

This key is used to sign all packages that are associated with the EPEL repository to verify their validity.

Once the gpg-key has been imported, the installation should proceed as expected.

This will install any dependencies that Nginx requires and actually incorporates the experimental Perl module. You can read more documentation about this feature as well as many others at Nginx's English Wiki.

Start

One odd thing is that Nginx is not started automatically:

sudo /etc/init.d/nginx start

Done

Navigate

Now simply navigate to your IP address:

http://123.45.67.890

and you will see the following welcome screen:

Nginx Welcome Screen

Init Scripts

As you would imagine when installing an application with the yum package manager, all init scripts have been created.

However, we need to set up Nginx to start automatically if the slice is rebooted:

sudo /sbin/chkconfig nginx on

Controlling nginx is done with these commands:

sudo /etc/init.d/nginx start
...
sudo /etc/init.d/nginx stop
...
sudo /etc/init.d/nginx reload
...
sudo /etc/init.d/nginx restart

You can also check the current status as well as the configuration syntax by using the following commands:

sudo /etc/init.d/nginx status
...
sudo /etc/init.d/nginx configtest

The configtest option is particularly useful for testing your Nginx configuration before actually implementing it with a reload or restart.

That's it.

Summary

Using the yum package manager along with the EPEL repository makes the installation of Nginx and associated dependencies very simple indeed.

The only thing to consider is the version disparity between the one offered by yum and the one available via source code.

Mark

Article Comments:

Johny commented Wed Dec 31 18:54:49 UTC 2008:

Hi,

Thanks for the how-to.

How to integrate php and mysql with nginx ?

Dan commented Thu Jan 01 21:47:22 UTC 2009:

Just as a heads up for anyone having trouble getting php and nginx to work on centos, this tutorial actually helped me get it up and running after a few hours of pulling my hair out: http://howtoforge.org/installing-nginx-with-php5-and-mysql-support-on-fedora-10-p2

Philippe commented Wed Jan 28 10:35:18 UTC 2009:

I thank you very much for the GREAT articles.

Luka commented Sun Mar 08 23:01:40 UTC 2009:

Intresting i also finded this tutorial since there was a problem with installing nginx over yum into cent os using that howtorforge fedora tutorial.Now it works perfectly fine.

Cursors commented Wed Apr 22 18:25:01 UTC 2009:

Thanks for the article. I just learned about nginx and it looks very good. Better than apache at handlying files and connections.

dyazdizon commented Fri Jun 19 06:23:00 UTC 2009:

Very Thank, very helpful

Snake commented Sun Jul 12 21:53:18 UTC 2009:

Very usefull, i instaled the latest version of Nginx thanks to this tutorial.

xpert-zone commented Fri Jul 24 21:02:41 UTC 2009:

Can we do that side by side with apache?

innov8ion commented Fri Oct 02 20:02:28 UTC 2009:

I believe you can do it side by side with apache if they run on distinct ports or IP's. Adjust the conf files as necessary.

Erik commented Thu Oct 08 06:53:07 UTC 2009:

Thanks for taking the time to write this up.

Cursors commented Mon Jan 18 21:02:32 UTC 2010:

When you use YUM, what's being automatically installed? Just the core stuff? It won't install php mysql, or any other things will it?

Scott commented Tue Feb 09 01:12:07 UTC 2010:

Very helpful, as was Dan's link to configuring nginx with fast cgi. Many thanks.

Jam commented Sun Feb 14 23:55:21 UTC 2010:

No sou usuario de SliceHost, pero me a sido de mucha ayuda esta este articulo para cambiar el Apache2 de mi VPS por el fantastico Nginx :D

Muchas Gracias!!!

Want to comment?


(not made public)

(optional)

(use plain text or Markdown syntax)