This article is written for those who were searching for a detailed and simple for the understanding guide on how to install Bitbucket on Ubuntu Server.

Bitbucket is a web-based version control repository hosting service owned by Atlassian, for source code and development projects that use either Mercurial or Git revision control systems.

In this guide, we will consider the case when you already have a server with the Ubuntu Server 18.04 LTS operating system installed on it.

You can read more about how to install Ubuntu Server 18.04 LTS in my guide «Installing Ubuntu Server 18.04 LTS».

In addition, OpenSSH must be installed on the server, and port 22 must be open in order to be able to connect to the server using the SSH protocol.

To install OpenSSH on the server, you can use the command:

sudo apt-get install openssh-server

If you plan to connect to the server using the Windows operating system, you can use PuTTY, a freeware client for various remote access protocols, including SSH, Telnet, rlogin.

This guide covers connecting to a server using the iTerm2 terminal emulator installed on the macOS operating system.

Please note that you will need to open the following TCP ports to access your server:

  • 80 – to receive a free cryptographic certificate through the Let’s Encrypt certificate authority.
  • 443 – to access the Bitbucket web interface.
  • 7990 – to access the Bitbucket web interface.

Connect to the server on which it is planned to install Bitbucket.

This guide discusses how to obtain a free cryptographic certificate through the Let’s Encrypt Certificate Authority. To receive and further update the free SSL certificate, we will use the Certbot software client, which is designed to simplify the receipt and renewal of the certificate through the Let’s Encrypt certificate authority.

Add the Certbot repository using the command:

sudo add-apt-repository ppa:certbot/certbot

Press the “Enter” button to confirm the addition of a new repository.

Now install the packages necessary for Bitbucket to work using the command:

sudo apt-get install -y postgresql apache2 git perl fontconfig certbot python-certbot-apache

Please note that in this guide, PostgreSQL will be used as the database management system, and Apache will be used as the webserver.

Configure Apache for further work with the Bitbucket.

Enable the Apache webserver module called “proxy_http” with the command:

sudo a2enmod proxy_http

Please note that the “proxy_http” module acts like a proxy server for the HTTP and HTTPS protocols.

Enable the Apache webserver module called “rewrite” with the command:

sudo a2enmod rewrite

Please note that the “rewrite” module is one of the most commonly used Apache webserver modules and provides a flexible and powerful way to manipulate URLs.

Now you need to create two virtual host files (called block in Nginx), with which Bitbucket will continue to work.

Two virtual host files will be required to provide access to Bitbucket via HTTPS, as well as to realize the possibility of using Bitbucket at https://bitbucket.heyvaldemar.net, without specifying port 7990 in the address bar of the browser.

In this manual, the bitbucket.heyvaldemar.net subdomain will be used to access the Bitbucket control panel from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be accessible from the Internet.

Create the first virtual host file using a text editor using the command:

sudo vim /etc/apache2/sites-available/bitbucket.heyvaldemar.net.conf

Press the “i” button to enter the editing mode, then insert the following configuration for the webserver to work:

In this manual, the bitbucket.heyvaldemar.net subdomain will be used to access the Bitbucket control panel from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be accessible from the Internet.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Create a second virtual host file using a text editor using the command:

sudo vim /etc/apache2/sites-available/bitbucket.heyvaldemar.net-ssl.conf

Press the “i” button to enter the editing mode, then insert the following configuration for the webserver to work:

In this manual, the bitbucket.heyvaldemar.net subdomain will be used to access the Bitbucket control panel from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be accessible from the Internet.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Activate the first virtual host using the command:

sudo a2ensite bitbucket.heyvaldemar.net.conf

Activate the second virtual host using the command:

sudo a2ensite bitbucket.heyvaldemar.net-ssl.conf

Deactivate the default virtual host using the command:

sudo a2dissite 000-default.conf

Make sure that there are no errors in the syntax of the new Apache configuration file using the command:

sudo apache2ctl configtest

Restart Apache to apply the changes using the command:

sudo systemctl restart apache2

Verify that Apache started successfully using the command:

sudo systemctl status apache2

Now, to increase the security level of the webserver, it is necessary to obtain a cryptographic certificate for the domain or subdomain, through which the Bitbucket will be accessible from the Internet.

