How to always have the latest nginx version in Ubuntu/Debian


#1

I am attaching the procedure that we use to to always have the latest
nginx version in Ubuntu/Debian.

M.

– start-of-procedure

Install the current Nginx (Ubuntu 8.10 = Nginx/0.6.34 @ backports)

sudo aptitude -R install nginx= ; # the ending = means install & hold to
prevent automatic upgrades

install needed ubuntu/debian compiling tools

sudo aptitude -R install build-essential libpcre3 libpcre3-dev
libpcrecpp0 libssl-dev zlib1g-dev

build & replace by the latest “debianized” Nginx 0.7.44

test -x $HOME/src/ || mkdir -p $HOME/src/ && cd $HOME/src/

nginx’s latest version: http://sysoev.ru/nginx/download.html

wget http://sysoev.ru/nginx/nginx-0.7.44.tar.gz
tar zxvf nginx-0.7.44.tar.gz

cd nginx-0.7.44
./configure --prefix=/etc/nginx
–sbin-path=/usr/sbin/nginx
–conf-path=/etc/nginx/nginx.conf
–error-log-path=/var/log/nginx/error.log
–pid-path=/var/run/nginx.pid
–lock-path=/var/lock/nginx.lock
–user=www-data
–group=www-data
–http-log-path=/var/log/nginx/access.log
–http-client-body-temp-path=/var/lib/nginx/body
–http-proxy-temp-path=/var/lib/nginx/proxy
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi
–with-cc-opt=-O2
–with-http_gzip_static_module
–with-http_ssl_module

ensure that there is only one -O in CFLAGS and that it is -O2

sed -i ‘/CFLAGS/s/ -O //g’ objs/Makefile

make

debian policy: use ‘install’ instead of ‘cp’ or ‘mv’

sudo /usr/bin/install -s -m 755 -o root objs/nginx /usr/sbin/nginx.new
&& sudo mv /usr/sbin/nginx /usr/sbin/nginx.old-"$(date +%Y%m%d-%H%M-%S)"
&& sudo mv -v /usr/sbin/nginx.new /usr/sbin/nginx

sudo kill -15 $(pidof nginx) ; sudo /etc/init.d/nginx restart

– end-of-procedure


#2

What does this do?

ensure that there is only one -O in CFLAGS and that it is -O2


#3

Mark,

Why not just use apt-get source to get the source package of nginx; wget
the
latest nginx; copy the debian/ directory from the source package into
the
new nginx directory; edit the (dch) changelog, control file, etc;
rebuild
the package (debuild -rfakeroot), and install with dpkg?

That’s what I do, anyway. I recommend similar procedure with any
software
package – you can even use dh_make to create the debian/ directory for
any
particular source directory. Try this guide out:
http://david415.wordpress.com/2008/09/10/customdebianopensshpackagebuild/which
tells you how to make the debian package for latest openssl from
scratch - what I mentioned above is how to do it from the existing
package,
which is what you want in this case because it has all the init.d files
and
such for you!

There should be plenty of information around the net on building custom
debian packages, if you have trouble finding it, try checking out
debian-mentors (they have mailing list and IRC).

  • Merlin

#4

On Mon, Mar 23, 2009 at 2:48 PM, Merlin removed_email_address@domain.invalid wrote:

Mark,

Why not just use apt-get source to get the source package of nginx; wget the
latest nginx; copy the debian/ directory from the source package into the
new nginx directory; edit the (dch) changelog, control file, etc; rebuild
the package (debuild -rfakeroot), and install with dpkg?

I actually just do this. the .deb installs but issues warnings but it
does work well enough. but I do want to learn how to properly roll a
.deb someday :slight_smile:

root@local:/usr/src/build# cat build-nginx
#!/bin/sh

VER=“0.7.43”
BD=pwd
rm -rf nginx-${VER}
wget -c http://sysoev.ru/nginx/nginx-${VER}.tar.gz
tar xvfz nginx-${VER}.tar.gz
cd nginx-${VER}

./configure --conf-path=/etc/nginx/nginx.conf --prefix=/usr
–user=www-data --group=www-data
–error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid

–lock-path=/var/lock/nginx.lock
–http-log-path=/var/log/nginx/access.log
–http-client-body-temp-path=/var/lib/nginx/body
–http-proxy-temp-path=/var/lib/nginx/proxy
–http-fastcgi-temp-path=/var/lib/nginx/fastcgi
–with-http_stub_status_module
–with-openssl=/usr/lib --with-md5=/usr/lib
–with-http_gzip_static_module
–without-mail_pop3_module --without-mail_smtp_module
–without-mail_imap_module
–with-http_flv_module --with-http_ssl_module --with-http_dav_module
–with-http_realip_module --with-http_xslt_module
–with-debug
echo “\tcp /usr/src/build/nginx.initd /etc/init.d/nginx” >>objs/Makefile
echo “\tcp /usr/src/build/nginx.1.manpage /usr/local/man/man1/nginx.1”

