Self-Hosting A Free Website with Raspberry Pi 5 – Setting Up Drupal

Imagine creating a professional-grade website on a platform that costs less than dinner for two. With the Raspberry Pi 5 and Drupal, this dream is a reality. In an age of decentralized solutions and cost-effective hosting, the Raspberry Pi 5 (RPi5) has emerged as a robust tool for enthusiasts and professionals alike. Pairing its power with Drupal, an open-source content management system, you can self-host a professional-grade website for free. This guide will walk you through the entire process of setting up a Drupal-powered website on the Raspberry Pi 5


Disclaimer: Hosting a website from home can expose your network to security risks. Always ensure you have robust security measures in place, and consult with your ISP to confirm that hosting is permitted under your service agreement.

How to Navigate This Series

This guide helps you set up a self-hosted Drupal website on a Raspberry Pi 5, ideal for flexible, content-rich websites and community platforms. After completing your Drupal installation, proceed to our Cloudflare setup to secure and enhance your site.

  • Complete the Core Setup: Follow the instructions here to install and configure Drupal on your Raspberry Pi 5.
  • Complete Cloudflare: After installing Drupal, refer to our Cloudflare Setup Guide to enhance the security, performance, and speed of your website.

Why Raspberry Pi 5 and Drupal Make a Great Pair

Raspberry Pi 5: A Powerful Upgrade

The RPi5 surpasses the capabilities of its predecessors. With its faster processor, improved memory, and hardware-accelerated video decoding, it’s perfectly suited for running lightweight servers. Its affordability and compact design make it an excellent choice for hosting websites.

Drupal: Open-Source and Flexible

Drupal is a highly versatile CMS known for its scalability and modular architecture. It supports blogs, forums, e-commerce sites, and more. Whether you're a developer or a novice, Drupal provides the tools to build a feature-rich website.

Combining these two technologies results in an optimal blend of flexibility, performance, and cost-efficiency. Drupal requires a LAMP stack (Linux, Apache, MySQL, PHP). Here’s how we are going to get it set up. First, we will start with the Linux environment:

Get Started: Setting Up Your Linux Server Environment

Once you have the necessary hardware, the next step is to set up your Linux server environment. Using Ubuntu Server on your SSD or NVMe drive provides a robust and efficient platform that's well-suited for hosting your Drupal blog. While microSD cards are fine for testing purposes, SSDs or NVMe drives offer significantly better performance and reliability for production use. Here's how to get your Linux environment up and running:

Install Your Linux Distribution

Choosing the right Linux distribution is key to ensuring smooth performance on your Raspberry Pi. Ubuntu Server is an excellent choice due to its minimal footprint and compatibility with most web hosting requirements.

  1. Download the OS: Start by downloading the Ubuntu Server image from the official Ubuntu website. Choose the 64-bit version for optimal performance and compatibility with modern applications. You can also use Raspberry Pi OS Lite (64-bit) successfully.
  2. Prepare Your Storage Device:
    • For Testing (MicroSD Card): If you're in the testing phase, a microSD card will suffice. Ensure it's a high-quality, high-speed card to minimize performance bottlenecks.
    • For Production (SSD or NVMe Drive): Connect an SSD or NVMe drive via USB 3.0 to ensure a stable and fast production environment. This setup significantly enhances read/write speeds and improves overall reliability.
  3. Flash the OS Image: Use a tool like Raspberry Pi Imager or balenaEtcher to flash the Ubuntu Server image onto your chosen storage device.
  4. Open Raspberry Pi Imager on your computer.
  5. Select "Choose OS" and pick Ubuntu Server 22.04 LTS (64-bit) from the list.
  6. Select "Choose Storage" and choose your target storage device—this could be an SSD, NVMe drive, or microSD card.
  7. Click "Write" to initiate the flashing process. A prompt will appear asking if you'd like to customize your installation.
  8. Choose "Yes" to access customization options:
    • Set Hostname: Assign a unique name to your Raspberry Pi for easy identification on your network.
    • Enable SSH: Activate SSH for remote access by selecting this option and setting a secure password or providing an SSH key.
    • Configure Wi-Fi: Enter your Wi-Fi network's SSID and password to enable wireless connectivity.
    • Set Locale: Adjust language, time zone, and keyboard layout to match your preferences.
  1. After configuring these settings, proceed with the flashing process.

