1

I'm using Vagrant to build a reproducible virtual machine for one of my projects. This virtual machine needs a basic LEMP stack, and I'm using a shell script to provision it after it's created.

The part I'm having trouble with is installing nginx from source. The provisioning script is as follows:

#!/bin/bash

# nginx settings
NGINX_VERSION=1.4.7
NGINX_SOURCE=http://nginx.org/download/nginx-$NGINX_VERSION.tar.gz

echo "==> Installing required packages and upgrading"
apt-get -u update
apt-get install make

echo "==> Checking if nginx is installed"
if [ ! -e /opt/nginx-$NGINX_VERSION ]
then
    echo "==> nginx not installed, installing nginx $NGINX_VERSION"

    # Download nginx to /usr/src and cd into the extracted directory
    cd /usr/src
    wget $NGINX_SOURCE
    tar xf nginx-$NGINX_VERSION.tar.gz
    cd nginx-$NGINX_VERSION

    # Configure nginx
    ./configure --with-pcre --with-http_ssl_module --with-http_spdy_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --prefix=/opt/nginx-$NGINX_VERSION

    # Make nginx and install it
    make
    make install
fi

The process fails at the make and make install steps, producing the following errors:

make: *** No rule to make target `build', needed by `default'.  Stop.
make: *** No rule to make target `install'.  Stop.

I've had to install make using apt-get at the start of the script because the image I'm using doesn't already have make installed. The image is a Ubuntu Server 12.04 64-bit image.

I've verified that nginx gets successfully downloaded and extracted by checking the usr/src directory after the scripts runs.

Googling the make errors doesn't seemm to return anything useful I can work with as they're all specific to installing software that I'm not using.

Any ideas?

John Dorean
  • 111
  • 1
  • 5
  • Why not use the binary package from your distro? – EEAA Apr 03 '14 at 22:10
  • AFAIK Ubuntu 12.04 doesn't have the latest version of nginx available via `apt-get`. – John Dorean Apr 03 '14 at 22:17
  • Do you *need* the latest version? Newest is often not the most stable, and using your distribution's nginx package is *much* easier in every regard. Best practice is to always use official distro packages unless there is a very specific need for a different version, and even then, build your own binary packages. Never compile anything on your servers. – EEAA Apr 03 '14 at 22:35
  • This is largely not what you want to do. Build your own packages if you need a newer version, and have apt use those instead. Don't try to build nginx from source every time a vagrant machine starts up. – devicenull Apr 03 '14 at 23:55
  • 1
    There is [official repo](http://wiki.nginx.org/Install#Official_Debian.2FUbuntu_packages) and [PPA](https://launchpad.net/~nginx) on Launchpad. The most common reason to rebuild nginx is to include some third-party modules. But even in this case you should build binary package somewhere else as @EEAA says. – Alexey Ten Apr 04 '14 at 06:37
  • Did you install the pcre libs? – Lama Jun 27 '15 at 08:08
  • Where comes the script from? – frlan Feb 06 '17 at 09:51
  • The previous action (`./configure ...`) was finished ok? – pbacterio Jan 15 '18 at 12:29

3 Answers3

1

I don't see the reason why would you install NginX from source since you didn't say any reason. So I'm just leaving this here from the official site:

For Ubuntu replace codename with Ubuntu distribution codename, and append the following to the end of the /etc/apt/sources.list file:

deb http://nginx.org/packages/mainline/ubuntu/ codename nginx
deb-src http://nginx.org/packages/mainline/ubuntu/ codename nginx

For Debian/Ubuntu then run the following commands:

apt-get update
apt-get install nginx

Ubuntu:

Version Codename    Supported Platforms
12.04   precise     x86_64, i386
14.04   trusty      x86_64, i386, aarch64/arm64
16.04   xenial      x86_64, i386, ppc64el, aarch64/arm64
16.10   yakkety     x86_64, i386
Bert
  • 1,028
  • 1
  • 16
  • 33
1

I had the same problem on my centos7 too, so it turned out that I hadn't installed the peer packages completely. So it might solve your problem if you are on centos, too:

yum install -y gcc pcre pcre-devel openssl openssl-devel gd gd-devel
MajidJafari
  • 111
  • 2
0

This happens when some library is missing. As I see this is kind of an try and error situation.

e.g:You need to install PCRE libraries for Nginx to compile. Try this:

apt-get install libpcre3 libpcre3-dev
apt-get install openssl
apt-get install libssl-dev

If it doesnt work, something else is missing...like in my case.

Edit: also make sure you got zlib installed

apt-get install --reinstall zlibc zlib1g zlib1g-dev

Also I switched to the newest version of nginx and then I was able to compile.

Lama
  • 243
  • 1
  • 3
  • 8