In this tutorial, we will show you how to install Craft CMS on Ubuntu 20.04 LTS. For those of you who didn’t know, Craft CMS is a free and open-source content management system written in PHP and based on the Yii framework. It is very popular due to its performance and full control of CMS. It is a secure and scalable CMS and comes with a lot of plugins that help you to customize your website easily.
This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘
sudo‘ to the commands to get root privileges. I will show you through the step-by-step installation of the Craft content management system on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
Install Craft CMS on Ubuntu 20.04 LTS Focal Fossa
Step 1. First, make sure that all your system packages are up-to-date by running the following
apt commands in the terminal.
sudo apt update sudo apt upgrade
Step 2. Installing the LAMP stack.
A Ubuntu 20.04 LAMP server is required. If you do not have LAMP installed, you can follow our guide here.
Step 3. Installing Composer.
Run the following command below to install Composer to your system:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
You can find out your installed version of Composer by running
composer -V from your terminal:
Step 4. Installing Craft CMS on Ubuntu 20.04.
Now we create a directory for your Craft CMS project. We create a directory named craft under
/var/www/html/ the directory:
mkdir /var/www/html/craft cd /var/www/html/craft composer create-project craftcms/craft
We will need to change some folders permissions:
chown -R www-data:www-data /var/www/html/craft
Step 5. Configuring MariaDB.
By default, MariaDB is not hardened. You can secure MariaDB using the
mysql_secure_installation script. you should read and below each step carefully which will set a root password, remove anonymous users, disallow remote root login, and remove the test database and access to secure MariaDB:
Configure it like this:
- Set root password? [Y/n] y - Remove anonymous users? [Y/n] y - Disallow root login remotely? [Y/n] y - Remove test database and access to it? [Y/n] y - Reload privilege tables now? [Y/n] y
Next, we will need to log in to the MariaDB console and create a database for the Craft CMS. Run the following command:
mysql -u root -p
This will prompt you for a password, so enter your MariaDB root password and hit Enter. Once you are logged in to your database server you need to create a database for Craft CMS installation:
CREATE DATABASE craft; CREATE USER 'craftuser'@'localhost' IDENTIFIED BY 'PASSWORD'; GRANT ALL PRIVILEGES ON `craft`.* TO 'craftuser'@'localhost'; FLUSH PRIVILEGES;
Step 6. Configuring Apache.
Now we create a new virtual host directive in Apache. For example, create a new Apache configuration file named ‘
craft.conf’ on your virtual server:
sudo nano /etc/apache2/sites-enabled/craft.conf
Add the following file:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot "/var/www/html/craft" ServerName craft.your-domain.com ServerAlias www.craft.your-domain.com <Directory "/var/www/html/craft"> Options Indexes FollowSymLinks AllowOverride All Require all granted </Directory> ErrorLog "/var/log/apache2/craft-error_log" CustomLog "/var/log/apache2/craft-access_log" combined </VirtualHost>
Now, we can restart the Apache webserver so that the changes take place:
sudo a2enmod rewrite sudo a2ensite craft.conf sudo systemctl restart apache2
Step 7. Configure Firewall.
Run the following commands to allow HTTP (80) and HTPPS (443) requests through the firewall.
sudo ufw allow 80/tcp sudo ufw allow 443/tcp sudo ufw reload
Step 8. Accessing Craft CMS Web Interface.
Once successfully installed, open your web browser and navigate the URL
http://craft.your-domain.com and you should see the welcome screen:
Congratulations! You have successfully installed Craft CMS. Thanks for using this tutorial for installing Craft CMS on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you to check the official Craft CMS website.