123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <!DOCTYPE html>
- <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>Self-hosted URL Shortener with Shlink</title>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <meta charset="UTF-8">
- <meta name="keywords" content="Browser Based,Home Lab,Home Lab Ideas,Install Guide,Self-Hosted,Web Based,Web Based Tools,FOSS,Free Software,Linux,Open Source,Self-Hosted URL Shortener,Shlink,Shlink.io,URL Shortener,Debian,Shlink.io Installation Guide,How To Install Shlink.io,How To,Tutorial,i12bretro">
- <meta name="author" content="i12bretro">
- <meta name="description" content="Self-hosted URL Shortener with Shlink">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="revised" content="01/13/2023 08:49:24 AM" />
- <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
- <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
- <script type="text/javascript" src="includes/js/steps.js"></script>
- <link href="css/steps.css" rel="stylesheet" type="text/css" />
- </head>
- <body>
- <div id="gridContainer">
- <div class="topMargin"></div>
- <div id="listName" class="topMargin">
- <h1>Self-hosted URL Shortener with Shlink</h1>
- </div>
- <div></div>
- <div id="content">
- <h2>What is Shlink?</h2>
- <blockquote><em>A PHP-based self-hosted URL shortener that can be used to serve shortened URLs under your own custom domain.</em> -<a href="https://github.com/shlinkio/shlink" target="_blank">https://github.com/shlinkio/shlink</a></blockquote>
- <h2>Installing Shlink</h2>
- <ol>
- <li>Log into the Linux device</li>
- <li>Run the following commands in a terminal:
- <div class="codeBlock"># update software repositories<br />
- sudo apt update<br />
- # install software updates<br />
- sudo apt upgrade -y<br />
- # install pre-requisites<br />
- sudo apt install lsb-release apt-transport-https ca-certificates unzip -y<br />
- # add php gpg key<br />
- sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg<br />
- # add php apt repository<br />
- echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" | sudo tee /etc/apt/sources.list.d/php.list<br />
- # update software repositories<br />
- sudo apt update<br />
- # install Apache HTTPD and MySQL<br />
- sudo apt-get install apache2 mariadb-server mariadb-client -y<br />
- # install PHP components<br />
- sudo apt install php8.0 libapache2-mod-php8.0 php8.0-curl php8.0-intl php8.0-gd php8.0-pdo php8.0-fpm php8.0-common php8.0-mysql php8.0-xml php8.0-apcu -y<br />
- # enable/disable apache2 modules<br />
- sudo a2dismod mpm_prefork php8.0<br />
- sudo a2enmod mpm_event rewrite proxy_fcgi setenvif php8.0<br />
- sudo a2enconf php8.0-fpm<br />
- # configure the MySQL database<br />
- sudo su<br />
- mysql_secure_installation</div>
- </li>
- <li>Press Enter to login as root</li>
- <li>Type Y and press Enter to set a root password, type the password twice to confirm</li>
- <li>Type Y and press Enter to remove anonymous users</li>
- <li>Type Y and press Enter to disallow root login remotely</li>
- <li>Type Y and press Enter to remove the test database</li>
- <li>Type Y and press Enter to reload privilege tables</li>
- <li>Run the following command to login into MySQL:
- <div class="codeBlock">mysql -u root -p</div>
- </li>
- <li>Authenticate with the root password set earlier</li>
- <li>Run the following commands to create the ShlinkIO database and database user
- <div class="codeBlock"># NOTE: update the password with a secure password<br />
- CREATE DATABASE shlinkio;<br />
- GRANT ALL ON shlinkio.* to 'shlinkio_rw'@'localhost' IDENTIFIED BY '$hlink10!';<br />
- FLUSH PRIVILEGES;<br />
- EXIT;<br />
- exit</div>
- </li>
- <li>Continue with the following commands to download and extract shlinkio
- <div class="codeBlock"># download latest shlink.io version<br />
- sudo wget https://github.com/shlinkio/shlink/releases/download/v2.6.2/shlink2.6.2_php8.0_dist.zip<br />
- # extract the zip archive<br />
- sudo unzip shlink2.6.2_php8.0_dist.zip -d /var/www<br />
- # rename the extracted folder<br />
- sudo mv /var/www/shlink* /var/www/shlinkio<br />
- # set the owner of the new shlinkio directory to www-data<br />
- sudo chown -R www-data:www-data /var/www/shlinkio<br />
- # run the shlinkio installer<br />
- sudo -u www-data php /var/www/shlinkio/bin/install</div>
- </li>
- <li>Type 1 for MariaDB > Press Enter</li>
- <li>Type shlinkio for the database name > Press Enter</li>
- <li>Press enter to use localhost for the database host</li>
- <li>Press enter to accept the default MySQL port</li>
- <li>Type shlinkio_rw for the database username > Press Enter</li>
- <li>Type the shlinkio_rw password created earlier ($hlink10!) > Press Enter</li>
- <li>Press Enter at the Unix socket prompt</li>
- <li>Enter the default domain name to use for shortened URLs,</li>
- <li>Type 0 for http > Press Enter</li>
- <li>Press Enter to validate long URLs</li>
- <li>Press Enter to accept the default shortened URL length</li>
- <li>Press Enter to say no to having shlink resolve page titles</li>
- <li>Press Enter to track orphan visits</li>
- <li>Press Enter at the GeoLite2 license key prompt</li>
- <li>Press Enter to anonymize report IP addresses</li>
- <li>Enter 301 for the kind of redirect > Press Enter</li>
- <li>Press Enter to accept the default redirect cache value</li>
- <li>Press Enter to accept displaying a 404 for all 3 redirects options</li>
- <li>Press Enter to leave parameter name blank</li>
- <li>Type No to enable safety check > Press Enter</li>
- <li>Type /shlinkio for the path > Press Enter</li>
- <li>Press Enter at the integrations prompt</li>
- <li>With the installation completed, run the following command to create a shlinkio.conf apache configuration
- <div class="codeBlock"># download shlinkio web client<br />
- sudo wget https://github.com/shlinkio/shlink-web-client/releases/download/v3.1.0/shlink-web-client_3.1.0_dist.zip<br />
- # extract the zip archive<br />
- sudo unzip shlink-web-client_3.1.0_dist.zip<br />
- # move the extracted files to the web root<br />
- sudo mv ./shlink-web-client*/* /var/www/html<br />
- sudo nano /etc/apache2/sites-available/shlinkio.conf</div>
- </li>
- <li>Paste the following configuration into shlinkio.conf
- <p>Alias /shlinkio "/var/www/shlinkio/public/"<br />
- <Directory /var/www/shlinkio/public><br />
- Options FollowSymlinks Includes ExecCGI<br />
- AllowOverride All<br />
- Require all granted<br />
- Order allow,deny<br />
- allow from all<br />
- </Directory></p>
- </li>
- <li>Press CTRL+O, Enter, CTRL+X to write the changes to shlinkio.conf</li>
- <li>Continue with the following commands to enable the site and restart Apache:
- <div class="codeBlock"># enable the shlinkio site<br />
- sudo a2ensite shlinkio<br />
- # restart apache2 service for the changes to take effect<br />
- sudo systemctl restart apache2<br />
- # generate an API key<br />
- sudo -u www-data php /var/www/shlinkio/bin/cli api-key:generate</div>
- </li>
- <li>Copy the generated API key to the clipboard</li>
- <li>Open a web browser and navigate to http://DNSorIP</li>
- <li>Click the add your first server link</li>
- <li>Enter a name for the server, the URL should be http://DNSorIP/shlinkio and paste the copied API key from earlier</li>
- </ol> </div>
- </div>
- </body>
- </html>
-
|