Friday, January 15, 2010

Install Nginx from source on Debian

I thought it was time to write a followup post to, Install Memcached from source on Debian Lenny.

At this moment, Debian provides Nginx 0.6.39 and I was wanting to run Nginx 0.7. The latest stable version is 0.7.64, so I thought I would put together a script to automate the download and installation for me.

Some devoted Debian users will want to string me up for installing a source package, and some others will no doubt say that I'm hating Debian for not using aptitude. These people are entitled to their opinion of course, but I don't feel that there is anything wrong with installing a source package on Debian.

If you feel like installing a package from source makes Debian cry, leave now :)




Permissions

On my system, my user has write permissions to /usr/local/src so I don't have to run everything under sudo.

You may need to set permissions for your system.

Install

A browser friendly version of the script can be seen at http://gist.github.com/274883.

This script should work on Debian Lenny, and Debian Etch. I think it would also work on Ubuntu.

By the way, I've found gists to be an excellent tool when automating source installs. Using gists makes it wasy to put any kind of script up on the net, as well as supporting config files as so on.

There is a link on that page to the "Raw" version of the script, which the script below will download and execute.

Gist Screenshot

To install, run this command...

# bash -c "`curl http://gist.github.com/raw/274883/e93ec7c38b303b759699e1023c8f6d2e60c93351/install_nginx_on_debian.sh`"

If all goes well, Nginx has been installed, started up, and set to start automatically at boot.

You can verify Nginx is running...
# ps -p `cat /var/run/nginx.pid`
  PID TTY          TIME CMD
15004 ?        00:00:00 nginx

Check that Nginx has been set to start at system boot.

# sudo sysv-rc-conf --list nginx
nginx        0:off 1:off 2:on 3:on 4:on 5:on 6:off

I'd love to hear if this was useful to you.

8 comments:

TJ said...

Nice work! I won't string you up for the source install :)

Scott Barr said...

Thanks for that TJ, I always thought asphyxiation for installing a package from a non apt source was a bit harsh. You're alright! :)

Mattia Trapani said...

Thanks, really helpful ;)

Unknown said...

A few basic newbish comments.

1. first apt-get install sudo
2. nginx default setting is to serve from /usr/local/nginx/html/

Great work!

Scott Barr said...

Hey Josh

Thanks for the comments.

Good point, I forgot sudo wasn't installed by default. The first thing I do with any server is install sudo :)

I might add a check for the sudo command in the script. The whole point of using sudo is to avoid running the entire script as root. Having "apt-get install sudo" in the actual script would require root privileges. I actually don't know the root password to any server I'm involved with.

I knew about the default location for nginx, but I always disliked serving web content from under /usr ... It feels dirty to me. /var is much more appropriate.

bacho said...

Usefull, still works, changing version variable with the lastest nginx 0.8.53

Buzzknow said...

hi,

could u combine this bash to include mysql, pureftpd?

thanks

Scott Barr said...

Hi @Buzzknow

I most definitely could, but in what way would that be fun for you? :)

I have actually created a project that consists of a number of discreet tasks to remotely install, configure and re-configure different "classes" of servers for some cloud based installations I work with. I can't give out that code though.

For example there is a task to entirely automate the installation and configuration of a new MySQL server.

It would be very easy to do what you're asking. Why not post a link to a bash script to do a MySQL install here in the comments?