After successfully flashing the OS image onto your chosen storage device, it's time to boot up your Raspberry Pi. Insert your SSD, NVMe drive, or microSD card into the Raspberry Pi, connect it to a power source, and allow it to start. The system will initialize and set up the basic environment, which may take a few minutes on the first run.

Once your Raspberry Pi has booted up, the next step is to update your system to ensure it has the latest features and security patches. If you’ve preconfigured SSH during the flashing process, you can simply SSH into your Raspberry Pi from another device on the same network using a command like this:

ssh username@your-pi-hostname.local

hostname you set earlier. If the hostname isn't working, you can use the Pi's IP address instead.)

If SSH wasn’t preconfigured, you’ll need to connect a keyboard and monitor to your Raspberry Pi to make some initial changes. Once logged in, follow these steps:

  1. Update your system to ensure it’s secure and stable by running:
sudo apt update && sudo apt upgrade -y

This command refreshes the package list and applies available updates.

  1. If you haven't already, run the following command to enable SSH for remote access:
sudo systemctl enable ssh
sudo systemctl start ssh

Now, with SSH enabled, you can manage your Raspberry Pi remotely from any device on the same network. This provides flexibility and convenience for future configurations.

Pro Tip: For enhanced SSH security, disable password-based logins and use key-based authentication. Edit the SSH config file (/etc/ssh/sshd_config) and set PasswordAuthentication no. This minimizes vulnerability to brute-force attacks.

You have successfully set up and prepared your Linux server environment. Next, you’ll proceed to configure your web server and install your database, bringing you closer to launching your self-hosted website.

Web Server Installation ✅

With your Linux environment ready, the next step is to set up a web server. For this guide, we’ll be using Apache HTTP Server. Alternatively, you can use NGINX, which is a popular choice for hosting due to its lightweight design, speed, and compatibility with modern web standards.

  • Apache: Known for its versatility and ease of use, Apache HTTP Server is a fantastic choice for beginners. It handles dynamic content efficiently, supporting pages that rely on scripting languages like PHP.
  • Nginx: Optimized for speed and memory efficiency, Nginx excels at serving high-traffic sites and static content. It manages multiple simultaneous connections with ease, though it does have a steeper learning curve for new users.

Setting up Apache on your Raspberry Pi is a straightforward process. Follow the step-by-step commands below to install and configure Apache:

  1. Update Your System
    Before installing Apache, make sure your system is up-to-date:
sudo apt update && sudo apt upgrade -y
  1. Install Apache HTTP Server
    Install Apache using the package manager:
sudo apt install apache2 -y
  1. Verify Apache Installation
    After installation, verify that Apache is running by checking its status:
sudo systemctl status apache2

