How To Install Contao on Ubuntu 24.04 LTS
Contao is a robust, open-source content management system (CMS) renowned for its user-friendly interface and flexibility. Designed for professionals and developers alike, Contao offers a wide range of features including multilingual support, responsive design capabilities, and strong security measures. These attributes make it an excellent choice for creating dynamic and scalable websites.
Installing Contao on Ubuntu 24.04 LTS provides a stable and secure environment, leveraging Ubuntu’s long-term support and extensive community resources. This guide aims to walk you through the installation process step-by-step, ensuring a smooth setup of Contao on your Ubuntu server. Whether you’re a seasoned developer or a beginner, this comprehensive tutorial will equip you with the knowledge needed to get Contao up and running efficiently.
Prerequisites
Before diving into the installation, ensure your system meets the following prerequisites:
- System Requirements: A server running Ubuntu 24.04 LTS with at least 2GB of RAM and sufficient storage space. Ensure you have the latest updates installed using
sudo apt update && sudo apt upgrade
. - Software Dependencies: Contao requires PHP 8.1 or higher, a database server like MySQL 8 or MariaDB, and a web server such as Apache or Nginx.
- Access Requirements: Root or sudo privileges are necessary to install and configure system packages. Additionally, SSH access to your server is essential for executing commands remotely.
- Additional Tools: Basic utilities like
wget
,curl
, andunzip
should be installed to facilitate the download and extraction of necessary files.
Step-by-Step Installation Guide
1. Update System and Install Basic Utilities
Start by updating your system packages to ensure all existing software is up-to-date. This minimizes compatibility issues during the installation process.
sudo apt update && sudo apt upgrade -y
Next, install essential utilities required for downloading and managing files:
sudo apt install wget curl unzip -y
2. Install and Configure Web Server
Contao can operate on either Apache or Nginx web servers. Choose the one that best fits your needs.
Option A: Apache
Install Apache using the following command:
sudo apt install apache2 -y
Enable the mod_rewrite
module, which is essential for URL rewriting in Contao:
sudo a2enmod rewrite
Restart Apache to apply the changes:
sudo systemctl restart apache2
Option B: Nginx
If you prefer Nginx, install it using:
sudo apt install nginx -y
Configure Nginx to serve Contao by creating a server block:
sudo nano /etc/nginx/sites-available/contao
Add the following configuration:
server {
listen 80;
server_name yourdomain.com;
root /var/www/contao/web;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
}
location ~ /\.ht {
deny all;
}
}
Enable the configuration and restart Nginx:
sudo ln -s /etc/nginx/sites-available/contao /etc/nginx/sites-enabled/
sudo systemctl restart nginx
3. Install PHP and Required Extensions
Contao requires PHP 8.1 or higher. Install PHP along with necessary extensions:
sudo apt install php8.1 php8.1-xml php8.1-pear php8.1-intl php8.1-common php8.1-json php8.1-curl php8.1-mbstring php8.1-mysql php8.1-gd php8.1-imagick php8.1-zip php8.1-opcache -y
For Apache users, install the PHP module:
sudo apt install libapache2-mod-php8.1 -y
Verify the PHP installation:
php -v
You should see an output similar to:
PHP 8.1.x (cli) (built: ...)
4. Install Database Server
Contao supports both MySQL and MariaDB. Here’s how to install MariaDB:
sudo apt install mariadb-server mariadb-client -y
Secure your MariaDB installation:
sudo mysql_secure_installation
Follow the prompts to set a strong root password, remove anonymous users, disallow root login remotely, remove the test database, and reload privilege tables.
Create a database and a dedicated user for Contao:
sudo mysql -u root -p
CREATE DATABASE contaodb;
CREATE USER 'contaouser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON contaodb.* TO 'contaouser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
5. Download and Configure Contao Files
Navigate to the temporary directory and download the Contao Manager:
cd /tmp/
wget https://download.contao.org/contao-manager/stable/contao-manager.phar -O contao-manager.phar.php
Create the Contao installation directory and move the downloaded file:
sudo mkdir -p /var/www/contao/web
sudo mv contao-manager.phar.php /var/www/contao/web/
Set the appropriate permissions to ensure the web server can access the files:
sudo chown -R www-data:www-data /var/www/contao
6. Configure Web Server for Contao
Depending on your chosen web server, configure it to serve the Contao files.
For Apache:
Create a virtual host configuration for Contao:
sudo nano /etc/apache2/sites-available/contao.conf
Add the following content:
<VirtualHost *:80>
ServerName yourdomain.com
DocumentRoot /var/www/contao/web
<Directory /var/www/contao/web>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/contao_error.log
CustomLog ${APACHE_LOG_DIR}/contao_access.log combined
</VirtualHost>
Enable the site and rewrite module, then restart Apache:
sudo a2ensite contao.conf
sudo systemctl reload apache2
For Nginx:
Ensure the server block points to the correct document root, as configured earlier. Restart Nginx if necessary:
sudo systemctl restart nginx
7. Complete Installation Using Contao Manager
Access the Contao Manager through your web browser to finalize the installation:
- Navigate to
http://yourdomain.com/contao-manager.phar.php
. - Create an admin account by filling in the required details.
- Select the desired Contao version and proceed with the installation.
- Enter the database credentials you created earlier:
Database Host: localhost
Database Name: contaodb
Database User: contaouser
Database Password: your_password
- Finalize the installation by updating the database schema.
- Wait for the installation process to complete. This may take several minutes as Contao downloads necessary packages and performs configurations.
Once completed, you will be redirected to the Contao backend:
http://yourdomain.com/contao
Post-installation Steps
After installing Contao, perform the following steps to ensure your setup is secure and optimized:
- Accessing the Backend: Log in with the admin credentials you created. Familiarize yourself with the dashboard and explore initial setup options.
- Enable HTTPS: Secure your website by installing an SSL certificate using Let’s Encrypt:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache -d yourdomain.com
- Regular Updates: Keep Contao and your server packages up-to-date to protect against vulnerabilities:
sudo apt update && sudo apt upgrade -y
- Backup Strategy: Implement regular backups of your database and Contao files to prevent data loss.
Troubleshooting Common Issues
Encountered issues during installation? Here are solutions to common problems:
- PHP Extension Errors: Ensure all required PHP extensions are installed. Refer to step 4 for the complete list.
- Database Connection Issues: Verify database credentials and ensure the database server is running. Use
sudo systemctl status mariadb
to check. - Permission Problems: Confirm that the web server user (usually
www-data
) has the correct permissions to access Contao files:
sudo chown -R www-data:www-data /var/www/contao
Congratulations! You have successfully installed Contao. Thanks for using this tutorial for installing Contao CMS on Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the official Contao website.