getButterfly Logo

Switching from Debian to Ubuntu: Beginner’s Guide

Server - Stripe

I just switched my development server from Debian to Ubuntu. I decided to use Ubuntu 16.04, nginx 1.10, PHP 7 and Percona MySQL.

Here are the steps involved in creating this configuration from scratch.


Get the ISO file from, add it to your boot sequence and run it. The installer will ask for general details such as name, location, keyboard type and installation type. For a non-GUI installation, just go with the default settings and do not check any extra modules.

When installation is complete, you need to configure your root password by running:

sudo passwd

and following the steps. You will have to type your password twice. Whenever you need root access, just use:


When everything is done, update your Ubuntu installation by running:

apt update

apt upgrade


We use nginx-extras from Ubuntu’s repository. We use the default paths.

apt install nginx-extras

Edit /etc/nginx/nginx.conf:

nano /etc/nginx/nginx.conf

Modify error_log to:

error_log /var/log/nginx/error.log warn;

Open your server IP on a browser (use ip addr show to display it) and you’ll see the default nginx webpage.

Percona MySQL

We are going to use Percona MySQL. Percona MySQL and normal SQL has no difference in commands, it is a special optimised version.

gpg --keyserver  hkp:// --recv-keys 1C4CBDCDCD2EFD2A

gpg -a --export CD2EFD2A | apt-key add -

sudo sh -c 'echo "deb xenial main" >> /etc/apt/sources.list.d/percona.list'

apt update

sudo apt install percona-server-5.7

sudo mysql_secure_installation

Delete all test/default users and databases. Now login to MySQL server and run the commands specific for Percona:

mysql -u root -h localhost -p





service mysql restart

After completion of this step, you can run a cat command on /etc/mysql/my.cnf. Percona has no my.cnf by default. The most important step is how to enable auto restart of MySQL, in order to prevent the “Error Establishing a Database Connection” error message.

echo " " > /etc/mysql/my.cnf

cd ~ && wget

cat fail-safe-my.cnf > /etc/mysql/my.cnf


For the latest PHP version, use the following commands:

sudo add-apt-repository ppa:ondrej/php

apt install libcurl3 libmcrypt4 libmemcached11 libxmlrpc-epi0 php7.0-cli php7.0-common php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline php7.0-xml php7.0-xmlrpc psmisc libmcrypt-dev mcrypt php-pear php-mysql php-mbstring php-mcrypt php-xml php-intl libmhash2 php-common
nano /etc/php/7.0/fpm/php.ini

Find cgi.fix_pathinfo. This will be commented out with a semi-colon (;) and set to 1 by default. We will change both of these conditions by uncommenting the line and setting it to 0 like this:


Edit default nginx file with sudo nano /etc/nginx/sites-available/default command and make it like this:

server {
    listen 80 default_server;
    root /usr/share/nginx/html;
    index index.html index.htm index.php;
    server_name localhost;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;

        # fastcgi_split_path_info ^(.+\.php)(/.+)$;
        # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini

        # With php7.0-fpm:
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        include fastcgi_params;

Then restart PHP and Nginx:

sudo systemctl restart php7.0-fpm


sudo service php7.0-fpm restart


service nginx restart

Now, delete the default file in /usr/share/nginx/html and add a PHP file:

cd /usr/share/nginx/html

rm -r *

nano index.php

Add “Hello World”, save and exit.


Before you install Redis, there are a couple of prerequisites that need to be downloaded to make the installation as easy as possible.

Update all of the apt packages:

apt update

Once the process finishes, download a compiler with build essential which will help us install Redis from source:

sudo apt install build-essential

sudo apt install tcl8.5

Since we won’t need to keep the source code that we’ll compile long term, we will build in the /tmp directory.

cd /tmp

Download the latest stable version of Redis.


Unzip and install:

tar xzvf redis-stable.tar.gz

cd redis-stable


make test

sudo make install

Now that Redis is installed, we can begin to configure it.

sudo mkdir /etc/redis

sudo cp /tmp/redis-stable/redis.conf /etc/redis

sudo nano /etc/redis/redis.conf

In the file, find the supervised directive. Currently, this is set to no. Since we are running an operating system that uses the systemd init system, we can change this to systemd:


# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
# supervised no - no supervision interaction
# supervised upstart - signal upstart by putting Redis into SIGSTOP mode
# supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
# supervised auto - detect upstart or systemd method based on
# UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
# They do not enable continuous liveness pings back to your supervisor.
supervised systemd


Next, find the dir directory. This option specifies the directory that Redis will use to dump persistent data. We need to pick a location that Redis will have write permission and that isn’t viewable by normal users.

We will use the /var/lib/redis directory for this, which we will create in a moment:


# The working directory.
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
# The Append Only File will also be created inside this directory.
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis


Save and exit.

Create and open the /etc/systemd/system/redis.service file to get started:

sudo nano /etc/systemd/system/redis.service

Add this:

Description=Redis In-Memory Data Store

ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown


Save and exit.

Now, we just have to create the user, group, and directory that we referenced in the previous two files.

Begin by creating the redis user and group. This can be done in a single command by typing:

sudo adduser --system --group --no-create-home redis

Now, we can create the /var/lib/redis directory by typing:

sudo mkdir /var/lib/redis

We should give the redis user and group ownership over this directory:

sudo chown redis:redis /var/lib/redis

Adjust the permissions so that regular users cannot access this location:

sudo chmod 770 /var/lib/redis

Start up the systemd service by typing:

sudo systemctl start redis

If all of your tests worked, and you would like to start Redis automatically when your server boots, you can enable the systemd service.

sudo systemctl enable redis

That’s it. These are the steps I’ve followed. For a more in-depth explanation, check the reference links below.


Image Credit:

One thought on “Switching from Debian to Ubuntu: Beginner’s Guide

  1. You must enter a row Type=forking in the section [Service] file redis.service

    for Ubuntu type sudo nano /etc/systemd/system/redis.service

Leave a Reply

Your email address will not be published. Required fields are marked *