How to Install Craft CMS on Ubuntu 20.04

Craft CMS is a free and open-source content management system written in PHP and based on Yii framework. It is very popular due to its performance and full control on CMS. It is a secure and scalable CMS and comes with a lot of plugins that help you to customize your website easily. It is specially designed for publishers and developers who want to create a website with ease.

In this guide, we will show you how to install a Craft CMS on Ubuntu 20.04.


  • A server running Ubuntu 20.04.

  • A root password is set up on your server.

Install LEMP Server

Craft CMS is written in PHP and uses MySQL/MariaDB as a database backend so the LEMP server must be installed in your server.

First, install the Nginx and MariaDB server using the following command:

apt-get install nginx mariadb-server -y

Once both are installed, you can install PHP with other required extensions using the following command:

apt-get install php php-cli php-fpm php-common php-curl php-gd php-imagick php-json php-mbstring php-mysql php-pgsql php-zip php-intl php-xml -y

After installing all packages, edit the php.ini file and change some desired values: vipul unsdkat

nano /etc/php/7.4/fpm/php.ini

Change the following lines:

memory_limit = 512M post_max_size = 32M upload_max_filesize = 32M date.timezone = Asia/Kolkata

Save and close the file then restart the PHP-FPM service to apply the changes.

systemctl restart php7.4-fpm

Now, you have the LEMP server installed in your system.

Create a Database for Craft CMS

Next, you will need to create a database and user for Craft CMS. First, connect to the MySQL using the following command:


Once connected, create a user and database with the following command:

MariaDB [(none)]> CREATE DATABASE craftdb; MariaDB [(none)]> GRANT ALL ON craftdb.* TO 'craftuser' IDENTIFIED BY 'password';

Next, flush the privileges and exit from the MySQL using the following command:

MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;

At this point, the MariaDB database is created for Craft CMS.

Install Craft CMS

Before downloading Craft CMS, you will need to install the latest version of Composer to your system.

First, download the Composer setup file using the following command:

curl -sS -o composer-setup.php

Next, install the Composer using the following command:

php composer-setup.php --install-dir=/usr/local/bin --filename=composer

Once the Composer is installed, verify the installed version of Composer with the following command:

composer --version

You should get the following output:

Composer version 2.0.12 2021-04-01 10:14:59

Next, create a directory for Craft CMS:

mkdir /var/www/html/craft

Next, change the directory to craft and install the Craft CMS using the following command:

cd /var/www/html/craft composer create-project craftcms/craft .

You will be asked to provide database details, admin username, password, site URL as shown below:

Continue as root/super user [yes]? yes Generating optimized autoload files Generated optimized autoload files containing 4215 classes > @php craft setup/welcome ______ .______ ___ _______ .___________. / || _ \ / \ | ____|| | | ,----'| |_) | / ^ \ | |__ `---| |----` | | | / / /_\ \ | __| | | | `----.| |\ \----./ _____ \ | | | | \______|| _| `._____/__/ \__\ |__| |__| A N E W I N S T A L L ______ .___ ___. _______. / || \/ | / | | ,----'| \ / | | (----` | | | |\/| | \ \ | `----.| | | | .----) | \______||__| |__| |_______/ Generating an application ID ... done (CraftCMS--a6453a60-bd00-4715-8211-e2e0573de5ff) Generating a security key ... done (vmCeyKETfmBXERiJHINieprdDJEzV-dW) Welcome to Craft CMS! Are you ready to begin the setup? (yes|no) [no]:yes Generating an application ID ... done (CraftCMS--4fee740d-4419-4cbb-be2b-c41b6cac1823) Which database driver are you using? [mysql,pgsql,?]: mysql Database server name or IP address: [] Database port: [3306] Database username: [root] craftuser Database password: Database name: craftdb Database table prefix: Testing database credentials ... success! Saving database credentials to your .env file ... done Install Craft now? (yes|no) [yes]:yes Username: [admin] Email: Password: Confirm: Site name: My Craft CMS Site URL: Site language: [en-US]

Next, set proper ownership with the following command:

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

Configure Nginx for Craft CMS

Next, you will need to create an Nginx virtual host configuration file for Craft CMS. You can create it using the following command:

nano /etc/nginx/conf.d/craft.conf

Add the following lines:

server { listen 80; server_name; root /var/www/html/craft/web; index index.php; 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.4-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 ""; } }

Save and close the file then verify Nginx for any syntax error with the following command:

nginx -t

You should get the following output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful

Next, restart the Nginx with the following command:

systemctl reload nginx

Access Craft CMS

Now, open your web browser and access the Craft CMS web interface using the URL You will be redirected to the following page:

Click on Go to your control panel. You should see the Craft CMS login page:

Provide your admin username, password and click on the Login button. You should see the Craft CMS dashboard in the following page:


Congratulations! you have successfully installed Craft CMS with Nginx on Ubuntu 20.04 server. You can now create your own website easily using Craft CMS.

Was this page helpful?

Thank you for helping us improve!