You should see a message indicating that Apache is active and running.

  1. Test Apache
    To confirm Apache is working:
    1. Open your browser and go to your Raspberry Pi's IP address (e.g., http://192.168.x.x).
    2. You should see the default Apache welcome page. (To find your Pi’s IP address you can use this command: hostname -I
  2. Enable Apache to Start on Boot
    Ensure Apache starts automatically when the Raspberry Pi reboots:
sudo systemctl enable apache2
  1. Adjust Firewall Settings (if applicable)
    If you have ufw (Uncomplicated Firewall) enabled, allow HTTP traffic:
sudo ufw allow 'Apache'
  1. Restart Apache (to Apply Changes)
    After making any configuration changes, restart Apache:
sudo systemctl restart apache2
Pro Tip: If you expect high traffic or want faster response times, enable caching modules like mod_cache and mod_expires. Use sudo a2enmod cache expires to improve page loading speed for repeated visitors.

Database Installation

A reliable database is essential for storing and managing your website’s data, especially when using a platform like Drupal that relies on databases for content, user information, and configuration settings. For this setup, MariaDB is a popular open-source option that serves as a high-performance, drop-in replacement for MySQL. Known for its simplicity and compatibility, MariaDB is an excellent choice for self-hosting, efficiently handling dynamic content and ensuring smooth, dependable operation.

Installing MariaDB

Follow these steps to install and configure MariaDB on your Linux server.

  1. Update Your System: As always, it’s best practice to start by updating your package list to ensure you’re downloading the latest version of MariaDB. Open a terminal and enter:
sudo apt update && sudo apt upgrade -y
  1. Install MariaDB: Use the following command to install MariaDB on your system. This command will download MariaDB along with all necessary dependencies:
sudo apt install mariadb-server -y
  1. Start and Enable MariaDB: After installation, start the MariaDB service and set it to run automatically on startup with these commands:
sudo systemctl start mariadb
sudo systemctl enable mariadb

This ensures that your database server is up and running whenever your server is active.

  1. Secure the Installation: For security, it’s important to configure MariaDB by running the following security script:
sudo mysql_secure_installation

This will prompt you to set a root password and make some security adjustments, such as removing anonymous users, disallowing remote root login, and deleting the test database. For each prompt, it’s generally recommended to select the secure option (Y) to strengthen the database’s security.

  1. Verify Installation: To confirm MariaDB is running, use the following command to check the service status:
sudo systemctl status mariadb

You should see an active status, indicating that MariaDB is up and running.

You can also log into the MariaDB shell to confirm:

sudo mysql -u root -p

Enter the root password you set during the secure installation step. If you successfully enter the MariaDB shell, the installation is complete.

Pro Tip: Install mysqltuner to monitor and optimize MariaDB performance over time. Run sudo apt install mysqltuner and periodically check for recommended adjustments as your database grows.

Installing and Configuring PHP

Follow these steps to install and configure PHP on your Linux server to ensure compatibility with Drupal.

  • Drupal 11 requires at least PHP 8.3
  • Drupal 10 requires at least PHP 8.1
  1. Update Your System
    Before installing PHP, ensure your package list is up-to-date. This ensures you’re getting the latest stable version of PHP available.
sudo apt update && sudo apt upgrade -y
  1. Enable the deb.sury.org Repository
    Ondřej Surý also maintains a repository for PHP packages specifically for Debian. Run the following commands to add it:
sudo apt install software-properties-common lsb-release ca-certificates -y

sudo wget -qO /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg

echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list

sudo apt update
  1. Install PHP 8.3 and Necessary Extensions
    Specify PHP 8.3 explicitly to ensure the correct version is installed:
sudo apt install php8.3 php8.3-mysql php8.3-xml php8.3-gd php8.3-curl php8.3-mbstring php8.3-json php8.3-zip libapache2-mod-php8.3 -y
  1. Verify the Installation
    Confirm that PHP 8.3 has been installed successfully:
php -v
  1. Restart Apache
    For the changes to take effect, restart the Apache web server:
sudo systemctl restart apache2

PHP is now installed and configured on your server for running Drupal. With the required extensions and settings in place, your system is ready for the next steps in the installation process.

Drupal Installation Guide

Prepare your server to host your Drupal site by downloading the latest stable version, extracting the files, and setting the correct permissions. These steps are essential for ensuring that your web server can access and serve your Drupal installation without issues.

Prerequsites:

Composer requires Git to download packages from source. Install Git using the following command:

sudo apt update && sudo apt install git -y

After installing Git, confirm that it’s in your PATH with this command: git --version

Install Composer

Before we can install Drupal, we need to first install Composer. We are going to download and install it globally:

cd /var/www

Then we will enter each of these commands:

sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

sudo php -r "if (hash_file('sha384', 'composer-setup.php') === 'dac665fdc30fdd8ec78b38b9800061b4150413ff2e3b6f88543c636f7cd84f6db9189d43a81e5503cda447da73c7e5b6') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

sudo php composer-setup.php

sudo php -r "unlink('composer-setup.php');"

Now to make Composer globally available, use this command:

sudo mv composer.phar /usr/local/bin/composer

Now lets check that it is working with the command: composer -v

We should see this to tell us it is working. Now we will use Composer to install Drupal.

Install Drupal

composer create-project drupal/recommended-project drupal

Let’s break this down step by step. Composer is essentially a package manager, much like apt for Linux. It helps you manage dependencies and install software. Similar to apt, Composer uses specific commands to perform actions—here, we use the create-project command.

The create-project command sets up a Drupal Composer project template, organizing the files so that the "index.php" and "core" directory are placed inside a subfolder called web. This structure is recommended because it enhances security by allowing you to configure your web server to restrict access to files outside the web directory.

Finally, drupal in the command specifies the directory where you want to install the project. You can name this directory anything, though it’s common practice to place it within /var/www for web projects.

Choose your desired directory and run the command above to get started!

Set Up Permissions:

  • Adjust the ownership of the directory (chown) to the www-data user and group and the permissions (chmod) to prevent unauthorized access, to which Apache uses to serve content:
sudo chown -R www-data:www-data /var/www/drupal
sudo chmod -R 755 /var/www/drupal

MySQL (MariaDB) Setup

Create a Database for Your Website: Drupal requires a dedicated database for storing content and configurations. While logged into the MariaDB shell, create a database and user specifically for Drupal.

  • To access, use the command: sudo mysql -u root -p

Enter the following commands:

CREATE DATABASE drupal_db;
CREATE USER 'drupal_user'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON drupal_db.* TO 'drupal_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;

Replace drupal_db, drupal_user, and your_password with your own values. This setup grants the user access to the database, which your website platform will use to store and retrieve data. With MariaDB installed and configured, you now have a fully operational database ready to support your website.

Setting Up an Apache Virtual Host for Drupal

To configure Apache to serve your Drupal site, you'll need to create a virtual host file:

  1. Open a new configuration file for your site:
sudo nano /etc/apache2/sites-available/drupal.conf
  1. Add the following content:
<VirtualHost *:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/drupal/web
    ServerName your-raspberry-pi-ip
    
    <Directory /var/www/drupal/web>
        AllowOverride All
        Require all granted
    </Directory>
    
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

You should be able to copy and paste this into the nano editor with CTRL-SHIFT-V

Replace your-raspberry-pi-ip with your Pi's IP address and webmaster@localhost with your email address. If you don't know your IP address, use this command: hostname -I

Once you have made the changes, you can press CTRL-X then Y and finally ENTER to save the changes.

  1. Enable the new site and the required Apache modules:
sudo a2ensite drupal.conf
sudo a2enmod proxy proxy_http rewrite
  1. Restart Apache to apply the changes:
sudo systemctl restart apache2
  1. Complete the Drupal Setup

Open a web browser on your computer and navigate to your Raspberry Pi’s IP address. http://your-raspberry-pi-ip

    • Select the language.
    • Configure the database using the credentials created earlier (drupal_db, drupal_user, and your_password).
    • Complete the setup and configure the site.

As mentioned earlier in this guide, this is the point where you transition to our Cloudflare setup article to configure your domain.

Maintenance: Keeping Your Site Running Smoothly

Regular maintenance is essential for ensuring your self-hosted site remains secure, responsive, and up-to-date. By setting up automated backups, regularly updating software, and understanding common issues, you can keep your website running smoothly with minimal downtime.

Updating

Keeping both your system and application software updated is crucial for security and functionality.

  • System Updates:
    • Regularly update your server’s operating system to ensure security patches and new features are applied. On most Linux distributions, use:
    • Use cloud storage services like Google Drive, Amazon S3, or Dropbox for remote backups. This adds an extra layer of protection in case of hardware failures on your main server.
Pro Tip: Set up automated backups with a cron job to ensure your data is safe. Use mysqldump for database backups and rsync for file backups. For example, schedule backups using crontab -e and add this line: 0 2 * * * mysqldump -u root -p drupal_db > /path/to/backup.sql.
sudo apt update && sudo apt upgrade -y
    • Consider setting up unattended upgrades to automate security updates:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure unattended-upgrades
  • Application Updates:
    • CMSs like WordPress, Drupal, or Ghost frequently release updates with security patches and new features. Set notifications to remind you when updates are available, and regularly check the platform’s dashboard or use plugins to automate updates.
    • For other applications, review each update’s release notes, especially if you’ve customized your setup, to ensure compatibility with existing plugins and configurations.
Tip: Over time, backup files, cache, and logs can consume significant disk space. Use tools like ncdu to visualize disk usage and periodically delete unnecessary files
Use monitoring tools like UptimeRobot or Pingdom to receive alerts if your site goes offline. These tools monitor server response times and can send notifications via email or SMS if they detect downtime.

By scheduling regular backups, staying on top of updates, and proactively addressing common issues, you’ll maintain a secure, efficient website that continues to deliver a reliable experience to visitors


Conclusion

Self-hosting a website with Raspberry Pi 5 and Drupal is a rewarding project. With its robust hardware and Drupal’s open-source flexibility, you can create a powerful online presence without spending a fortune.

Ready to dive in? You can start building your website or blog from the Drupal admin interface.


Resources and Further Learning

Building and maintaining a self-hosted website is a continuous learning journey, and accessing the right resources can make the process much smoother. From online forums and educational platforms to comprehensive documentation, here are some valuable resources to help you troubleshoot, expand your skills, and stay up-to-date with the latest best practices.

Forums

Online forums are essential for troubleshooting issues, sharing ideas, and connecting with other developers and enthusiasts. Here are some of the best forums for support and guidance:

  • Stack Overflow: An extensive community of developers ready to help with coding and development questions.Stack Overflow's extensive archive of questions and answers is invaluable, whether you're struggling with server configuration, coding errors, or platform-specific issues..
  • Raspberry Pi Forums: For those using a Raspberry Pi as their server, the official Raspberry Pi Forums offer dedicated support for Pi-specific challenges. Topics include hardware compatibility, networking setup, and project ideas, making it a go-to resource for Pi users.
  • Cloudflare Community: The Cloudflare Community is a hub for users looking to optimize DNS settings, enable CDN, and troubleshoot performance issues. Here, you’ll find advice from both Cloudflare experts and experienced users, covering everything from basic SSL configurations to advanced performance settings.

Educational Resources

Learning platforms offer structured courses and hands-on labs to build foundational skills in Linux, networking, and web development. Consider these resources for guided learning:

  • Udemy & Coursera: Both Udemy and Coursera feature a variety of courses tailored to different skill levels. Topics range from Linux administration and server management to full-stack web development and networking essentials. Look for courses with high ratings and hands-on labs for practical experience.
  • YouTube Channels:
    • Binary Tech {LABS}: A source for straightforward tutorials on DIY tech projects, home automation, and Raspberry Pi setups. Binary Tech {LABS} breaks down complex topics into easy-to-follow steps, making tech accessible for everyone from hobbyists to experienced users.
    • NetworkChuck: Known for his engaging, step-by-step tutorials on networking, server setup, and cyber security. NetworkChuck’s videos simplify complex topics like DNS configuration, server administration, and Docker, making them accessible for beginners and advanced users alike.
    • Traversy Media: A popular channel covering web development and backend technologies. From HTML basics to setting up Nginx and Apache, Traversy Media provides clear, practical guidance on various web technologies.

Documentation

Official documentation is a key resource for understanding the inner workings of each platform and ensuring your setup aligns with best practices. Bookmark these resources for in-depth information, configuration options, and troubleshooting steps:

By leveraging these community forums, educational platforms, and official documentation resources, you can deepen your understanding, solve technical challenges more effectively, and keep improving your self-hosted website setup.


Thanks for Your Support!
I truly appreciate you taking the time to read my article. If you found it helpful, please consider sharing it with your friends or fellow makers. Your support helps me continue creating content like this.

  • Leave a Comment: Got questions or project ideas? Drop them below—I'd love to hear from you!
  • Subscribe: For more tutorials, guides, and tips, subscribe to my YouTube channel and stay updated on all things tech!
  • Shop & Support: If you're ready to get started, check out the recommended products in my articles using my affiliate links. It helps keep the lights on without costing you anything extra!

Thanks again for being part of this community, and happy building!