Install Phabricator on Ubuntu

Phabricator is a free set of web tools for joint development of various software products, it has built-in chat, code verification, problem tracking, etc.

Once looking at the list of services for hosting Mercurial on the site
https://www.mercurial-scm.org/wiki/MercurialHosting
decided to use a phabricator
https://www.phacility.com/phabricator/

For example, I will install Phabricator on Ubuntu Server 18.04.

First, update the system and install the necessary components:

sudo apt update
sudo apt upgrade
sudo apt install git mercurial php php-mysql php-gd php-curl php-apcu php-cli php-zip php-json php-mbstring php libapache2-mod-php mysql-server apache2 zip
sudo a2enmod php7.2
sudo a2enmod rewrite

The following command will follow the MySQL security recommendations:

sudo mysql_secure_installation

Specify the root password for the user if it is not installed (where ixnfo is the password):

mysql -u root
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'ixnfo';
FLUSH PRIVILEGES;
exit;

Let’s create a user in the operating system under which Phabricator will work:

adduser phd --home /home/phd
adduser phd sudo
chown -R phd:phd /home/phd/

Create a directory for Phabricator, download it into it, and also download the dependencies:

cd /home/phd
sudo git clone https://github.com/phacility/libphutil.git
sudo git clone https://github.com/phacility/arcanist.git
sudo git clone https://github.com/phacility/phabricator.git

Open the new apache2 configuration file in a text editor:

sudo nano /etc/apache2/sites-available/git.ixnfo.com.conf

I will give an example configuration:

<VirtualHost *:80>
ServerName git.ixnfo.com
ServerAdmin test@ixnfo.com
Redirect permanent / https://git.ixnfo.com/
DocumentRoot /home/phd/phabricator/webroot/

ErrorLog ${APACHE_LOG_DIR}/phabricator-error.log
CustomLog ${APACHE_LOG_DIR}/phabricator-access.log combined

<Directory "/home/phd/phabricator/webroot/">
Require all granted
</Directory>
</VirtualHost>


<VirtualHost *:443>
ServerAdmin test@ixnfo.com
ServerName git.ixnfo.com
DocumentRoot /home/phd/phabricator/webroot/

RewriteEngine on
RewriteRule ^(.*)$ /index.php?__path__=$1 [B,L,QSA]
        <Directory "/home/phd/phabricator/webroot/">
#                Options -Indexes +FollowSymlinks
                Options FollowSymLinks
#                AllowOverride All
#                Order allow,deny
#                allow from all
                Require all granted
        </Directory>

SSLEngine on
SSLCertificateFile /etc/letsencrypt/live/git.ixnfo.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/git.ixnfo.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/git.ixnfo.com/chain.pem

ErrorLog /var/log/apache2/phabricator_error-ssl.log
LogLevel warn
CustomLog /var/log/apache2/phabricator_access-ssl.log combined
</VirtualHost>

You can install free SSL, for example, as I described in the article:
Installing Certbot in Ubuntu

We activate the created configuration and check its correctness:

sudo a2ensite git.ixnfo.com
sudo apachectl -t

Let’s make apache2 start at system startup and reboot it to apply the changes made earlier:

sudo systemctl enable apache2
sudo systemctl restart apache2

The commands below indicate the parameters for connecting to the MySQL server (the connection must be made from the root user):

cd /var/www/phabricator/phabricator
./bin/config set mysql.host localhost
./bin/config set mysql.port 3306
./bin/config set mysql.user root
./bin/config set mysql.pass your_password

Or you can create a separate user with full rights (Phabricator will not connect to the database if the password contains characters):

mysql -u root
CREATE USER 'phd'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON * . * TO 'phd'@'localhost';
FLUSH PRIVILEGES;
quit

Run one of the commands below to create the necessary databases and tables:

./bin/storage upgrade
./bin/storage upgrade --force

Instead of apache2, you can install nginx:

sudo apt install nginx php-fpm
sudo service nginx status
sudo service php7.2-fpm status

Example configuration file:

server {
  server_name 192.168.2.2;
  root        /home/phd/phabricator/webroot;

  location / {
    index index.php;
    rewrite ^/(.*)$ /index.php?__path__=/$1 last;
  }

  location /index.php {
    fastcgi_pass   localhost:9000;
    fastcgi_index   index.php;

    #required if PHP was built with --enable-force-cgi-redirect
    fastcgi_param  REDIRECT_STATUS    200;

    #variables to make the $_SERVER populate in PHP
    fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
    fastcgi_param  QUERY_STRING       $query_string;
    fastcgi_param  REQUEST_METHOD     $request_method;
    fastcgi_param  CONTENT_TYPE       $content_type;
    fastcgi_param  CONTENT_LENGTH     $content_length;

    fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;

    fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
    fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

    fastcgi_param  REMOTE_ADDR        $remote_addr;
  }
}

Also, in the /etc/php/7.2/fpm/pool.d/www.conf file, change:

;listen = /run/php/php7.2-fpm.sock
listen = 9000

And restart php7.2-fpm to apply the changes:

sudo service php7.2-fpm restart

See also my articles:

Leave a comment

Leave a Reply