Unless you were using the tasks mentioned in the installation recipe, you now have a properly configured server. To make it a web server, you need to install the web server, the database (if you will be hosting one), the programming language/environment, libraries, any web frameworks you're using, and so on. Fortunately, Debian packages several of them for you, and since you have a configured APT system, you can get started faster.
Although there are a handful of web servers packaged for Debian, there are two schools: Apache and Nginx. They have different execution models—while Nginx is a lightweight, event-oriented server that runs your application via CGI asynchronously, Apache is full of features, more mature with a thread/process approach. You can also have a dual approach where Nginx, designed for concurrency, takes the frontend paired with memcached, and Apache serves the application in the backend.
In either case, you will need to install the web server using APT.
apt-get install task-web-server #
apt-get install nginx #
If you install Apache, you will note there are several flavors of it available as different packages; worker is one of the MPMs (Multi Processing Module) for Apache. You might also want to use prefork since it provides a similar operation model to previous versions of Apache and avoids threads, which might be a problem with non-thread-safe libraries. Simply write
apt-get install task-web-server apache2-mpm-prefork+(think of the plus sign as "I really want this package").
There are two steps for configuring your web server: configure your site or virtual host, and configure your application execution method.
Configuring virtual hosts is very easy in both Apache and Nginx. They both have
/etc/nginxrespectively) where you can drop in a bit of configuration corresponding to your host. You can then link that file to the
sites-enabled/folder (or, for Apache, using the a2ensite/a2dissite tool) and reload your server.
service apache2 restart #
service nginx restart #
Configuring the execution method for your application depends on the programming language you are using (Perl, Python, PHP, Ruby, and so on). We'll assume PHP. As previously mentioned, while Nginx will run PHP via FastCGI, Apache also offers the possibility of using
mod_php, where PHP is basically embedded in the Apache process. For doing that, you only need to install and enable the
apt-get install libapache2-mod-php5
For Nginx, the easiest configuration involves spawning a PHP FastCGI process (manually or optionally with an
initscript) and setting FastCGI parameters, as described on the Nginx Wiki page (http://wiki.nginx.org/PHPFcgiExample). Here, you can find lots of other configuration snippets, including advanced proxying, caching, and specific directives for CMS and other programming languages besides PHP.
Separating the database from the application server may also make sense since the database is I/O bound but the web application is not—most of the time. But you might not have much hardware, or you might be planning on scaling out with tight application plus database units in volumes. Or you might not be using a conventional database at all. However, let's assume you are.
As with the application server, there are two schools for RDBMS: MySQL and PostgreSQL. Debian's default is PostgreSQL but you're free to choose.
apt-get install mysql-server
apt-get install postgresql
Configuration involves lots of variables, from performance to security, and while the default configuration works fine for setting up your server, we will provide some pointers later in the book.
Finally, you need to install the proper bindings for the programming language you're using; otherwise, the application will not be able to connect to the database. For example:
apt-get install php5-mysql
Most likely, the interpreter for your language is already installed on Debian (such as Perl, Python) or is readily available (such as PHP through
mod_php, or Ruby, and so on) but some libraries might not be. For example, if your application needs
gdextensions, you can perform:
apt-get install php5-gd
While you may find frameworks such as Dancer, Rails, or Symfony conveniently packaged in Debian's repositories, they are changing creatures by nature, and most developers download them from the project's website and roll their own outside the APT system. We discuss frameworks briefly later in this book.