Debian Web Server – nginx, PHP, MySQL

September 9, 2012 by

This is a guide to setting up a Debian web server utilizing nginx, PHP, MySQL. Got a VPS but don’t know what to do with it? Want to be the cool kid with your own server or even your own hosting company? Start here!

Debian setup
So, you’ve got your VPS, have connected via SSH, and are now staring at a screen that looks a little like this:

The first thing we want to do is add the dotdebpackages to our apt sources list. Do the following to do this:

It will prompt you to enter a password to use for the MySQL root user. Make this password very secure – The root user will have access to all your databases! Once done, let’s see if it worked:

[bash]mysql -u root -p[/bash]

Enter the password you chose during installation. If it works, success! You have a MySQL installation!

We’re done!
See, wasn’t that easy?! You now have your very own system that you can do practically anything with. Use it as a development environment, a staging environment, or host your own websites on it!Of course, there’s a bit more to do for a full setup. For one, you’ll want more than one virtual host. A “virtual host” is basically just a domain. It allows you to host more than one site on your server. For example, yourdomain.com could go to one site, whereas yourdomain2.com could go to another site, both using the same IP address. This is how normal shared hosting works.Create a new file in /etc/nginx/sites-available/ with a name for the virtual host (eg. “yourdomain.com”), and set up the virtual host in this new folder. Here is a barebones example file: