URL Shortener

2. Repository Klonen

mkdir -p ~/projects && cd ~/projects
git clone https://github.com/YOURLS/YOURLS.git
cd YOURLS
git checkout 1.9.2 && git stash
composer install --no-dev
cp user/config-sample.php user/config.php && chmod 0600 user/config.php && sudo chown www-data:www-data user/config.php

3. MySQL User 'yourls' und Datenbank 'yourls' erstellen.

mysql -u root -p --execute="CREATE USER IF NOT EXISTS yourls@localhost IDENTIFIED BY '<password>';"
mysql -u root -p --execute="GRANT USAGE ON *.* TO yourls@localhost REQUIRE NONE;"
mysql -u root -p --execute="CREATE DATABASE IF NOT EXISTS yourls;"
mysql -u root -p --execute="GRANT ALL PRIVILEGES ON yourls.* TO yourls@localhost;"

4. Die Datei user/config.php bearbeiten

/** MySQL database password */
define( 'YOURLS_DB_PASS', '<mysql-password>' );

define( 'YOURLS_SITE', 'https://s.locr.com' );

/** A random secret hash used to encrypt cookies. You don't have to remember it, make it long and complicated
 ** Hint: copy from http://yourls.org/cookie */
define( 'YOURLS_COOKIEKEY', '<hash>' );

/** Username(s) and password(s) allowed to access the site. Passwords either in plain text or as encrypted hashes
 ** YOURLS will auto encrypt plain text passwords in this file
 ** Read http://yourls.org/userpassword for more information */
$yourls_user_passwords = [
    'serverconnect' => '<login-password>' /* Password encrypted by YOURLS */ ,
    // 'username2' => 'password2',
    // You can have one or more 'login'=>'password' lines
];

/** URL shortening method: either 36 or 62
 ** 36: generates all lowercase keywords (ie: 13jkm)
 ** 62: generates mixed case keywords (ie: 13jKm or 13JKm)
 ** For more information, see https://yourls.org/urlconvert */
define( 'YOURLS_URL_CONVERT', 62 );

5. WebServer Konfiguration

5.1. nginx Datei /etc/nginx/sites-available/s.locr.com hinzufügen

server {
    listen 80;
    listen [::]:80;
    listen 443 ssl http2;
    listen [::]:443 ssl http2;

    root /home/serverconnect/projects/YOURLS;

    index index.php index.html;

    server_name s.locr.com;

    include snippets/snakeoil.conf;
    # ssl_certificate     /etc/letsencrypt/live/s.locr.com/fullchain.pem;
    # ssl_certificate_key /etc/letsencrypt/live/s.locr.com/privkey.pem;

    client_max_body_size 1024M;

    # for Let's Encrypt
    location /.well-known {
        try_files $uri $uri/ = 404;
    }

    if ($scheme != "https") {
        rewrite ^ https://$host$uri permanent;
    }

    include conf.d/php;

    location / {
        if (!-e $request_filename){
            rewrite ^(.*)$ /yourls-loader.php last;
        }

        try_files $uri $uri/ /yourls-loader.php$is_args$args;
    }
}
cd /etc/nginx/sites-enabled && sudo ln -s ../sites-available/s.locr.com .
sudo service nginx restart

5.3. Let’s Encrypt Zertifikat erstellen

sudo certbot certonly --email entwicklung@locr.com --webroot -w /home/serverconnect/projects/YOURLS -d s.locr.com

5.4. Die Datei /etc/nginx/sites-enabled/s.locr.com bearbeiten und nginx neustarten

    # include snippets/snakeoil.conf;
    ssl_certificate     /etc/letsencrypt/live/s.locr.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/s.locr.com/privkey.pem;
sudo service nginx restart