objs/Makefile
echo “\tcp /usr/src/build/nginx.logrotate /etc/logrotate.d/nginx”

objs/Makefile
echo “\tupdate-rc.d -f nginx remove” >>objs/Makefile
echo “\tupdate-rc.d -f nginx defaults” >>objs/Makefile
make
mkdir -p doc-pak
mkdir -p /etc/nginx
checkinstall --pkgname=“custom-nginx” --pkgversion="$VER"
–provides=“nginx” --requires=“libc6, libpcre3, zlib1g” --strip=yes
–stripso=yes --backup=no -y --install=no
mv *.deb …
cd $BD
rm -rf nginx-${VER}


#5

Merlin wrote:

Mark,

Why not just use apt-get source to get the source package of nginx; wget
the latest nginx; copy the debian/ directory from the source package

Come on, with a new nginx 0.7.4x coming out every day?

The reported procedure is a faster and gets the job done rather well.

I have a couple of sites on a Linode VPS with very low hardware
resources. This is all I need to use nginx and follow its development.

M.


#6

mike wrote:

What does this do?

ensure that there is only one -O in CFLAGS and that it is -O2

When we use --with-cc-opt= to specify any alternative -On C compiler
optimization, there seems to be a bug (or is it a designed feature?) in
nginx’s ./configure that leads to the following line in the created
objs/Makefile file:

CFLAGS = -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter
-Wno-unused-function -Wunused-variable -Wunused-value -Werror -g -O2

If I am not wrong, that line should only have one instance of -O:

CFLAGS = -pipe -W -Wall -Wpointer-arith -Wno-unused-parameter
-Wno-unused-function -Wunused-variable -Wunused-value -Werror -g -O2

Hence the usage of the command sed -i ‘/CFLAGS/s/ -O //g’ objs/Makefile
to clean the other instances of -O.

From man cc:
" -O2 Optimize even more.
(…)
As compared to -O, this option increases both compilation time and the
performance of the generated code."

M.


#7

mike wrote:

I actually just do this. the .deb installs but issues warnings but it
does work well enough.

Nice script. Short and clean.
I will try it and report back.

J.


#8

On Mon, Mar 23, 2009 at 4:11 PM, Mark A. removed_email_address@domain.invalid
wrote:

Merlin wrote:

Mark,

Why not just use apt-get source to get the source package of nginx; wget
the latest nginx; copy the debian/ directory from the source package

Come on, with a new nginx 0.7.4x coming out every day?

I don’t know what list you’re on that I’m not but I’d love to see the
daily
nginx release list ;).

The reported procedure is a faster and gets the job done rather well.

Neither procedure is any faster than the other (both can be scripted
down to
one invocation and the configure/build process will take the same amount
of
time!), but the original method appears to get the job done rather
well -
if you don’t care about possibly breaking your debian installation.

Personally, I like things to be easy to inspect/add/remove/update with
the
tools that are built into the distrobution. This is not to say your
method
is “wrong” or even that it will break anything; I merely offer another
way
to do things more in-line with the way other things are done in the
distrobution.

$ dpkg -l | grep nginx
ii nginx 0.7.44-1 small, but very
powerful
and efficient web server

I bet yours still says 0.6.32-3.

  • Merlin

#9

On Mon, Mar 23, 2009 at 09:56:45PM +0000, Mark A. wrote:

CFLAGS = -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter
to clean the other instances of -O.

From man cc:
" -O2 Optimize even more.
(…)
As compared to -O, this option increases both compilation time and the
performance of the generated code."

As I understand gcc uses the lastest -O option, therefore -O -O2 is the
same
as -O2. Also you may disable optimizations using -O -O0. As to -O2
itself,
I believe you would not see any significant changes in nginx with -O2
if compared with just -O. However, -O0 vs -O change is dramatically.


#10

i have one for redhat which just does a make install/etc. each time
but it seems for large amounts of servers i’d rather to .debs…

it’s not clean and requires mkdir -p /var/lib/nginx /var/log/nginx and
such…


#11

On Mon, Mar 23, 2009 at 02:56:50PM -0700, mike wrote:

.deb someday :slight_smile:

root@local:/usr/src/build# cat build-nginx
#!/bin/sh

If you build something by hand, use program tuned specially for this:
make,
even with the single target. make has one excellent feature: it always
tests
a program exit code and stops execution if the program has failed.


#12

when my “make” runs this is what i see:

