Installing Craft 3 CMS on Linux

Installing Craft 3 CMS on Linux using Composer

Last updated on

Craft is a CMS that was developed by ExpressionEngine add-on developers Pixel & Tonic. In this article we will download and install Craft 3 on Linux using Composer.


You should have your LAMP or LEMP stack up and running and a MySQL or Postgres database created for Craft.

1. Install Composer

If you already have Composer installed, skip to Step 2,

Firstly, let’s update the package database.

sudo apt update

Next, install the required packages

sudo apt install curl php-cli php-mbstring git unzip

You also need the zip extension for PHP. Ensure to replace php7.0 with your own version of PHP. If you don’t know what version you have, run php -version

sudo apt install php7.0-zip

Composer provides an installer, written in PHP. Make sure you’re in your home directory, and retrieve the installer using curl:

cd ~


curl -sS -o composer-setup.php

To install composer globally, use the following:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
All settings correct for using Composer Downloading... Composer (version 1.6.5) successfully installed to: /usr/local/bin/composer Use it: php /usr/local/bin/composer

Once installed, you can check the version

composer -V
Composer version 1.6.5 2018-05-04 11:44:59

2. Install Craft

You should now decide where you want to install Craft. We normally install it in somewhere like /var/www/

sudo composer create-project craftcms/craft PATH_HERE

We are running Composer with sudo because if the PATH does not already exist, you may get an error [RuntimeException] Could not delete path. Note that normally you should never run Composer as root for apps you don’t trust.

On success, you should see

______ .______ ___ _______ .___________.
/ || _ \ / \ | ____|| |
| ,----'| |_) | / ^ \ | |__ `---| |----`
| | | / / /_\ \ | __| | |
| `----.| |\ \----./ _____ \ | | | |
\______|| _| `._____/__/ \__\ |__| |__|

______ .___ ___. _______.
/ || \/ | / |
| ,----'| \ / | | (----`
| | | |\/| | \ \
| `----.| | | | .----) |
\______||__| |__| |_______/

Generating a security key... done (UwYczEAKvxkbfdgf5es3h2T4x_yEK)

Welcome to Craft CMS! Run the following command if you want to setup Craft from your terminal:

/var/www/ setup

To view the directory structure.

ls -l /var/www/
total 140
-rw-r--r-- 1 root root 1012 May 18 19:26 composer.json
-rw-r--r-- 1 root root 95914 Jun 2 12:00 composer.lock
drwxr-xr-x 3 root root 4096 May 18 19:26 config
-rwxr-xr-x 1 root root 577 May 18 19:26 craft
-rw-r--r-- 1 root root 330 May 18 19:26 craft.bat
-rw-r--r-- 1 root root 1081 May 18 19:26
drwxr-xr-x 2 root root 4096 May 18 19:26 modules
-rw-r--r-- 1 root root 1464 May 18 19:26
drwxr-xr-x 4 root root 4096 Jun 2 12:00 storage
drwxr-xr-x 2 root root 4096 May 18 19:26 templates
drwxr-xr-x 27 root root 4096 Jun 2 12:00 vendor
drwxr-xr-x 3 root root 4096 Jun 2 12:05 web

The “web” directory is the document root. You can change this to whatever you want, for example public_html, etc.

You must update your Apache or Nginx configuration and ensure it is pointing to the correct document root.

3. Configure Craft

Change to the craft directory.

cd /var/www/

Run the Craft setup.

sudo ./craft setup

You will be asked a series of questions next about database details. You can press ENTER for defaults.

Which database driver are you using? [mysql,pgsql,?]: mysql
Database server name or IP address: [localhost] localhost
Database port: [3306]
Database username: [root] 
Database password:
Database name: devtest1_craft
Database table prefix: craft
Testing database credentials... success!
Saving database credentials to your .env file... done

Install Craft now? (yes|no) [yes]:

Username: [admin] 
Email: [email protected]
Site name: DevTest1
Site URL: [@web]
Site language: [en-US]

*** installing Craft
> create table ......
*** installed Craft successfully (time: 3.781s)

You should now be able to access the admin panel at

If you are using Nginx, you should add the following location handlers.

# Root directory location handler
location / {
    try_files $uri/index.html $uri $uri/ /index.php?$query_string;
# Craft-specific location handlers to ensure AdminCP requests route through index.php
location ^~ /admin {
    try_files $uri $uri/ /index.php?$query_string;

For more information about Nginx configuration, please read here.

Let me know in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 5.00 (3 votes)

Leave a Reply

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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces