How to Install Craft CMS on Debian 9

Published on: Fri, Feb 15, 2019 at 11:36 am EST
CMS Debian Linux Guides Server Apps

Craft CMS is an open source CMS written in PHP. Craft CMS source code is hosted on GitHub. This guide will show you how to install Craft CMS on a fresh Debian 9 Vultr instance.

Requirements

  • PHP 5.3.0 or greater with safe mode disabled and the following extensions:
    • Reflection Extension
    • PCRE Extension
    • SPL Extension
    • PDO Extension
    • PDO MySQL Extension
    • Mcrypt Extension
    • GD Extension with FreeType Support (unless ImageMagick Extension is installed)
    • OpenSSL Extension
    • Multibyte String Extension
    • JSON Extension
    • cURL -crypt() with BLOWFISH_CRYPT enabled
    • DOM Extension (optional)
    • iconv Extension (optional)
    • ImageMagick Extension (optional)
    • SimpleXML (optional)
  • MySQL 5.1.0 or later, with the InnoDB storage engine installed
  • A web server. This guide will use Nginx
  • A minimum of 32MB of memory allocated to PHP
  • A minimum of 20MB of free disk space
  • A minimum of 1MB of database space

Before you begin

Check the Debian version.

lsb_release -ds
# Debian GNU/Linux 9.4 (stretch)

Ensure that your system is up to date.

apt update && apt upgrade -y

Install necessary packages.

apt install -y sudo vim wget unzip zip

Create a new non-root user account with sudo access and switch to it.

adduser johndoe --gecos "John Doe"
usermod -aG sudo johndoe
su - johndoe

NOTE: Replace johndoe with your username.

Set up the timezone.

sudo dpkg-reconfigure tzdata

Install PHP, MySQL and Nginx

Download and install PHP 7.0 and required PHP extensions. We will also install optional PHP extensions.

sudo apt install -y php7.0 php7.0-cli php7.0-fpm php7.0-mysql php7.0-mcrypt php7.0-gd php7.0-mbstring php7.0-json php7.0-curl php7.0-xml php7.0-common php-imagick

Check the PHP version.

php --version
# PHP 7.0.30-0+deb9u1 (cli) (built: Jun 14 2018 13:50:25) ( NTS )

Because there are many existing Vultr Docs detailing the installation of Nginx and the installation and creation of MySQL or MariaDB databases, this article will only cover the configuration of Nginx. You will need to create a database for Craft.

Step 2 - Configure Nginx

Run sudo vim /etc/nginx/sites-available/craft.conf and populate the file with the following Nginx configuration.

server {
  listen [::]:80;
  listen 80;

  server_name example.com;
  root /var/www/craft/public;

  index index.html index.htm index.php;
  charset utf-8;

  location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
  }

  location ~ [^/]\.php(/|$) {
    try_files $uri $uri/ /index.php?$query_string;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass unix:/var/run/php/php7.0-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param HTTP_PROXY "";       
  }
}

Activate the new craft.conf configuration by linking the file to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/craft.conf /etc/nginx/sites-enabled/

Test the Nginx configuration.

sudo nginx -t

Reload Nginx.

sudo systemctl reload nginx.service

Step 3 - Download and install Craft CMS

Create a document root directory.

sudo mkdir -p /var/www/craft

Change ownership of the /var/www/craft directory to johndoe.

sudo chown -R johndoe:johndoe /var/www/craft

Navigate to the document root.

cd /var/www/craft

Download the latest stable release of Craft CMS.

wget https://download.craftcdn.com/craft/2.6/2.6.3019/Craft-2.6.3019.zip

Unzip Craft CMS.

unzip Craft-2.6.3019.zip
rm Craft-2.6.3019.zip

Tell Craft how to connect to your database.

vim craft/config/db.php

Change ownership of the /var/www/craft directory to www-data.

sudo chown -R www-data:www-data /var/www/craft

Now that everything is set up, point your browser to http://example.com/admin and follow the Craft installer.

To access Craft's administrative interface append /admin to your IP/domain.

Want to contribute ?

You could earn up to $300 by adding new articles