Craft CMS is a robust, open-source content management system (CMS) designed for developers and content creators who need flexibility. It provides extensive customization options to create powerful websites and manage content across multiple sites from a unified dashboard. As a viable alternative to WordPress and Drupal, Craft CMS supports numerous free and paid plugins to enhance functionality.
In this guide, we’ll walk you through installing Craft CMS with Apache and securing it with Let’s Encrypt SSL on Ubuntu 22.04.
Prerequisites
- An Ubuntu 22.04 server.
- A valid domain name pointing to your server’s IP address.
- Root user access to the server.
Install LAMP Server
Since Craft CMS relies on PHP and MariaDB, you’ll need to set up a LAMP stack on your server.
Run the following command to install Apache, MariaDB, and PHP with all necessary extensions:
apt-get install apache2 mariadb-server php php-cli libapache2-mod-php php-common php-json php-curl php-gd php-imagick php-json php-mbstring php-mysql php-pgsql php-zip php-intl php-xml -y
After installation, edit PHP’s configuration file to optimize its default settings:
nano /etc/php/8.1/php.ini
Modify these parameters:
memory_limit = 512M post_max_size = 32M upload_max_filesize = 32M max_execution_time = 360
Save your changes and restart Apache:
systemctl restart apache2
Create a Database for Craft CMS
Create a database and user for Craft CMS by logging into the MariaDB shell:
mysql
Execute the following commands to set up the database and user:
MariaDB [(none)]> CREATE DATABASE craftcms; MariaDB [(none)]> GRANT ALL ON craftcms.* TO 'craftuser' IDENTIFIED BY 'password';
Then, flush the privileges and exit:
MariaDB [(none)]> FLUSH PRIVILEGES; MariaDB [(none)]> EXIT;
Install Craft CMS Using Composer
Next, install Composer to fetch the latest version of Craft CMS:
curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer
Create a new Craft CMS project by running the following commands in Apache’s web root directory:
cd /var/www/html composer create-project craftcms/craft craftcms
You’ll be prompted to enter your database settings and site details:
Which database driver are you using? (mysql or pgsql) [mysql] Database server name or IP address: [127.0.0.1] Database port: [3306] Database username: [root] craftuser Database password: Database name: craft Database table prefix: Testing database credentials ... success! Saving database credentials to your .env file ... done Install Craft now? (yes|no) [yes]:yes Username: [admin] admin Email: admin@example.com Password: Confirm: Site name: CraftCMS Site Site URL: http://craftcms.example.com Site language: [en-US]
Set the proper file permissions for the Craft CMS directory:
chown -R www-data:www-data /var/www/html/craftcms/ chmod -R 755 /var/www/html/craftcms/
Configure Apache for Craft CMS
Create a virtual host configuration file for Craft CMS:
nano /etc/apache2/sites-available/craftcms.conf
Insert the following configuration:
<VirtualHost *:80> ServerAdmin admin@example.com DocumentRoot /var/www/html/craftcms/web ServerName craftcms.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>
Save the file, then activate the site and enable Apache’s rewrite module:
a2ensite craftcms.conf a2enmod rewrite
Restart Apache to implement these changes:
systemctl restart apache2
Verify Apache’s status:
systemctl status apache2
Access Craft CMS Web Interface
Visit http://craftcms.example.com in your browser. You should see the Craft CMS welcome page:
Click go to your control panel to reach the login page:
Enter your admin credentials to access the Craft CMS dashboard:
Secure Craft CMS with Let’s Encrypt SSL
To secure your site with SSL, first, install Certbot:
apt-get install python3-certbot-apache -y
Run Certbot to obtain and install a free SSL certificate from Let’s Encrypt:
certbot --apache -d craftcms.example.com
Provide your email address and agree to the terms of service. You will then decide whether to redirect HTTP traffic to HTTPS:
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2
Type ‘2’ to enforce HTTPS, completing your SSL setup:
Enabled Apache rewrite module Redirecting vhost in /etc/apache2/sites-enabled/craftcms.conf to ssl vhost in /etc/apache2/sites-available/craftcms-le-ssl.conf - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://craftcms.example.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=craftcms.example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Conclusion
Congratulations on installing Craft CMS with Apache and securing it with Let’s Encrypt SSL on Ubuntu 22.04! You’ve set the stage for building dynamic digital experiences. Should you have any questions, feel free to reach out.
Frequently Asked Questions (FAQ)
Q1: What is Craft CMS?
A1: Craft CMS is an open-source content management system that offers the flexibility to build highly customized websites and manage content efficiently.
Q2: Why choose Craft CMS over WordPress or Drupal?
A2: Craft CMS is often chosen for its intuitive user interface, developer-friendly customization options, and powerful templating framework, making it ideal for bespoke website development.
Q3: Is Craft CMS free to use?
A3: Yes, Craft CMS is free for personal projects and small websites. However, it also offers premium features under a paid license for larger or commercial projects.
Q4: Can I add plugins to Craft CMS?
A4: Absolutely! Craft CMS supports an extensive library of free and paid plugins to extend its functionality.
Q5: How can I ensure my Craft CMS installation is secure?
A5: Besides installing Let’s Encrypt SSL for secure data transmission, regularly update Craft CMS and its plugins, use strong passwords, and limit access to your administrative accounts.