Do you know that you can host multiple apps on your Raspberry Pi and access them from outside your network? I understand that the Raspberry Pi may not be powerful enough for database-related transactions, but you can still host simple and lightweight apps on it to enhance your productivity. In this article, I will show you how to host multiple web apps on your Raspberry Pi machine using Apache as a web server.
If you wish to install Nextcloud on your Raspberry Pi, you can follow this article.
Install web server
To install the LAMP (Apache, MariaDB, and PHP) stack, follow this article from step 2 to step 4. The rest of the steps are dependent on your requirements.
However, we can just install Apache for static sites.
apt install apache2 zip unzip
a2enmod ssl rewrite headers proxy proxy_http deflate cache proxy_wstunnel http2 proxy_fcgi env expires
Enable Apache at boot time and restart it.
systemctl enable apache2
systemctl restart apache2
Before we proceed
If you want to access your sites over a dynamic IP, follow this guide to set it up with Cloudflare. Skip this step if you already have a static IP.
To run these sites exclusively on your network, add them to the
/etc/hosts file and skip the SSL setup below. In this case, the DOMAIN.COM (Apache virtual hosts) corresponds to portfolio.local and startup.local.
Create multiple hosts
If you want to install any database-related web app, such as WordPress, Moodle, or Nextcloud, follow its respective guide. You don’t need to follow the entire guide; read through and follow the parts that are required, such as the database, download section etc.
For the sake of this guide, we will keep things simple and create two static sites with only one page. Let’s call them portfolio (site 1) and startup (site 2).
We will create an index.html file in it and start with the basics. You can push your own files to it or enhance it accordingly.
Paste the following in it:
<p>Hi, my name is Admin.</p>
Save this and change the ownership of this directory.
chown -R www-data:www-data /var/www/html/portfolio
Now, we will create a virtual host file. Switch to sites-available directory and create a portfolio.conf file.
Paste the following into it while changing the domain name.
Options -Indexes +FollowSymLinks
Enable this configuration:
systemctl reload apache2
Now, if we browse the domain in a browser, we will see a basic page like the one below.
The process is almost the same as the portfolio website. Simply create an index.html file or push your own files to the
/var/www/html/startup directory. Additionally, create a virtual host configuration file named startup.conf in the
Once you are done, you can enable this site and restart Apache.
systemctl reload apache2
You will now be able to see the site in the browser using the domain you selected.
This is optional, but if you have a static IP or are using DDNS to access your sites outside your network, it is good to have SSL in front of them.
Please note that the IP should be pointed to the domains for this to work.
Follow the section from ‘How to install Nextcloud on Raspberry Pi‘ to obtain free certificates from Let’s Encrypt.
Once you have successfully retrieved the certificates, you can update the virtual host files with them. Follow this section to learn how to update them. Make changes where necessary, such as the path to the document root, path to certificates, etc.