Learn How To Install Craft CMS on Ubuntu 16.04 LTS
Table of Contents
- Requirements
- Before you begin
- Step 1 – Install PHP and required PHP extensions, MySQL and NGINX
- Step 2 – Configure NGINX
- Step 3 – Download and install Craft CMS
If you are using a different system, please check our other tutorials.
How to Install Craft CMS on CentOS 7
How to Install Craft CMS on Debian 9
How to Install Craft CMS on Fedora 29
How to Install Craft CMS on FreeBSD 12
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 Ubuntu 16.04 LTS IT Web Services instance.
Requirements
Server Requirements
- PHP 5.3.0 – 7.1.x with safe mode disabled
- MySQL 5.1.0 or later, with the InnoDB storage engine installed
- A web server (Apache, Nginx, IIS)
- A minimum of 32MB of memory allocated to PHP
- A minimum of 20MB of free disk space
- A minimum of 1MB of database space
Required PHP 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
Optional PHP Extensions
- DOM Extension
- iconv Extension
- ImageMagick Extension
- SimpleXML
Before you begin
Check the Ubuntu version.
lsb_release -ds
# Ubuntu 16.04.4 LTS
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
Ensure that your system is up to date.
sudo apt update && sudo apt upgrade -y
Step 1 – Install PHP and required PHP extensions, 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 PHP version.
php --version
# PHP 7.0.28-0ubuntu0.16.04.1 (cli) ( NTS )
# Copyright (c) 1997-2017 The PHP Group
# Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
# with Zend OPcache v7.0.28-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies
Because there are many existing IT Web Services Docs detailing the installation of MySQL and NGINX, 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 copy/paste the following.
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 document root.
cd /var/www/craft
Download the latest stable release of Craft CMS.
wget https://download.craftcdn.com/craft/2.6/2.6.3012/Craft-2.6.3012.zip
Install unzip
package.
sudo apt install unzip
Unzip Craft CMS.
unzip Craft-2.6.3012.zip
rm Craft-2.6.3012.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
Run sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf
and append the following directive at the end of this file.
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Now that everything’s 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.
Need help?
Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!