0225.html 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!DOCTYPE html>
  2. <html lang="en" xmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <title>Self-hosted URL Shortener with Shlink</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <meta charset="UTF-8">
  7. <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">
  8. <meta name="author" content="i12bretro">
  9. <meta name="description" content="Self-hosted URL Shortener with Shlink">
  10. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  11. <meta name="revised" content="01/13/2023 08:49:24 AM" />
  12. <link rel="icon" type="image/x-icon" href="includes/favicon.ico">
  13. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  14. <script type="text/javascript" src="includes/js/steps.js"></script>
  15. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  16. </head>
  17. <body>
  18. <div id="gridContainer">
  19. <div class="topMargin"></div>
  20. <div id="listName" class="topMargin">
  21. <h1>Self-hosted URL Shortener with Shlink</h1>
  22. </div>
  23. <div></div>
  24. <div id="content">
  25. <h2>What is Shlink?</h2>
  26. <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>
  27. <h2>Installing Shlink</h2>
  28. <ol>
  29. <li>Log into the Linux device</li>
  30. <li>Run the following commands in a terminal:
  31. <div class="codeBlock"># update software repositories<br />
  32. sudo apt update<br />
  33. # install software updates<br />
  34. sudo apt upgrade -y<br />
  35. # install pre-requisites<br />
  36. sudo apt install lsb-release apt-transport-https ca-certificates unzip -y<br />
  37. # add php gpg key<br />
  38. sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg<br />
  39. # add php apt repository<br />
  40. echo &quot;deb https://packages.sury.org/php/ $(lsb_release -sc) main&quot; | sudo tee /etc/apt/sources.list.d/php.list<br />
  41. # update software repositories<br />
  42. sudo apt update<br />
  43. # install Apache HTTPD and MySQL<br />
  44. sudo apt-get install apache2 mariadb-server mariadb-client -y<br />
  45. # install PHP components<br />
  46. 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 />
  47. # enable/disable apache2 modules<br />
  48. sudo a2dismod mpm_prefork php8.0<br />
  49. sudo a2enmod mpm_event rewrite proxy_fcgi setenvif php8.0<br />
  50. sudo a2enconf php8.0-fpm<br />
  51. # configure the MySQL database<br />
  52. sudo su<br />
  53. mysql_secure_installation</div>
  54. </li>
  55. <li>Press Enter to login as root</li>
  56. <li>Type Y and press Enter to set a root password, type the password twice to confirm</li>
  57. <li>Type Y and press Enter to remove anonymous users</li>
  58. <li>Type Y and press Enter to disallow root login remotely</li>
  59. <li>Type Y and press Enter to remove the test database</li>
  60. <li>Type Y and press Enter to reload privilege tables</li>
  61. <li>Run the following command to login into MySQL:
  62. <div class="codeBlock">mysql -u root -p</div>
  63. </li>
  64. <li>Authenticate with the root password set earlier</li>
  65. <li>Run the following commands to create the ShlinkIO database and database user
  66. <div class="codeBlock"># NOTE: update the password with a secure password<br />
  67. CREATE DATABASE shlinkio;<br />
  68. GRANT ALL ON shlinkio.* to &#39;shlinkio_rw&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;$hlink10!&#39;;<br />
  69. FLUSH PRIVILEGES;<br />
  70. EXIT;<br />
  71. exit</div>
  72. </li>
  73. <li>Continue with the following commands to download and extract shlinkio
  74. <div class="codeBlock"># download latest shlink.io version<br />
  75. sudo wget https://github.com/shlinkio/shlink/releases/download/v2.6.2/shlink2.6.2_php8.0_dist.zip<br />
  76. # extract the zip archive<br />
  77. sudo unzip shlink2.6.2_php8.0_dist.zip -d /var/www<br />
  78. # rename the extracted folder<br />
  79. sudo mv /var/www/shlink* /var/www/shlinkio<br />
  80. # set the owner of the new shlinkio directory to www-data<br />
  81. sudo chown -R www-data:www-data /var/www/shlinkio<br />
  82. # run the shlinkio installer<br />
  83. sudo -u www-data php /var/www/shlinkio/bin/install</div>
  84. </li>
  85. <li>Type 1 for MariaDB &gt; Press Enter</li>
  86. <li>Type shlinkio for the database name &gt; Press Enter</li>
  87. <li>Press enter to use localhost for the database host</li>
  88. <li>Press enter to accept the default MySQL port</li>
  89. <li>Type shlinkio_rw for the database username &gt; Press Enter</li>
  90. <li>Type the shlinkio_rw password created earlier ($hlink10!) &gt; Press Enter</li>
  91. <li>Press Enter at the Unix socket prompt</li>
  92. <li>Enter the default domain name to use for shortened URLs,</li>
  93. <li>Type 0 for http &gt; Press Enter</li>
  94. <li>Press Enter to validate long URLs</li>
  95. <li>Press Enter to accept the default shortened URL length</li>
  96. <li>Press Enter to say no to having shlink resolve page titles</li>
  97. <li>Press Enter to track orphan visits</li>
  98. <li>Press Enter at the GeoLite2 license key prompt</li>
  99. <li>Press Enter to anonymize report IP addresses</li>
  100. <li>Enter 301 for the kind of redirect &gt; Press Enter</li>
  101. <li>Press Enter to accept the default redirect cache value</li>
  102. <li>Press Enter to accept displaying a 404 for all 3 redirects options</li>
  103. <li>Press Enter to leave parameter name blank</li>
  104. <li>Type No to enable safety check &gt; Press Enter</li>
  105. <li>Type /shlinkio for the path &gt; Press Enter</li>
  106. <li>Press Enter at the integrations prompt</li>
  107. <li>With the installation completed, run the following command to create a shlinkio.conf apache configuration
  108. <div class="codeBlock"># download shlinkio web client<br />
  109. sudo wget https://github.com/shlinkio/shlink-web-client/releases/download/v3.1.0/shlink-web-client_3.1.0_dist.zip<br />
  110. # extract the zip archive<br />
  111. sudo unzip shlink-web-client_3.1.0_dist.zip<br />
  112. # move the extracted files to the web root<br />
  113. sudo mv ./shlink-web-client*/* /var/www/html<br />
  114. sudo nano /etc/apache2/sites-available/shlinkio.conf</div>
  115. </li>
  116. <li>Paste the following configuration into shlinkio.conf
  117. <p>Alias /shlinkio &quot;/var/www/shlinkio/public/&quot;<br />
  118. &lt;Directory /var/www/shlinkio/public&gt;<br />
  119. Options FollowSymlinks Includes ExecCGI<br />
  120. AllowOverride All<br />
  121. Require all granted<br />
  122. Order allow,deny<br />
  123. allow from all<br />
  124. &lt;/Directory&gt;</p>
  125. </li>
  126. <li>Press CTRL+O, Enter, CTRL+X to write the changes to shlinkio.conf</li>
  127. <li>Continue with the following commands to enable the site and restart Apache:
  128. <div class="codeBlock"># enable the shlinkio site<br />
  129. sudo a2ensite shlinkio<br />
  130. # restart apache2 service for the changes to take effect<br />
  131. sudo systemctl restart apache2<br />
  132. # generate an API key<br />
  133. sudo -u www-data php /var/www/shlinkio/bin/cli api-key:generate</div>
  134. </li>
  135. <li>Copy the generated API key to the clipboard</li>
  136. <li>Open a web browser and navigate to http://DNSorIP</li>
  137. <li>Click the add your first server link</li>
  138. <li>Enter a name for the server, the URL should be http://DNSorIP/shlinkio and paste the copied API key from earlier</li>
  139. </ol> </div>
  140. </div>
  141. </body>
  142. </html>