Knowledgebase

Install Craft CMS on Ubuntu 20.04 Print

  • 0

Introduction

Craft is a free and open-source Content Management System (CMS) based on PHP. A large community of developers supports it, hence the availability of plugins for customization to meet your usage needs. In addition, it allows you to have access and control over the whole system. Some of its core features are:

  • It also comes with a customizable backend.
  • Allows you to design the layout of your content to efficiently work with a team on with similar content.
  • Built-in management features.
  • Building and managing e‑commerce store.
  • Developers toolkit for developing components.

This article explains how to install Craft CMS on Ubuntu 20.04 server.

Prerequisites

1. Install Required Packages

Update system package list.

$ sudo apt update

Install PHP 7.4 and more modules.

$ sudo apt install apache2 mysql-server php7.4 libapache2-mod-php7.4 php7.4-json php7.4-common php7.4-gmp php7.4-curl php7.4-mysql php7.4-opcache php7.4-intl php7.4-fpm php7.4-xmlrpc php7.4-bcmath php7.4-zip php7.4-imagick php7.4-mbstring php7.4-gd php7.4-cli php7.4-xml php7.4-zip wget unzip curl -y

Edit the PHP configuration file.

$ sudo nano /etc/php/7.4/apache2/php.ini

Change the following values. To search for a specific line, use Control+W, enter search phrase then press Enter.

max_execution_time = 360
memory_limit = 512M
upload_max_filesize = 100M
post_max_size = 100M

Restart Apache2 service for all changes made to take effect.

$ sudo systemctl restart apache2

2. Create Craft CMS Database

Log in to MySQL shell. At the password prompt, just press Enter to continue. The names and passwords used can be changed to more secure credentials.

$ sudo mysql -u root -p

Create a database called craftcms.

CREATE DATABASE craftcms;

Create a database user called craftcmsuser with a password StrongPassword.

CREATE USER 'craftcmsuser'@'localhost' IDENTIFIED BY 'StrongPassword';

Grant the user full access to the database.

GRANT ALL ON craftcms.* TO 'craftcmsuser'@'localhost' WITH GRANT OPTION;

Save the changes made to the database.

FLUSH PRIVILEGES;

Exit MySQL shell.

exit;

3. Install Craft CMS

Download the Composer setup file.

$ curl -sS https://getcomposer.org/installer -o composer-setup.php

Install Composer.

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

Navigate to the web root directory.

$ cd /var/www/html

Use Composer to download Craft CMS application. You will get a prompt to enter the database details.

$ composer create-project craftcms/craft craftcms

Generate secret key for configuration.

$ cd craftcms

$ php craft setup/security-key

Change ownership of the installation directory.

$ sudo chown -R www-data:www-data /var/www/html/craftcms

Change access permissions for the directory.

$ sudo chmod -R 755 /var/www/html/craftcms

Configure Apache2

Create Apache configuration file for Craft CMS.

$ sudo nano /etc/apache2/sites-available/craftcms.conf

Add the following block of code to the file. Then, save and close the file:

<VirtualHost *:80>
ServerAdmin admin@example.com
DocumentRoot /var/www/html/craftcms/web
ServerName example.com
ServerAlias www.example.com

     <Directory /var/www/html/craftcms/web/>
          Options FollowSymlinks
          AllowOverride All
          Require all granted
     </Directory>

     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
    
     <Directory /var/www/html/craftcms/web/>
            RewriteEngine on
            RewriteBase /
            RewriteCond %{REQUEST_FILENAME} !-f
            RewriteRule ^(.*) index.php [PT,L]
    </Directory>
</VirtualHost>

Enable the new Apache configuration file.

$ sudo a2ensite craftcms.conf

Disable Apache default configuration file.

$ sudo a2dissite 000-default.conf

Enable Apache rewrite mode.

$ sudo a2enmod rewrite

Restart Apache service.

$ sudo systemctl restart apache2

5. Access Craft CMS Web Interface

To access the Craft CMS Web Interface, go to your browser and visit http://Server_IP/. For example:

http://192.0.2.10/

Conclusion

