How to Install YOURLS on Elementary OS
In this tutorial, we will be installing YOURLS, an open-source, self-hosted URL shortener, on the latest version of Elementary OS. Follow the steps below to complete the installation.
Prerequisites
Before we begin, ensure that your Elementary OS system is up to date and has the following packages installed:
- Apache web server
- PHP
- MySQL
You can install these packages by running the following command in your terminal:
sudo apt-get update
sudo apt-get install apache2 php mysql-server php-mysql
Step 1: Download and Configure YOURLS
Download the latest version of YOURLS from the official website by running the following command in your terminal:
wget https://yourls.org/latest.zipExtract the downloaded zip file using the following command:
unzip latest.zip -d /var/www/html/Change the ownership of the extracted YOURLS directory using the following command:
sudo chown -R www-data:www-data /var/www/html/yourls/Rename the
user/config-sample.phpfile touser/config.phpusing the following command:mv /var/www/html/yourls/user/config-sample.php /var/www/html/yourls/user/config.phpOpen the
config.phpfile using a text editor and add the following configuration settings:/** MySQL database username */ define( 'YOURLS_DB_USER', 'your_mysql_username' ); /** MySQL database password */ define( 'YOURLS_DB_PASS', 'your_mysql_password' ); /** The name of the database for YOURLS */ define( 'YOURLS_DB_NAME', 'your_database_name' ); /** MySQL hostname */ define( 'YOURLS_DB_HOST', 'localhost' );Save and close the
config.phpfile.
Step 2: Create a MySQL Database for YOURLS
Log in to the MySQL command-line interface using the following command:
mysql -u root -pEnter your MySQL root password when prompted.
Create a new database for YOURLS using the following command:
create database your_database_name;Create a new MySQL user for YOURLS using the following command:
create user 'your_mysql_username'@'localhost' identified by 'your_mysql_password';Grant all privileges to the new MySQL user for the newly created database using the following command:
grant all privileges on your_database_name.* to 'your_mysql_username'@'localhost';Flush the privileges using the following command:
flush privileges;Exit the MySQL command-line interface by typing
exit;and pressing Enter.
Step 3: Configure Apache
Create a new virtual host configuration file for YOURLS using the following command:
sudo nano /etc/apache2/sites-available/yourls.confPaste the following configuration code into the file:
<VirtualHost *:80> ServerAdmin [email protected] DocumentRoot /var/www/html/yourls <Directory /var/www/html/yourls> Options Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/yourls_error.log CustomLog ${APACHE_LOG_DIR}/yourls_access.log combined </VirtualHost>Save and close the file by pressing
Ctrl + X, thenY, and finallyEnter.Enable the YOURLS virtual host configuration by running the following command:
sudo a2ensite yourls.confReload the Apache web server using the following command:
sudo service apache2 reload
Step 4: Test YOURLS
Open your web browser and navigate to
http://localhost/admin/.Follow the on-screen instructions to configure and use YOURLS to create short URLs.
Congratulations! You have successfully installed and configured YOURLS on Elementary OS.