Installing, Configuring, and Setting up the YOURLS Short URL Program

Publish: 2018-01-10 | Modify: 2018-04-23

YOURLS is a short link program developed using PHP + MySQL. Compared to public short URLs, the advantage of YOURLS is that the data is controlled by the user and has higher controllability.

secureurl_520

1. Download

YOURLS is free and open source. You can download the latest version from Releases · YOURLS/YOURLS, unzip it and place it in the root directory of your website. Rename config-sample.php to config.php.

mv user/config-sample.php user/config.php

2. Configure MySQL Database

You need to create a new MySQL database and set up the account and password (skipped). Then modify the user/config.php configuration file and fill in the correct MySQL information. The configuration information is as follows.

# Database username
define( 'YOURLS_DB_USER', 'yourls' );

# Database password
define( 'YOURLS_DB_PASS', 'xxxxxxxx' );

# Database name
define( 'YOURLS_DB_NAME', 'yourls' );

# Database host
define( 'YOURLS_DB_HOST', 'localhost' );

# Database table prefix, usually keep the default
define( 'YOURLS_DB_PREFIX', 'yourls_' );

3. Set Username and Password

# Modify the configuration file
vi user/config.php
# Set username and password, multiple users can be set
$yourls_user_passwords = array(
        'username' => 'password',
        // 'username2' => 'password2',
        // You can have one or more 'login'=>'password' lines
        );

4. Other Settings

# Set website domain name
define( 'YOURLS_SITE', 'http://ozh.in' );
# GMT time offset
define( 'YOURLS_HOURS_OFFSET', '-5' );
# Whether it is private
define( 'YOURLS_PRIVATE', 'true' );
# Set cookie, you can visit https://api.yourls.org/services/cookiekey/1.0/ to generate
define( 'YOURLS_COOKIEKEY', 'qQ4KhL_pu|s@Zm7n#%:b^{A[vhm' );
# MySQL connection method
define('YOURLS_DB_DRIVER','mysqli');

5. Set Pseudo-Static

YOURLS is already built-in with Apache .htaccess rules by default. If you are using Apache server and have enabled pseudo-static support, you generally do not need to set it again. If you are using Nginx, please add the following rules and reload Nginx.

location / {
    try_files $uri $uri/ /yourls-loader.php?$args;
}

6. Set Chinese Language

YOURLS is set to Chinese interface by default, which is not convenient to operate. I saw that some netizens provided Chinese translation. Visit yourls-zh_CN to download the Chinese package, unzip it to the user/languages directory, and then modify user/config.php.

# Put the language pack in languages
[root@aliyun-hz languages]# ll
total 68
-rw-r--r-- 1 www www   210 Apr 23  2017 index.html
-rw-r--r-- 1 www www    51 Mar 24  2013 README.md
-rw-r--r-- 1 www www 22123 Mar 24  2013 zh_CN.mo
-rw-r--r-- 1 www www 32783 Mar 24  2013 zh_CN.po
# Modify the configuration file to enable Chinese
vi user/config.php
# Enable Chinese
define( 'YOURLS_LANG', 'zh_CN' );

7. Access Test

After completing the above configuration, access http://domain.com/admin to complete the initial installation. Enter the account and password set in step 3 to log in.

snipaste_20180110_144008

snipaste_20180110_144322

Summary

YOURLS can also provide statistics on link data, including visits/regions/sources, and also provides API support (refer to the official documentation). In terms of functionality, it is basically enough, but the interface is a bit outdated.

Demo: https://dwz.ovh/laoxue (visiting this address will redirect to Laoxue's host) Official website: http://yourls.org/ Source code: https://github.com/YOURLS/YOURLS


Comments