Virtualmin, MariaDB, and NginX on Debian 7

Tags:

Installing Debian 7

If you're on a local machine or virtual machine, you will want to download the Net Install image from here. If you're on Linode or another VPS (virtual private server), use their installation copy of Debian 7.

Create an ordinary user if you haven't already. Let's call him george.

  1. First, if your system is local and you need to know its IP address, find it with: ip addr

  2. From a terminal on your regular machine, log in to your new server with SSH, as your ordinary user. Then install sudo, which we use even at the expense of a little typing, so all your commands stay in your ~/.bash_history -- install it like this: su apt-get install sudo and set your ordinary user to be in the sudo group (see /etc/sudoers for details): addgroup -G sudo george

  3. Exit the root shell. Create (mkdir) a temporary directory under your home directory and move (cd) into it. Download the Virtualmin install script into there by running wget http://software.virtualmin.com/gpl/scripts/install.sh

  4. Now change the permissions of the install script to make it executable, and copy it to the global /opt directory chmod 744 install.sh sudo mkdir /opt/virtualmin sudo mv install.sh /opt/virtualmin

  5. Run the installer by by running sudo /opt/virtualmin/install.sh

  6. You'll be asked if you want to continue. Type y, then press Enter.

The installation should proceed without error and give you a standard prompt back.

I also like to add a favorite program or two, and disable root SSH logins:

sudo apt-get install emacs23-nox emacs /etc/ssh/sshd_config

And change the line that says:

PermitRootLogin yes

to:

PermitRootLogin no

At this point, if you can, you might want to clone your virtual machine, or take a snapshot, or do a backup... so you can get back to here easily if the next step goes sideways.

You must install MariaDB after Virtualmin; otherwise you will probably have great difficulties with apt-get trying to re-install MySQL "on top of" MariaDB, or otherwise encounter dependency problems.

Install MariaDB to replace MySQL

We will be using MariaDB 10.0 following the installation instructions here. Login as your regular user and run the following commands

sudo apt-get install python-software-properties ``sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db sudo add-apt-repository 'deb http://mirror.stshosting.co.uk/mariadb/repo/10.0/debian wheezy main'

Once the key is imported and the repository added you can install MariaDB with:

sudo apt-get update ; sudo apt-get install mariadb-server

This removes the MySQL server and installs MariaDB.

Next we visit the Virtualmin login page at https://*xxx.xxx.xxx.xxx*:10000 where the x's are your server's IP address. Login with the regular user you created -- since you have sudo ability, that will work.

Let Virtualmin check your configuration. If things have gone smoothly so far, there should be no errors to resolve.

NginX

The final big step is to replace Apache with NginX.

At this point again I recommend doing a snapshot, clone, or backup of your machine for easy recovery if these steps go wrong. Then, logged in as your regular user at the terminal:

  1. Shut down Apache: sudo /etc/init.d/apache2 stop

  2. Remove Apache from the system startup: sudo update-rc.d -f apache2 remove

  3. In addition to the NginX web server, we now install the APC cache for PHP: sudo apt-get install nginx php-apc

  4. Start NginX: sudo /etc/init.d/nginx start

  5. Install the Nginx plugin for Virtualmin: sudo apt-get install webmin-virtualmin-nginx

If you want to use SSL, you will need a package called webmin-virtualmin-nginx-ssl ... that is covered separately.

Back at https://xxx.xxx.xxx.xxx:10000 -- Turn on, and enable in the Defaults column,

Nginx website

Turn off, and remove from Defaults,

Apache website, Webalizer reporting, SSL website, AWstats reporting, Protected web directories

Click Save; then, back on the main System Information page, click Refresh system information to refresh the status bars. Click the right-arrow by the Status bar if it is not already open; you should see "Nginx Webserver" as a managed service.

Congratulations!

You now have a VPS running Debian 7, MariaDB, and NginX! Have fun.

If you are going to install WordPress, you will want manually edit the NginX configuration file through Webmin to make permalinks work properly.

From Webmin, open Servers in the left column, and click on Nginx Webserver. In the right pane, click Edit Configuration Files. In the drop down list, select the domain you are going to edit. At the bottom off that file, Virtualmin has added a stock location ... { stanza; you need to add one above it. The domain definition should now end like this:

location / {
    index index.php index.html index.htm;
    try_files $uri $uri/ /index.php?$args;
}
location ~ \.php$ {
    try_files $uri =404;
    fastcgi_pass unix:/var/php-nginx/1234567890123.sock/socket;
}

Back on the WordPress admin screen, under Settings/Permalinks, select Custom Structure and replicate the permalink directory structure you want. I use /%year%/%monthnum%/%day%/%postname%/ -- you cannot use the built-in settings like "Default" or "Day and Name" because WordPress will detect that mod_rewrite is not loaded and use its PATHINFO fallback which adds index.php into the path.

NOTE: Originally the last bit of the try_files line was: /index.php?q=$uri&$args; but WordPress now understands the simpler /index.php?$args; just fine.