Introduction

Craft CMS is a flexible and user-friendly content management system. This tutorial will guide you through the process of installing Craft CMS with Apache and securing it with Let's Encrypt SSL on Ubuntu 22.04 LTS.

Prerequisites

Before you begin, ensure you have:

  1. An Ubuntu 22.04 LTS server
  2. SSH access to the server (optional)
  3. Domain name pointed to your server's IP address

Step 1: Install Apache and PHP

Update the package index and install Apache and PHP:

sudo apt update
sudo apt install -y apache2 php libapache2-mod-php php-mysql php-mbstring php-xml php-gd

Step 2: Install MySQL/MariaDB

Install MySQL/MariaDB server:

sudo apt install -y mariadb-server

Run the MySQL/MariaDB secure installation script:

sudo mysql_secure_installation

Step 3: Create a Database for Craft CMS

Log in to the MySQL/MariaDB shell:

sudo mysql -u root -p

Create a new database and user for Craft CMS:

CREATE DATABASE craftcmsdb CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'craftcmsuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON craftcmsdb.* TO 'craftcmsuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Step 4: Download and Install Craft CMS

Download and extract the latest version of Craft CMS:

cd /var/www/html
wget https://craftcms.com/latest.zip
sudo apt install -y unzip
sudo unzip latest.zip
sudo mv craftcms/* .
sudo rm -rf craftcms latest.zip

Step 5: Configure Apache

Enable the Apache rewrite module:

sudo a2enmod rewrite

Create a new virtual host configuration file for Craft CMS:

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

Add the following configuration:

<VirtualHost *:80>
    ServerName your_domain.com
    DocumentRoot /var/www/html/public

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    <Directory /var/www/html/public>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

Enable the Craft CMS site and restart Apache:

sudo a2ensite craftcms.conf
sudo systemctl restart apache2

Step 6: Install Let's Encrypt SSL

Install Certbot and the Apache plugin:

sudo apt install -y certbot python3-certbot-apache

Obtain an SSL certificate for your domain:

sudo certbot --apache --agree-tos --redirect --hsts --staple-ocsp --email [email protected] -d your_domain.com

Step 7: Access Craft CMS

Open a web browser and navigate to https://your_domain.com. Follow the on-screen instructions to complete the Craft CMS installation.

Conclusion

Congratulations! You have successfully installed Craft CMS with Apache and secured it with Let's Encrypt SSL on Ubuntu 22.04 LTS. You can now start building your website with Craft CMS.

Was this answer helpful? 0 Users Found This Useful (0 Votes)