Hello, friends. In this post, you will learn how to install YOURLS on Ubuntu 20.04. Thanks to tool, tool, you will be able to have your URL shortener for your server.
Introduction to YOURL
According to the project website, we have the following definition:
YOURLS stands for Your Own URL Shortener. It is a small set of PHP scripts that will allow you to run your own URL shortening service (a la TinyURL or Bitly).
Running your URL shortener is fun, geeky, and useful: you own your data and don’t rely on third-party services. It’s also a good way to add branding to your short URLs, instead of using the same public URL shortener that everyone else uses.
So, having a tool like this is important for URL shortening that you can manage yourself.
Install LAMP on Ubuntu 20.04
First, we need to install a LAMP server so that the application can run smoothly. To achieve this, open a terminal and run the following command.
sudo apt install apache2 mariadb-server php7.4 libapache2-mod-php php7.4-mysql php7.4-curl php7.4-json php7.4-cgi php7.4-xsl php-sqlite3
Once the installation is finished, you can configure MariaDB to define a root key.
sudo mysql_secure_installation
Then, press ENTER to log in, and you will be able to set your root password. Thereafter, you will be asked a few configuration questions
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
Answer Y
to all of them, and you are done.
Next, create a new database and a dedicated user for YOURLS.
sudo mysql -u root -p
Next, create the database for YOURLS.
CREATE DATABASE yourls;
Now create the user and its permissions over the database
GRANT ALL PRIVILEGES ON yourls.* TO 'user'@'localhost' IDENTIFIED BY 'pss';
Now refresh the permissions:
FLUSH PRIVILEGES;
And exit the console.
exit;
Download YOURLS on Ubuntu 20.04
Now, thanks to GIT, download YOURLS to your computer.
git clone https://github.com/YOURLS/YOURLS.git
Now move the generated folder to the Apache root.
sudo mv YOURLS /var/www/html/
Then make Apache the owner of the folder.
sudo chown -R www-data:www-data /var/www/html/YOURLS
Next, set the appropriate permissions on the folder.
sudo chmod -R 775 /var/www/html/YOURLS
Configuring YOURLS in Ubuntu 20.04
The next step is to configure YOURLS. To achieve this, copy the sample configuration file.
cd /var/www/html/YOURLS/user
sudo cp config-sample.php config.php
And then edit it
sudo vi config.php
Inside the file define the database credentials and the URL where the server will run.
define( 'YOURLS_DB_USER', 'user' );
define( 'YOURLS_DB_PASS', 'pss' );
define( 'YOURLS_DB_NAME', 'yourls' );
define( 'YOURLS_DB_HOST', 'localhost' );
define( 'YOURLS_DB_PREFIX', 'yourls_' );
define( 'YOURLS_SITE', 'http://url.unixcop.com' );
Now create the new user by modifying the existing registered:
$yourls_user_passwords = [
'user' => 'password',
// 'username2' => 'password2',
// You can have one or more 'login'=>'password' lines
];
Save the changes and close the editor.
Now create a new VirtualHost for Apache that has the YOURLS configuration.
sudo vi /etc/apache2/sites-available/yourls.conf
And add the following:
<VirtualHost *:80>
ServerName url.unixcop.com
DocumentRoot /var/www/html/YOURLS
<Directory /var/www/html/YOURLS>
Options FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/yourdomain.com_error.log
CustomLog ${APACHE_LOG_DIR}/yourdomain.com_access.log combined
</VirtualHost>
Save the changes and close the editor.
Then, enable the new Virtual Host and the rewrite module. Finally, restart Apache2.
sudo a2ensite yourls.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
Now let’s install it.
Install YOURLS on Ubuntu 20.04
Now visit http://your-domain/admin
and you will see the following screen.
Then, continue with the steps until you see the Login screen. Once you have logged in with the credentials defined in the file, you will see the dashboard.
You are done.
Conclusion
YOURLS is an interesting application to shorten URLs and do it on our server with our conditions.