Craft CMS is a powerful and flexible content management system that allows developers and content authors to build bespoke websites. With its extensive customization features and a wide range of plugins, Craft CMS offers an alternative solution to WordPress and Drupal. In this article, we will guide you through the process of installing Craft CMS with Apache and Let’s Encrypt SSL on Ubuntu 22.04 LTS.
Prerequisites
Before we begin, make sure you have the following:
- A server running Ubuntu 22.04.
- A valid domain name pointed to your server’s IP address.
- Root password configured on the server.
Step 1: Install LAMP Server
Craft CMS requires a LAMP (Linux, Apache, MySQL/MariaDB, PHP) stack to run. To install the necessary packages, open the terminal and run the following command:
sudo apt-get update sudo 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
Once the installation is complete, edit the PHP configuration file to change the default settings:
sudo nano /etc/php/8.1/php.ini
Modify the following settings:
memory_limit = 512M post_max_size = 32M upload_max_filesize = 32M max_execution_time = 360
Save and close the file. Restart the Apache service to apply the changes:
sudo systemctl restart apache2
Step 2: Create a Database for CraftCMS
Craft CMS requires a database backend to store its data. We will use MariaDB for this purpose. Log in to the MariaDB shell with the following command:
sudo mysql -u root
Once you are logged in, create a database and user for Craft CMS:
CREATE DATABASE craftcms; GRANT ALL ON craftcms.* TO 'craftuser' IDENTIFIED BY 'password'; FLUSH PRIVILEGES; EXIT;
Replace ‘password’ with a strong password for the Craft CMS database user. With this, the MariaDB database is ready for Craft CMS.
Step 3: Install Craft CMS Using Composer
Composer is a dependency management tool for PHP. We will use Composer to download and install the latest version of Craft CMS. Install Composer by running the following command:
curl -sS https://getcomposer.org/installer | sudo php ----install-dir=/usr/local/bin --filename=composer
Once Composer is installed, navigate to the Apache web root directory and create a Craft CMS project:
cd /var/www/html sudo composer create-project craftcms/craft craftcms
During the installation, you will be prompted to provide your database settings, admin username, password, and site URL. Enter the required information as prompted.
Set the proper permissions and ownership for the Craft CMS directory:
sudo chown -R www-data:www-data /var/www/html/craftcms sudo chmod -R 755 /var/www/html/craftcms
Step 4: Configure Apache for Craft CMS
Next, we need to create an Apache virtual host configuration file for Craft CMS. Run the following command to create the configuration file:
sudo nano /etc/apache2/sites-available/craftcms.conf
Add the following lines to the file:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
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 and close the file. Activate the Apache virtual host and the rewrite module:
sudo a2ensite craftcms.conf
sudo a2enmod rewrite
Restart the Apache service to apply the changes:
sudo systemctl restart apache2
Verify the status of the Apache service:
sudo systemctl status apache2
Step 5: Access Craft CMS Web Interface
Now that the configuration is complete, you can access the Craft CMS web interface by entering your site URL in a web browser. For example, if your site URL is http://craftcms.example.com
, enter that URL in your browser.
You should see the Craft CMS installation wizard. Follow the on-screen instructions to complete the installation. After installation, you will be redirected to the Craft CMS login page.
Enter the admin username and password you set during the installation process. Once logged in, you will have access to the Craft CMS dashboard.
Step 6: Secure Craft CMS with Let’s Encrypt SSL
To secure your Craft CMS website with Let’s Encrypt SSL, install the Certbot client package:
sudo apt-get install python3-certbot-apache -y
After the installation, run the following command to secure your website with Let’s Encrypt SSL:
sudo certbot --apache -d craftcms.example.com
Follow the prompts to provide your email address and accept the terms of service. Choose the appropriate redirect option, either redirecting all HTTP traffic to HTTPS or not. Let’s Encrypt will automatically obtain and install the SSL certificate for your website.
Conclusion
Congratulations! You have successfully installed Craft CMS with Apache and Let’s Encrypt SSL on Ubuntu 22.04 LTS. You can now explore the powerful features of Craft CMS and start building your website. If you have any questions or need further assistance, feel free to reach out to us at Shape.host. We provide reliable and scalable Linux SSD VPS hosting services to help businesses thrive in the digital world.