YOURLS is a small PHP application used for creating personal URL shortening service. This tutorial will guide you on how to install YOURLS on the latest version of FreeBSD.
Before proceeding, ensure that your FreeBSD machine has the following requirements:
The first step is to install the necessary packages for running the YOURLS application. Open the terminal and type the following command to update the package repository:
sudo pkg update
Next, install the required packages for PHP, MySQL, and Apache/Nginx using the following command:
sudo pkg install php74 php74-mysqli php74-session php74-curl php74-zip sudo mysql57-server apache24
After installing the necessary packages, you need to configure the MySQL database. Enter the following command to start the MySQL service:
sudo service mysql-server start
Then, set up a new MySQL user and a database for YOURLS using the following SQL commands:
mysql -u root -p
CREATE USER 'yourls_user'@'localhost' IDENTIFIED BY 'password';
CREATE DATABASE `yourls`;
GRANT ALL PRIVILEGES ON `yourls`.* TO 'yourls_user'@'localhost';
FLUSH PRIVILEGES;
exit;
Now download YOURLS by entering the following command:
sudo wget https://github.com/YOURLS/YOURLS/archive/refs/tags/1.7.11.tar.gz -O yourls.tar.gz
Extract the downloaded file using the following command:
sudo tar -xvzf yourls.tar.gz -C /usr/local/www/apache24/data/
And rename the extracted directory to yourls:
sudo mv /usr/local/www/apache24/data/YOURLS-1.7.11 /usr/local/www/apache24/data/yourls
Then navigate to the root directory of the YOURLS application and rename the user/config-sample.php
file to user/config.php
:
cd /usr/local/www/apache24/data/yourls
sudo mv user/config-sample.php user/config.php
In the configuration file user/config.php
, find the following settings and replace their values with your database details:
/** MySQL database username */
define( 'YOURLS_DB_USER', 'yourls_user' );
/** MySQL database password */
define( 'YOURLS_DB_PASS', 'password' );
/** The name of the database for YOURLS */
define( 'YOURLS_DB_NAME', 'yourls' );
/** MySQL hostname.
** If using a non standard port, specify it like 'hostname:port', e.g. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );
Now you need to configure the web server to run YOURLS. Follow the instructions below for your web server:
Open the Apache configuration file by running:
sudo nano /usr/local/etc/apache24/httpd.conf
Add the following lines to the file:
<Directory "/usr/local/www/apache24/data/yourls">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Save and close the file, and then restart the Apache service:
sudo service apache24 restart
Open the Nginx configuration file by running:
sudo nano /usr/local/etc/nginx/nginx.conf
Add the following lines to the file inside the server block:
location /yourls {
root /usr/local/www/nginx/data;
index index.php index.html index.htm;
try_files $uri $uri/ /yourls/index.php?$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Save and close the file, and then restart the Nginx service:
sudo service nginx restart
Now you can access the YOURLS application by navigating to http://your-ip-address/yourls
from a web browser. You will see a message asking you to install YOURLS. Follow the on-screen instructions to complete the installation.
Congratulations! You have successfully installed YOURLS on FreeBSD Latest. You can now start using it to create your URL shortening service.
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!