How to Self-Host Plausible on a VPS (Complete Guide)
Plausible is a lightweight and open-source web analytics tool that respects user privacy. Self-hosting Plausible on a Virtual Private Server (VPS) allows you to maintain full control over your data while benefiting from powerful analytics. In this guide, weโll walk through the steps to set up Plausible using Docker on your chosen VPS provider.
Prerequisites
Before you begin, ensure you have:
-
A VPS: Choose a provider from the options below which are affordable and developer-friendly:
Provider Price Features Contabo VPS 5.99 EUR/mo High storage options Hetzner Cloud 4.15 EUR/mo Flexible and fast performance DigitalOcean 6 USD/mo Easy to scale services Vultr 6 USD/mo Global availability Linode (Akamai Cloud) 5 USD/mo Great community support -
A domain name: Ensure you have registered a domain name that you own.
-
Basic knowledge of terminal commands and Docker.
-
An appropriate Docker environment installed on your VPS.
Step 1: Setting Up Your VPS
-
Access Your VPS: Use SSH to connect to your VPS.
ssh root@your-vps-ip -
Update Your System: Always make sure your server is updated.
apt update && apt upgrade -y -
Install Docker: If Docker is not installed, run the following commands:
apt install apt-transport-https ca-certificates curl software-properties-common -y curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" apt update apt install docker-ce -y -
Install Docker Compose: You will also need Docker Compose to manage the Docker containers.
curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose
Step 2: Configure Plausible Analytics
-
Create a Directory for Plausible: Organize your files with a dedicated directory.
mkdir ~/plausible cd ~/plausible -
Create a Docker Compose File: Use your favorite text editor to create
docker-compose.yml.version: '3' services: plausible: image: plausible/analytics:latest environment: - DATABASE_URL=postgres://plausible:plausible@db/plausible - SECRET_KEY=your-secret-key - PLAUSIBLE_PUBLIC_HOST=your-domain.com ports: - "8000:8000" depends_on: - db db: image: postgres:13 environment: - POSTGRES_USER=plausible - POSTGRES_PASSWORD=plausible - POSTGRES_DB=plausible volumes: - db_data:/var/lib/postgresql/data volumes: db_data: -
Modify the Environment Variables: Ensure you replace
your-secret-keywith a secure random string andyour-domain.comwith your actual domain.
Step 3: Running Plausible
-
Start the Services: Run the following command to launch Plausible.
docker-compose up -d -
Access Plausible: Open your web browser and navigate to
http://your-domain.com:8000. If everything is configured correctly, you should see the Plausible login page. -
Frontend Configuration: Follow the Plausible documentation to add your domain and start tracking analytics.
Step 4: Securing Your Installation
-
Set Up HTTPS: Itโs advisable to run your analytics over HTTPS. You can obtain a free SSL certificate using Letโs Encrypt. Hereโs a quick guide:
apt install certbot certbot certonly --standalone -d your-domain.com -
Configure Nginx as a Reverse Proxy: If you want to serve Plausible on standard ports and add SSL.
server { listen 80; server_name your-domain.com; return 301 https://$host$request_uri; } server { listen 443 ssl; server_name your-domain.com; ssl_certificate /etc/letsencrypt/live/your-domain.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/your-domain.com/privkey.pem; location / { proxy_pass http://localhost:8000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } }
FAQs
1. What is Plausible and why should I self-host it?
Plausible is an open-source web analytics tool designed to provide a simple and privacy-focused alternative to Google Analytics. By self-hosting, you control your data and ensure that usersโ privacy is respected, adhering to GDPR and other privacy regulations. Additionally, you avoid vendor lock-in and can tailor the service to meet your specific needs.
2. Which VPS provider is best for self-hosting Plausible?
Choosing the best VPS provider depends on your budget, location, and performance needs. For example, Hetzner Cloud offers competitive pricing at 4.15 EUR/mo, while DigitalOcean and Vultr are popular for their easy scalability and user-friendliness at 6 USD/mo. For a full VPS comparison, check out this link. Always analyze specific features and support that align with your technical requirements before making a decision.
3. How do I monitor the health of my self-hosted Plausible service?
To monitor your self-hosted Plausible instance, you can use Dockerโs built-in management commands like docker logs plausible to check for any errors or issues. Additionally, integrating monitoring solutions such as Grafana or Prometheus can provide insights into the performance and resource usage of your Docker containers. Itโs essential to regularly check the operational logs to preemptively catch any potential downtime or errors.
By following these steps, you can efficiently self-host Plausible on a VPS, maintaining both performance and data privacy. Enjoy your journey in self-hosting with open-source tools!