How to build YOURLS - A URL Shortening Platform
Preview:
Disadvantages:
Suitable for personal use only, administrators must be manually added in the configuration file, and cannot be added directly from the frontend.
Deployment Method:
Step One: Update Sources and Install Dependencies
Ubuntu/Debian:
apt update -y && apt upgrade -y
sudo apt install unzip -y
sudo apt install git -y
Centos:
sudo yum update -y && sudo yum upgrade -y
sudo yum install unzip -y
sudo yum install git -y
Step Two: Install Apache Web
Ubuntu/Debian:
sudo apt-get install apache2
Centos:
sudo yum install httpd -y
Step Three: Install MySQL
Ubuntu/Debian:
sudo apt-get install mysql-server
Centos:
sudo yum install mysql-server -y
sudo systemctl start mysqld
Step Four: Install PHP and Required Extensions
Ubuntu/Debian:
sudo apt-get install php php-mysql libapache2-mod-php php-cli
Centos:
sudo yum install php php-mysql php-cli
sudo systemctl restart httpd
Step Five: Configure the Database
Enter MySQL
mysql -u root -p
Enter the root password
Create Database
CREATE DATABASE yourls;
Create User and Grant Permissions
CREATE USER 'yourls_user'@'localhost' IDENTIFIED BY 'password'; GRANT ALL PRIVILEGES ON yourls.* TO 'yourls_user'@'localhost';
Restart and Exit
FLUSH PRIVILEGES; EXIT;
Step Six: Download Source Code and Unzip
wget https://github.com/YOURLS/YOURLS/archive/refs/tags/1.9.2.zip unzip 1.9.2.zip
Step Seven: Configure YOURLS
Copy the Sample Configuration File:
cp YOURLS-1.9.2/user/config-sample.php YOURLS-1.9.2/user/config.php
Open the Configuration File and Make Modifications:
nano YOURLS-1.9.2/user/config.php
The following must be modified:
Database Username:
define( 'YOURLS_DB_USER', 'yourls_user' );
Database Password:
define( 'YOURLS_DB_PASS', 'password' );
Database Name:
define( 'YOURLS_DB_NAME', 'yourls' );
COOKIEKEY (Generate at http://yourls.org/cookie):
define( 'YOURLS_COOKIEKEY', 'modify this text with something random' );
Admin Username and Password (If unmodified, username will be "username" and password will be "password," multiple users can be added for management here):
$yourls_user_passwords = [ 'username' => 'password', // 'username2' => 'password2', // You can have one or more 'login'=>'password' lines ];
Access URL (Remember to resolve this URL to host IP):
define( 'YOURLS_SITE', 'http://example.com' );
The following can be modified optionally:
Allow Public Use (true for not allowed, false for allowed):
define( 'YOURLS_PRIVATE', true );
Allow Multiple Short Links to Point to the Same Long Link (For example, after enabling, both a.com/1 and a.com/2 will redirect to b.com, useful for analyzing data for each short link during multi-platform promotion):
define( 'YOURLS_UNIQUE_URLS', true );
Change Language (Default is English, for Chinese version enter 'zh_CN', further configuration is required later):
define( 'YOURLS_LANG', '' );
Exclude Sensitive Words (Long URLs containing the specified sensitive words will not be shortened):
$yourls_reserved_URL = [ '1', ];
Step Eight: Install Language Pack (Skip if Language is Not Changed)
git clone https://github.com/ZvonimirSun/YOURLS-zh_CN.git && mv YOURLS-zh_CN/* /root/YOURLS-1.9.2/user/languages/ && rm -rf YOURLS-zh_CN
Step Nine: Configure and Restart Apache
sudo mv /root/YOURLS-1.9.2/* /var/www/html/
sudo chown -R www-data:www-data /var/www/html/
sudo systemctl restart apache2
Conclusion:
Feel free to leave your shortened links in the comment section and see how short they can get.
Original link:http://enblog.fuyiran.link/Technology/16.html
Copyright: All posts on this blog, unless otherwise stated, are published using theCC BY-NC-SA 4.0 license agreement. Please indicate the source for reprinting Fu Speaking (enblog.fuyiran.link)