To obtain and subsequently renew a free SSL certificate, we will use the Let’s Encrypt Certificate Authority, as well as the Certbot software client, which is designed to simplify the receipt and renewal of the certificate through the Let’s Encrypt Certificate Authority.

In this manual, the bitbucket.heyvaldemar.net subdomain will be used to access the Bitbucket control panel from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be accessible from the Internet.

Request a cryptographic certificate using the command:

sudo certbot --apache -d bitbucket.heyvaldemar.net

Next, indicate the email address to which Let’s Encrypt will send notifications about the expiration of the cryptographic certificate and press the “Enter” button.

The next step is to read and accept the terms of use of the services provided.

Press the “a” button, then “Enter” if you agree to the terms of use of the services provided.

At the next stage, you need to choose: do you want to share the email address indicated above with the Electronic Frontier Foundation to receive newsletters.

Press the “n” button, then “Enter”.

The next step is to choose: do you want the parameters to automatically redirect HTTP traffic to HTTPS be automatically added to the Apache configuration file.

Press the button “2”, then “Enter”.

Please note that the cryptographic certificates received through the Let’s Encrypt Certificate Authority are valid for ninety days. Certbot automatically adds a script to renew the certificate in the task scheduler, and the script runs twice a day, automatically updating any cryptographic certificate that expires within thirty days.

You can check the operability of the cryptographic certificate renewal process using the command:

sudo certbot renew --dry-run

Now you need to create a database that Bitbucket will use in the future, as well as a user with the necessary rights to this database.

Switch to the “postgres” user, who has administrator rights in PostgreSQL using the command:

sudo su - postgres

Next, switch to the PostgreSQL command line using the command:

psql

Create a new user using the command:

CREATE USER bitbucketdbuser WITH PASSWORD 'mU%g673b=6])?8E6R9M3T';

The user name will be “bitbucketdbuser” with the password “mU%g673b=6])?8E6R9M3T”.

Create a new database and give it rights to the previously created user using the command:

CREATE DATABASE bitbucketdb WITH OWNER "bitbucketdbuser" ENCODING='UTF8' CONNECTION LIMIT=-1;

In this manual, “bitbucketdb” will be used as the name for the database.

Exit the PostgreSQL command line using the command:

\q

Exit the user “postgres” using the command:

exit

Now you need to download the Bitbucket installer using the command:

wget https://www.atlassian.com/software/stash/downloads/binary/atlassian-bitbucket-7.1.1-x64.bin

Please note that the latest version of Bitbucket can be found on the official Atlassian website https://www.atlassian.com/software/bitbucket/download

This guide covers the installation of Bitbucket 7.7.1.

Let’s enable the execution of the file “atlassian-bitbucket-7.1.1-x64.bin” with the command:

sudo chmod +x atlassian-bitbucket-7.1.1-x64.bin

Run the Bitbucket installation using the command:

sudo ./atlassian-bitbucket-7.1.1-x64.bin

Please note that your team will differ from the one specified in this article since you will install the current version of Bitbucket at the time of reading.

At the first stage, you can choose whether to install a new Bitbucket server or upgrade an existing one.

This guide describes how to install a new Bitbucket server.

Press on the “Enter” button.

The next step is to select the Bitbucket edition.

Specify the desired edition of Bitbucket for installation and press on the “Enter” button.

Press on the “Enter” button.

In the next step, you can choose where to install Bitbucket.

This guide covers installing Bitbucket in “/opt/atlassian/bitbucket/7.1.1”

Press on the “Enter” button.

Next, you can choose where to store Bitbucket data.

This guide covers installing Bitbucket in “/var/atlassian/application-data/bitbucket”.

Press on the “Enter” button.

Now you can select the port that Bitbucket will use.

This guide covers installing Bitbucket using port 7990 for HTTP.

Press on the “Enter” button.

Next, you will be offered the opportunity to install Bitbucket as a service.

Press on the “Enter” button.

Press on the “Enter” button to start installing Bitbucket.

Bitbucket installation completed successfully.

Please note that you do not need to run Bitbucket.

Specify “n” and press the “Enter” button.

Now you need to create the Bitbucket configuration file using the command:

sudo vim /var/atlassian/application-data/bitbucket/shared/bitbucket.properties

