Knickers: Change your underwear!

Setting Up A Web Server

There are many different web servers available, and choosing one is really beyond the scope of this site; but if you are just trying to check out Knickers and don't already have a web server installed, this is one simple method for setting one up. Please note that this is not intended to cover all aspects of setting up a production webserver (notably, it does not discuss securing a web server) -- it is just quick start guide.

These instructions assume you are running Ubuntu Linux. The process will be similar (but different) for other distributions.

As Knickers applications generally require a web server, PHP, and a database server, we're going to install all three.

Install Apache and PHP

First, let's install Apache and PHP.
sudo apt-get install apache2 php5 php5-cli 

Now, let's setup a basic apache environment. We need a "virtual host" for our stuff; we will set up a generic one for now -- you can add others (or modify the one this command generates) later more specific to your applications. Before running the following command, change YOURNAME to your local username. (Note that if you change the file this generates later, you need to restart apache for the changes to take effect.)

sudo bash -c 'echo -e "<VirtualHost *:80>\n\tDocumentRoot /home/YOURNAME/public_html\n\t \
<Directory />\n\t\tOptions FollowSymLinks\n\t\tAllowOverride All\n\t</Directory>\n \
</VirtualHost>" > /etc/apache2/sites-enabled/mysite'

We need to make sure mod rewrite (an Apache module) is enabled, as is important to any Knickers application. On Ubuntu, this is how it's done:

sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/

And then a couple more Ubuntu-specific steps...

sudo rm /etc/apache2/sites-enabled/000-default
sudo bash -c 'echo "ServerName localhost" >> /etc/apache2/httpd.conf'

It can be very helpful to display some PHP errors when developing a site; but error display is off by default. In /etc/php5/apache2/php.ini, change "display_errors = Off" to "display_errors = On". On the other hand, which types of errors PHP is set up to display can be a bit too verbose, so change "error_reporting = E_ALL & ~E_DEPRECATED" to "error_reporting = E_ALL & ~E_NOTICE".

And then we can start up Apache:

sudo /etc/init.d/apache2 restart

It may give a warning about public_html not existing, but we'll take care of that.

Now, to test it...

cd
mkdir public_html
echo "<?php phpinfo(); ?>" >> public_html/index.php

...and point your browser at http://localhost/ , and you should see the PHP info page. Success!

Install a database

There are many options for databases. If you want to be cool and use PostgreSQL...

sudo apt-get install postgresql

It's reaaaallly helpful if your user has a postgres superuser account; otherwise you have to become the postgres user anytime you want to do anything.

sudo -u postgres createuser --superuser $USER

Now, for kicks, create a database...

createdb mydb

...and login to it with the command-line client

psql mydb

If you get a "mydb=#" prompt, you have succeeded! Within this command-line client, you can type \d to list tables, \? for a list of commands, \h for help with sql syntax.

It is a good idea to setup database user specific to the database (multiple users is even better; one for "super" access, one for "write" access, and one for "read only" access - but we will leave that as an excercise for the reader). Assuming you are still logged into the database, here's how to setup a "mydb_user" account that has full access to the "mydb" database:

create user mydb_user with password 'somepassword';
grant all privileges on database mydb to mydb_user;

Now, quit (\q) and test that you can log in as that user:

psql -h localhost -U mydb_user mydb

Note: This is the user and password you provide when setting up a new Knickers application.

Once you are done there (\q to quit), as you want to use PostgreSQL from PHP, you need to do:

sudo apt-get install php5-pgsql

At this point, you should be ready to Install Knickers if you haven't already.