You have installed Craft CMS on your server. Access the Installation Wizard screen to complete installation by connecting to your database and creating an administrator account. Log in with the username and password you made during the installation. You can now access the Dashboard and begin to manage your online shop.

More Information

To learn more about using Craft CMS, go to the official documentation page.

Introduction Craft is a free and open-source Content Management System (CMS) based on PHP. A large community of developers supports it, hence the availability of plugins for customization to meet your usage needs. In addition, it allows you to have access and control over the whole system. Some of its core features are: It also comes with a customizable backend. Allows you to design the layout of your content to efficiently work with a team on with similar content. Built-in management features. Building and managing e‑commerce store. Developers toolkit for developing components. This article explains how to install Craft CMS on Ubuntu 20.04 server. Prerequisites Deploy a fully updated Rcs Ubuntu 20.04 Server. Create a non-root user with sudo access. 1. Install Required Packages Update system package list. $ sudo apt update Install PHP 7.4 and more modules. $ sudo apt install apache2 mysql-server php7.4 libapache2-mod-php7.4 php7.4-json php7.4-common php7.4-gmp php7.4-curl php7.4-mysql php7.4-opcache php7.4-intl php7.4-fpm php7.4-xmlrpc php7.4-bcmath php7.4-zip php7.4-imagick php7.4-mbstring php7.4-gd php7.4-cli php7.4-xml php7.4-zip wget unzip curl -y Edit the PHP configuration file. $ sudo nano /etc/php/7.4/apache2/php.ini Change the following values. To search for a specific line, use CONTROL+W, enter search phrase then press ENTER. max_execution_time = 360 memory_limit = 512M upload_max_filesize = 100M post_max_size = 100M Restart Apache2 service for all changes made to take effect. $ sudo systemctl restart apache2 2. Create Craft CMS Database Log in to MySQL shell. At the password prompt, just press ENTER to continue. The names and passwords used can be changed to more secure credentials. $ sudo mysql -u root -p Create a database called craftcms. CREATE DATABASE craftcms; Create a database user called craftcmsuser with a password StrongPassword. CREATE USER 'craftcmsuser'@'localhost' IDENTIFIED BY 'StrongPassword'; Grant the user full access to the database. GRANT ALL ON craftcms.* TO 'craftcmsuser'@'localhost' WITH GRANT OPTION; Save the changes made to the database. FLUSH PRIVILEGES; Exit MySQL shell. exit; 3. Install Craft CMS Download the Composer setup file. $ curl -sS https://getcomposer.org/installer -o composer-setup.php Install Composer. $ sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer Navigate to the web root directory. $ cd /var/www/html Use Composer to download Craft CMS application. You will get a prompt to enter the database details. $ composer create-project craftcms/craft craftcms Generate secret key for configuration. $ cd craftcms $ php craft setup/security-key Change ownership of the installation directory. $ sudo chown -R www-data:www-data /var/www/html/craftcms Change access permissions for the directory. $ sudo chmod -R 755 /var/www/html/craftcms Configure Apache2 Create Apache configuration file for Craft CMS. $ sudo nano /etc/apache2/sites-available/craftcms.conf Add the following block of code to the file. Then, save and close the file: ServerAdmin admin@example.com DocumentRoot /var/www/html/craftcms/web ServerName example.com ServerAlias www.example.com Options FollowSymlinks AllowOverride All Require all granted ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*) index.php [PT,L] Enable the new Apache configuration file. $ sudo a2ensite craftcms.conf Disable Apache default configuration file. $ sudo a2dissite 000-default.conf Enable Apache rewrite mode. $ sudo a2enmod rewrite Restart Apache service. $ sudo systemctl restart apache2 5. Access Craft CMS Web Interface To access the Craft CMS Web Interface, go to your browser and visit http://Server_IP/. For example: http://192.0.2.10/ Conclusion You have installed Craft CMS on your server. Access the Installation Wizard screen to complete installation by connecting to your database and creating an administrator account. Log in with the username and password you made during the installation. You can now access the Dashboard and begin to manage your online shop. More Information To learn more about using Craft CMS, go to the official documentation page.

Was this answer helpful?
Back

Powered by WHMCompleteSolution