Jul 26, 2024 4 min read

Phabricator: Self-Hosting Made Simple

Phabricator: Self-Hosting Made Simple
Table of Contents

Phabricator is an open-source project management and collaboration tool designed for developers and teams. It provides robust features like code reviews, task tracking, and repositories, making it a powerful alternative to cloud-based solutions. Self-hosting Phabricator ensures complete control over your data, significant customization, and seamless integration into your development workflow. This guide will cover everything from installation to advanced configurations, helping you deploy and manage Phabricator effectively.

Installing Phabricator

Phabricator can be installed using Docker for simplicity or manually for granular control. Below are actionable steps for both methods.

πŸ“¦ Docker/Docker Compose Setup

Using Docker allows you to quickly deploy Phabricator with minimal system dependencies.

  1. Create a docker-compose.yml file with the following content:

version: '3.8'

services:

phabricator:

image: bitnami/phabricator:latest

container_name: phabricator

ports:

- "8080:80"

volumes:

- phabricator_data:/bitnami

environment:

- PHABRICATOR_HOST=phabricator.local

- MARIADB_HOST=mariadb

- MARIADB_PORT_NUMBER=3306

- MARIADB_ROOT_PASSWORD=example_password

mariadb:

image: bitnami/mariadb:latest

container_name: mariadb

environment:

- ALLOW_EMPTY_PASSWORD=no

- MARIADB_ROOT_PASSWORD=example_password

volumes:

- mariadb_data:/bitnami

volumes:

phabricator_data:

mariadb_data:

  1. Deploy Phabricator by running:

docker-compose up -d

This command pulls the necessary images and starts Phabricator and MariaDB services.

  1. Verify the installation by visiting http://<server-ip>:8080.

πŸš€ Manual Installation

For greater control, install Phabricator manually on a Linux server.

  1. Install dependencies:

sudo apt update && sudo apt install -y git apache2 mysql-server php php-cli php-mysql php-curl php-json php-mbstring php-soap php-xml php-zip

  1. Clone the Phabricator repository:

cd /opt

sudo git clone https://github.com/phacility/phabricator.git

sudo git clone https://github.com/phacility/libphutil.git

sudo git clone https://github.com/phacility/arcanist.git

  1. Set up MySQL:

sudo mysql -e "CREATE DATABASE phabricator;"

sudo mysql -e "CREATE USER 'phabricator'@'localhost' IDENTIFIED BY 'secure_password';"

sudo mysql -e "GRANT ALL PRIVILEGES ON phabricator.* TO 'phabricator'@'localhost';"

sudo mysql -e "FLUSH PRIVILEGES;"

  1. Configure Phabricator:

cd /opt/phabricator

./bin/config set mysql.host localhost

./bin/config set mysql.user phabricator

./bin/config set mysql.pass secure_password

Configuring Nginx as a Reverse Proxy

After installation, configure Nginx to serve Phabricator for easier access and SSL security.

🌐 Nginx Configuration

  1. Create a new Nginx server block:

sudo nano /etc/nginx/sites-available/phabricator

  1. Add the following configuration:

server {

listen 80;

server_name phabricator.local;

location / {

proxy_pass http://127.0.0.1:8080;

proxy_set_header Host $host;

proxy_set_header X-Real-IP $remote_addr;

proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

}

client_max_body_size 32M;

}

  1. Enable the configuration:

sudo ln -s /etc/nginx/sites-available/phabricator /etc/nginx/sites-enabled/

sudo nginx -t

sudo systemctl reload nginx

πŸ”’ SSL/TLS Setup

  1. Install Certbot for Let’s Encrypt:

sudo apt install -y certbot python3-certbot-nginx

  1. Generate an SSL certificate:

sudo certbot --nginx -d phabricator.local

  1. Automate renewals:

sudo crontab -e

Add the following line to renew certificates automatically:


0 3 * * * /usr/bin/certbot renew --quiet

πŸ› οΈ Testing and Reloading Nginx

  1. Test your Nginx configuration:

sudo nginx -t

  1. Reload Nginx to apply changes:

sudo systemctl reload nginx

Logging and Debugging Phabricator

Monitoring logs is crucial for maintaining a healthy Phabricator installation.

πŸ—ƒοΈ Enabling Debug Logs

  1. Enable debug logging via Phabricator’s CLI:

cd /opt/phabricator

./bin/config set debug.enabled true

  1. Restart the web server to apply changes:

sudo systemctl restart apache2

πŸ“„ Viewing Logs

  1. View application logs:

tail -f /var/log/phabricator/phabricator.log

  1. For Docker-based installations, use:

docker logs phabricator

πŸ› οΈ Troubleshooting Common Issues

  1. Check for missing dependencies:

./bin/storage upgrade

  1. Resolve permission issues:

sudo chown -R www-data:www-data /opt/phabricator/

πŸ“€ Exporting Logs

For advanced analysis, export logs to ELK:


cat /var/log/phabricator/phabricator.log | curl -X POST "http://elk-server:9200/_bulk" -H "Content-Type: application/json" -d @-

Backup and Restore

Regularly backing up Phabricator ensures data reliability.

πŸ—‚οΈ File-Based Backups

  1. Archive key directories:

tar -czvf phabricator-backup.tar.gz /opt/phabricator /etc/nginx/sites-available/phabricator

πŸ”„ Database Backups

  1. Export the database:

mysqldump -u phabricator -p phabricator > phabricator_db.sql

  1. Restore the database:

mysql -u phabricator -p phabricator < phabricator_db.sql

πŸ“… Automated Backup Scripts

  1. Create a backup script:

nano /usr/local/bin/phabricator_backup.sh

Add the following:


#!/bin/bash

tar -czvf /backup/phabricator-$(date +%F).tar.gz /opt/phabricator

mysqldump -u phabricator -p'password' phabricator > /backup/phabricator_db-$(date +%F).sql

  1. Schedule it via cron:

crontab -e

Add:


0 2 * * * /usr/local/bin/phabricator_backup.sh

Updating and Upgrading Phabricator

Keep Phabricator up-to-date to ensure security and access to new features.

⬆️ Updating Docker Images

  1. Pull the latest image:

docker-compose pull

docker-compose up --force-recreate -d

πŸ› οΈ Manual Updates

  1. Pull updates from Git:

cd /opt/phabricator

sudo git pull origin stable

  1. Apply storage updates:

./bin/storage upgrade

πŸ” Checking for Updates

Verify the installed version:


./bin/version

Compare it with the latest version on the Phabricator GitHub page.

Leveraging Phabricator’s Unique Features

Phabricator offers extensive functionality for developers.

πŸ”§ Enabling APIs

  1. Enable the API:

./bin/config set phabricator.cluster.enabled true

  1. Test the API with curl:

curl -X POST -d '{"method":"user.whoami","api.token":"<your_api_token>"}' http://phabricator.local/api/

🌟 Advanced Configurations

  1. Customize workflows:

./bin/config set differential.show-host true

  1. Integrate Git repositories:

./bin/repository create git --name "MyRepo" --callsign "MR" --uri "/path/to/repo.git"

Wrapping Up

This guide covered the essential steps for deploying, configuring, and managing Phabricator. By following these instructions, you can harness the full potential of Phabricator’s customization and control. Whether you're managing tasks, conducting code reviews, or integrating repositories, Phabricator is a comprehensive tool that adapts to your workflows. Start implementing these steps today to elevate your team’s productivity and collaboration.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to Selfhosted Ninja.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.