This tutorial exists for these OS versions
- Debian 12 (Bookworm)
- Debian 11 (Bullseye)
- Debian 9 (Stretch)
- Debian 8 (Jessie)
- Debian 6 (Squeeze)
- Debian 5 (Lenny)
On this page
Installing Nginx With PHP5 And MySQL Support On Debian Etch
Version 1.0
Author: Falko Timme
Nginx (pronounced "engine x") is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. This tutorial shows how you can install Nginx on a Debian Etch server with PHP5 support (through FastCGI) and MySQL support.
I do not issue any guarantee that this will work for you!
1 Preliminary Note
In this tutorial I use the hostname server1.example.com with the IP address 192.168.0.100. These settings might differ for you, so you have to replace them where appropriate.
I've compiled this guide from three different sources and filled in my own bits and pieces:
- Debian Etch - installing nginx by Slicehost
- Debian Etch - adding an nginx init script by Slicehost
- Init-script for php-cgi in external FASTCGI Mode (Daemon mode) by Kurt Zankl
2 Installing MySQL 5.0
First we install MySQL 5.0 like this:
apt-get install mysql-server mysql-client
Create a password for the MySQL user root (replace yourrootsqlpassword with the password you want to use):
mysqladmin -u root password yourrootsqlpassword
Then check with
netstat -tap | grep mysql
on which addresses MySQL is listening. If the output looks like this:
tcp 0 0 localhost.localdo:mysql *:* LISTEN 2713/mysqld
which means MySQL is listening on localhost.localdomain only, then you're safe with the password you set before. But if the output looks like this:
tcp 0 0 *:mysql *:* LISTEN 2713/mysqld
you should set a MySQL password for your hostname, too, because otherwise anybody can access your database and modify data:
mysqladmin -h server1.example.com -u root password yourrootsqlpassword
3 Installing Nginx
Nginx is available as a package for Debian Etch, but it's ancient (version 0.4.13), while the latest stable version is 0.6.34. Therefore I build nginx from the sources.
First we install some prerequisites:
apt-get install libpcre3 libpcre3-dev libpcrecpp0 libssl-dev zlib1g-dev build-essential
Then we download nginx and uncompress it (you can find the latest stable release on http://nginx.net/):
cd /tmp
wget http://sysoev.ru/nginx/nginx-0.6.34.tar.gz
tar xvfz nginx-0.6.34.tar.gz
cd nginx-0.6.34
You can run
./configure --help
to find out about all configuration options.
I use the following configure statement...
./configure --sbin-path=/usr/local/sbin --with-http_ssl_module
... and run
make
make install
afterwards to complete the installation.
This will create the directory /usr/local/nginx which contains the configuration files, logs, and the default web site (in /usr/local/nginx/html).
Next we create the nginx init script:
vi /etc/init.d/nginx
#! /bin/sh ### BEGIN INIT INFO # Provides: nginx # Required-Start: $all # Required-Stop: $all # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: starts the nginx web server # Description: starts nginx using start-stop-daemon ### END INIT INFO PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin DAEMON=/usr/local/sbin/nginx NAME=nginx DESC=nginx test -x $DAEMON || exit 0 # Include nginx defaults if available if [ -f /etc/default/nginx ] ; then . /etc/default/nginx fi set -e case "$1" in start) echo -n "Starting $DESC: " start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; stop) echo -n "Stopping $DESC: " start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec $DAEMON echo "$NAME." ;; restart|force-reload) echo -n "Restarting $DESC: " start-stop-daemon --stop --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec $DAEMON sleep 1 start-stop-daemon --start --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec $DAEMON -- $DAEMON_OPTS echo "$NAME." ;; reload) echo -n "Reloading $DESC configuration: " start-stop-daemon --stop --signal HUP --quiet --pidfile /usr/local/nginx/logs/nginx.pid --exec $DAEMON echo "$NAME." ;; *) N=/etc/init.d/$NAME echo "Usage: $N {start|stop|restart|force-reload}" >&2 exit 1 ;; esac exit 0 |
Make the file executable and start nginx:
chmod 755 /etc/init.d/nginx
/etc/init.d/nginx start
Type in your web server's IP address or hostname into a browser (e.g. http://192.168.0.100), and you should see the nginx welcome page:
To make nginx start at boot time, run
update-rc.d nginx defaults