How to Install YOURLS on OpenBSD

YOURLS stands for Your Own URL Shortener. YOURLS is a set of PHP scripts that allow you to run your URL shortening service (a la TinyURL or bitly).

This tutorial will explain how to install YOURLS on OpenBSD.

Prerequisites

Before installing YOURLS on OpenBSD, ensure the following:

Step 1: Download and Extract YOURLS

  1. Download the latest version of YOURLS from the official website by running the following command in your OpenBSD terminal:

    $ ftp https://github.com/YOURLS/YOURLS/archive/master.zip
    

    Alternatively, you can download the latest stable release by visiting the YOURLS release page and downloading the .zip file directly.

  2. Extract the downloaded file by running the following command:

    $ unzip master.zip
    

    This will create a new directory called YOURLS-master in your current directory.

Step 2: Configure Apache

  1. Open the Apache configuration file /etc/apache2/httpd.conf with your preferred text editor:

    $ sudo vi /etc/apache2/httpd.conf
    
  2. Add the following lines at the end of the <VirtualHost *:80> block:

    DocumentRoot "/var/www/YOURLS-master"
    ServerName yourls.example.com
    <Directory "/var/www/YOURLS-master">
          Options Indexes FollowSymLinks
          AllowOverride All
          Require all granted
    </Directory>
    

    This will configure Apache to serve YOURLS from the YOURLS-master directory and allow YOURLS to use .htaccess files.

  3. Save the changes and exit the text editor.

  4. Restart Apache to apply the changes:

    $ sudo apachectl restart
    

Step 3: Configure MySQL/MariaDB

  1. Log in to the MySQL shell as the root user:

    $ mysql -u root -p
    
  2. Create a new database for YOURLS:

    mysql> CREATE DATABASE yourlsdb;
    
  3. Create a new MySQL user for YOURLS and grant it full privileges on the database:

    mysql> CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'yourlspassword';
    mysql> GRANT ALL PRIVILEGES ON yourlsdb.* TO 'yourlsuser'@'localhost';
    mysql> FLUSH PRIVILEGES;
    
  4. Exit the MySQL shell:

    mysql> quit
    

Step 4: Configure YOURLS

  1. Rename the sample configuration file user/config-sample.php to config.php:

    $ cd YOURLS-master/user
    $ mv config-sample.php config.php
    
  2. Open the config.php file with your preferred text editor and modify the following lines:

    /** Database connection settings */
    define( 'YOURLS_DB_USER', 'yourlsuser' );
    define( 'YOURLS_DB_PASS', 'yourlspassword' );
    define( 'YOURLS_DB_NAME', 'yourlsdb' );
    define( 'YOURLS_DB_HOST', 'localhost' );
    
    /** Site URL */
    define( 'YOURLS_SITE', 'http://yourls.example.com' );
    
    /** Signature salt */
    define( 'YOURLS_SECRET', 'yourlssecret' );
    

    Replace yourlsuser and yourlspassword with the MySQL/MariaDB user and password you created earlier, replace yourlsdb with the name of the MySQL/MariaDB database you created earlier, and replace yourls.example.com with the domain name or IP address of your server.

    You can generate a unique secret for YOURLS using a tool like Random.org.

  3. Save the changes and exit the text editor.

Step 5: Test YOURLS

  1. Open your web browser and navigate to http://yourls.example.com/admin/.

  2. You should see the YOURLS login screen. Enter the default username admin and the default password admin, then click the Login button.

  3. You should now see the YOURLS administration interface. You can begin generating short URLs by entering a long URL in the Enter a new URL to shorten field and clicking the Shorten button.

Congratulations, you have successfully installed YOURLS on OpenBSD!

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!

Alternatively, for the best virtual desktop, try Shells!