Press on the “i” button to enter the editing mode, then insert the following configuration for Bitbucket to work:

This guide will use the bitbucket.heyvaldemar.net subdomain to access Bitbucket from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be available from the Internet.

Now press the “Esc” button to exit the editing mode, and then enter “:x” and press the “Enter” button to save the changes and exit the editor.

Run Bitbucket with the command:

sudo service atlbitbucket start

Open the Bitbucket log to check if Bitbucket started correctly using the command:

sudo less /var/atlassian/application-data/bitbucket/log/atlassian-bitbucket.log

On the keyboard, press the “Shift” and “f” keys to begin to monitor changes in the Bitbucket log in real-time.

On the keyboard, press the key combination “Ctrl” and “c”, then “q” to close the Bitbucket log.

To continue the process of installing the Bitbucket, you must go from workstation to the link https://bitbucket.heyvaldemar.net, where bitbucket.heyvaldemar.net is the name of my server. Accordingly, you need to specify the name or IP address of your server with the Bitbucket installed.

This guide covers installing Bitbucket for a productive environment.

In the “Language” field, select the language in which you plan to use Bitbucket.

In the “Database” field select “External”.

Now you need to specify the database management system and the previously created database that will be used for Bitbucket.

In the “Database Type” field select “PostgreSQL”.

In this guide, the database for running Bitbucket is on the same server as Bitbucket.

In the “Hostname” field specify “localhost”.

In the “Port” field indicate the value “5432”.

In this guide, “bitbucketdb” is used as the database name for Bitbucket to work.

In the “Database name” field indicate “bitbucketdb”.

In this manual, “bitbucketdbuser” is used as the user name that has the rights to the database for Bitbucket to operate.

In the “Database username” field specify “bitbucketdbuser”.

In the “Database password” field specify the password assigned to the user “bitbucketdbuser”.

Click on the “Test” button.

The message “Successfully established database connection.” means that all data was specified correctly.

Click on the “Next” button.

Now you need to specify the base URL and license key for Bitbucket.

The “Base URL” field should contain the domain or subdomain by which your Bitbucket is accessible from the Internet.

This guide will use the bitbucket.heyvaldemar.net subdomain to access Bitbucket from the Internet. You will need to specify your domain or subdomain by which your Bitbucket will be available from the Internet.

If you do not already have a license key, you can request a temporary key to familiarize yourself with Bitbucket.

This guide covers installing Bitbucket with a temporary license key.

In the “License key” section, select “I need an evaluation key” and click on the “Create an account” button.

The next step is to specify: email address, first name, last name and password to create an Atlassian account.

Click on the “Sign up” button.

Please note that you will receive an email to the email address provided during registration. In the letter, you will find a link to complete the registration.

If you already have an Atlassian account, then enter the email address associated with the Atlassian account in the “Enter email” field and click on the “Continue” button.

Specify the password for the Atlassian account and click on the “Log in” button.

The next step is to indicate which product you need a temporary license key, as well as the name of your organization.

Click on the “Generate License” button to generate a temporary license key for Bitbucket.

Next, you need to confirm that the temporary license key for Bitbucket will be installed on your server.

Click on the “Yes” button.

In the “Your License Key” field, insert the previously received temporary license key and click on the “Next” button.

The next step is to specify: username, name, email address and password to create a Bitbucket admin account.

Click on the “Go to Bitbucket” button.

You can now log into the Bitbucket control panel under the previously created Bitbucket admin account.

Specify the username and password of an account that has Bitbucket administrator rights, and click on the “Log in” button.

Welcome to the Bitbucket dashboard.

Now you can create a new project and repository.

Click on the “Git on with it” button.

Click on “Create project” to start creating a new project.

In the “Project name” field, specify the name for the project and click on the “Create project” button.

Click on “Create repository” to start creating a new repository.

In the “Name” field, specify the name for the repository and click on the “Create repository” button.

Everything is ready to use Bitbucket.

Author

Hi, I’m Vladimir Mikhalev, but my friends call me Valdemar. I have a lot of experience in the design and maintenance of various information systems. On my website, you will find detailed and clear guides for setting up IT solutions. Dive into the ocean, full of positive and technology! For cooperation: callvaldemar@gmail.com

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.