Hosting both Nextcloud and Forgejo on a single Raspberry Pi is entirely feasible, but it requires careful planning to avoid conflicts and ensure optimal performance. Below, I outline the key considerations and steps to take for a successful setup:
1. Understand the Potential Conflicts
Both Nextcloud and Forgejo are web-based applications that rely on a web server (e.g., Apache or Nginx) and may use similar resources such as:
- Ports: By default, web servers listen on port 80 (HTTP) and 443 (HTTPS). Hosting two applications on the same ports without proper configuration will cause conflicts.
- Resources: A Raspberry Pi has limited CPU, memory, and storage. Running both applications simultaneously may strain these resources, especially under heavy usage.
- Database: Both applications typically use databases (e.g., MySQL/MariaDB or PostgreSQL). While they can share the same database server, they must use separate databases to avoid interference.
2. Proposed Approach
a. Use Subdomains or Subdirectories
To avoid port conflicts, you can configure your web server to serve each application under a unique subdomain or subdirectory:
- Subdomains:
nextcloud.example.com → Nextcloud
forgejo.example.com → Forgejo
- Subdirectories:
example.com/nextcloud → Nextcloud
example.com/forgejo → Forgejo
This approach requires configuring your web server (e.g., Nginx or Apache) to route requests appropriately.
b. Configure the Web Server
Here’s how you can set up Nginx to handle both applications:
-
Install Nginx:
sudo apt update
sudo apt install nginx
-
Create Separate Configuration Files:
- For Nextcloud (
/etc/nginx/sites-available/nextcloud):
server {
listen 80;
server_name nextcloud.example.com;
root /var/www/nextcloud;
index index.php;
location / {
try_files $uri $uri/ =404;
}
# PHP handling (adjust PHP version if needed)
location ~ \.php$ {
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
- For Forgejo (
/etc/nginx/sites-available/forgejo):
server {
listen 80;
server_name forgejo.example.com;
root /var/www/forgejo;
index index.html;
location / {
proxy_pass http://localhost:3000; # Adjust port if Forgejo uses a different one
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
-
Enable the Configurations:
sudo ln -s /etc/nginx/sites-available/nextcloud /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/forgejo /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
-
Set Up SSL with Certbot:
Install Certbot to secure both applications with HTTPS:
sudo apt install certbot python3-certbot-nginx
sudo certbot --nginx -d nextcloud.example.com -d forgejo.example.com
c. Use Separate Databases
Ensure that each application uses its own database:
- For Nextcloud:
CREATE DATABASE nextcloud;
GRANT ALL PRIVILEGES ON nextcloud.* TO 'nextclouduser'@'localhost' IDENTIFIED BY 'password';
- For Forgejo:
CREATE DATABASE forgejo;
GRANT ALL PRIVILEGES ON forgejo.* TO 'forgejouser'@'localhost' IDENTIFIED BY 'password';
d. Optimize Resource Usage
3. Additional Recommendations
- Use Docker (Optional): If you’re comfortable with containerization, Docker can simplify the setup by isolating each application in its own container. This avoids potential conflicts between dependencies.
- Backup Regularly: Use tools like
rsync or borgbackup to back up both applications and their data regularly.
4. Conclusion
By using subdomains or subdirectories, properly configuring your web server, and ensuring resource optimization, you can successfully host both Nextcloud and Forgejo on a single Raspberry Pi. If you encounter specific issues during setup, feel free to provide details, and I’ll assist further.