gcc -c -O -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter
-Wno-unused-function -Wunused-variable -Wunused-value -Werror -g -I
src/core -I src/event -I src/event/modules -I src/os/unix -I
/usr/lib/include -I /usr/include/libxml2 -I objs
-o objs/src/core/ngx_array.o
src/core/ngx_array.c

that is as optimal as it should be for an x86_64 ubuntu linux box,
basically, right?

2009/3/23 Igor S. removed_email_address@domain.invalid:

objs/Makefile file:

as -O2. Also you may disable optimizations using -O -O0. As to -O2 itself,
I believe you would not see any significant changes in nginx with -O2
if compared with just -O. However, -O0 vs -O change is dramatically.


Igor S.
http://sysoev.ru/en/

hen


#13

2009/3/23 Igor S. removed_email_address@domain.invalid:

root@local:/usr/src/build# cat build-nginx
#!/bin/sh

If you build something by hand, use program tuned specially for this: make,
even with the single target. make has one excellent feature: it always tests
a program exit code and stops execution if the program has failed.

You mean make a “make nginx” instead of ./build-nginx ?


#14

On Mon, Mar 23, 2009 at 11:03:29PM -0700, Michael S. wrote:

basically, right?
Yes, -O is enough.


#15

On Mon, Mar 23, 2009 at 11:04:43PM -0700, Michael S. wrote:

2009/3/23 Igor S. removed_email_address@domain.invalid:

root@local:/usr/src/build# cat build-nginx
#!/bin/sh

If you build something by hand, use program tuned specially for this: make,
even with the single target. make has one excellent feature: it always tests
a program exit code and stops execution if the program has failed.

You mean make a “make nginx” instead of ./build-nginx ?

Just “make” with such Makefile:

all:
./configure …
make
echo
mv/etc


#16

On Tue, Mar 24, 2009 at 09:08:31AM +0300, Igor S. wrote:

You mean make a “make nginx” instead of ./build-nginx ?

Just “make” with such Makefile:

all:
./configure …
make
echo
mv/etc

all:
wget
tar
cd …
&& ./configure …
&& make
echo
mv/etc


#17

Igor S. wrote:

As I understand gcc uses the lastest -O option, therefore -O -O2 is the same
as -O2.

As far as I know in several Linux systems it is.
But nginx should not rely on that to cope with a less than optimal
./configure that is generating too much flags. I wonder, is it doing the
same with other flags?

Also you may disable optimizations using -O -O0. As to -O2 itself,
I believe you would not see any significant changes in nginx with -O2
if compared with just -O. However, -O0 vs -O change is dramatically.

Thank you Igor and keep up with the good work.

M.


#18

On Tue, Mar 24, 2009 at 09:02:43AM +0000, Mark A. wrote:

Igor S. wrote:

As I understand gcc uses the lastest -O option, therefore -O -O2 is the
same
as -O2.

As far as I know in several Linux systems it is.

This is gcc’s feature, but not Linux’s one.

But nginx should not rely on that to cope with a less than optimal
./configure that is generating too much flags. I wonder, is it doing the
same with other flags?

I do not understand the question.


#19

Igor S. wrote:

But nginx should not rely on that to cope with a less than optimal
./configure that is generating too much flags. I wonder, is it doing the
same with other flags?

I do not understand the question.

Does the nginx ./configure script have a procedure to ensure that the
same flag does not get added (with different values) several times in
the same compiler line?

If not, how does ./configure select the last (and relevant) instance of
each flag entered in a compiler line?

M.


#20

Merlin wrote:

This is not to say your method is “wrong” or even that it will break anything;
I merely offer another way to do things more in-line with the way
other things
are done in the distribution.

I see, you are thinking in something complex like this:
https://wiki.ubuntu.com/PackagingGuide/Recipes/PackageUpdate

But, perhaps, the following procedure is better for you. Change 0.6.34,
0.7.44, John D., and jdoe@jdoe.0 for your own values, and try this:

sudo aptitutde -R install build-essential fakeroot devscripts wget
test -x $HOME/tmp/ || mkdir -p $HOME/tmp/ && cd $HOME/tmp/
wget -c http://sysoev.ru/nginx/nginx-0.7.44.tar.gz # get latest nginx
apt-get source nginx
cd nginx-0.6.34
uupdate -rfakeroot --upstream-version 0.7.44 …/nginx-0.7.44.tar.gz
cd …/$(dpkg-parsechangelog | sed -n ‘s/^Source: //p’)-0.7.44
(export DEBFULLNAME=‘John D.’;export DEBEMAIL=‘jdoe@jdoe.0’;debuild -i
-us -uc -b)
cd …

Rather boring, isn’t it? It doesn’t make it any easier to play around
with nginx ./configure switches.

M.