0225.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  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. <script type="text/javascript" src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
  7. <script type="text/javascript">
  8. $(function(){
  9. $('textarea').each(function(i,e){
  10. theTextarea = $(this);
  11. theTextarea.height((theTextarea[0].scrollHeight-5) +'px');
  12. });
  13. $('li').each(function(i,e){
  14. if(!$(this).hasClass('noCheckbox')){
  15. var uuid = 'li_' + Math.floor(Math.random() * Math.floor(1000000)).toString() + '_' + i.toString();
  16. $(this).contents().wrap('<span id="'+ uuid +'"><label for="cb_'+ uuid +'"></label></span>');
  17. $(this).prepend('<input type="checkbox" class="completeBox" id="cb_' + uuid +'" rel="'+ uuid +'" />')
  18. }
  19. });
  20. $('code,div.codeBlock,textarea.codeBlock').each(function(i,e){
  21. theElement = $(this);
  22. var lines = theElement.html().split("\n");
  23. theElement.empty();
  24. for(l=0;l<lines.length;l++){
  25. if($.trim(lines[l]) != '' && $.trim(lines[l]).substr(0,1) != '#' && $.trim(lines[l]).indexOf(' #') == -1 && lines[l].substr(0, 4).toUpperCase() != 'REM '){
  26. theElement.append('<input type="image" src="images/clipboard.png" value="" class="copy-text" rel="copy_'+ i +'_'+ l +'" data-clipboard-text="'+ $.trim(lines[l].replace(/"/g, '&quot;')) +'" /><span id="copy_'+ i +'_'+ l +'">'+ lines[l] +'</span>');
  27. } else {
  28. theElement.append(lines[l]);
  29. }
  30. }
  31. });
  32. $(document).on('click','input.copy-text',function(){
  33. theButton = $(this);
  34. $('input.copy-text').attr('src','images/clipboard.png');
  35. $('span.copy-animation,span.copy-animation-ps').removeClass('copy-animation copy-animation-ps');
  36. try {
  37. if($('#'+ theButton.attr('rel')).parent('div').hasClass('PS')){
  38. $('#'+ theButton.attr('rel')).addClass('copy-animation-ps');
  39. } else if($('#'+ theButton.attr('rel')).parent('div').hasClass('CMD')){
  40. $('#'+ theButton.attr('rel')).addClass('copy-animation-cmd');
  41. } else {
  42. $('#'+ theButton.attr('rel')).addClass('copy-animation');
  43. }
  44. navigator.clipboard.writeText(theButton.data('clipboard-text').replace(/<[^>]*>?/gm, ''));
  45. theButton.attr('src','images/clipboard_active.png');
  46. } catch(err) {
  47. }
  48. return false;
  49. });
  50. $(document).on('click','input.completeBox',function(){
  51. theBox = $(this);
  52. $('#'+ theBox.attr('rel')).addClass('strikethrough');
  53. theBox.prop('disabled',true);
  54. theBox.parent('li').prevAll().each(function(i,e){
  55. theLI = $(this);
  56. if(theLI.find('input[type=checkbox]').not(':checked')){
  57. $('#'+ theLI.find('input[type=checkbox]').attr('rel')).addClass('strikethrough');
  58. theLI.find('input[type=checkbox]').prop('checked',true).prop('disabled',true);
  59. }
  60. });
  61. });
  62. if(window.self !== window.top){
  63. window.parent.$('iframe.stepsFrame').height((this['scrollingElement']['scrollHeight']+20) +'px');
  64. }
  65. });
  66. </script>
  67. <link href="css/steps.css" rel="stylesheet" type="text/css" />
  68. </head>
  69. <body>
  70. <div id="gridContainer">
  71. <div class="topMargin"></div>
  72. <div id="listName" class="topMargin">
  73. <h1>Self-hosted URL Shortener with Shlink</h1>
  74. </div>
  75. <div></div>
  76. <div id="content">
  77. <h2>What is Shlink?</h2>
  78. <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>
  79. <h2>Installing Shlink</h2>
  80. <ol>
  81. <li>Log into the Linux device</li>
  82. <li>Run the following commands in a terminal:
  83. <div class="codeBlock"># update software repositories<br />
  84. sudo apt update<br />
  85. # install software updates<br />
  86. sudo apt upgrade -y<br />
  87. # install pre-requisites<br />
  88. sudo apt install lsb-release apt-transport-https ca-certificates -y<br />
  89. # add php gpg key<br />
  90. sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg<br />
  91. # add php apt repository<br />
  92. echo &quot;deb https://packages.sury.org/php/ $(lsb_release -sc) main&quot; | sudo tee /etc/apt/sources.list.d/php.list<br />
  93. # update software repositories<br />
  94. sudo apt update<br />
  95. # install Apache HTTPD and MySQL<br />
  96. sudo apt-get install apache2 mariadb-server mariadb-client -y<br />
  97. # install PHP components<br />
  98. 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 />
  99. # enable/disable apache2 modules<br />
  100. sudo a2dismod mpm_prefork php8.0<br />
  101. sudo a2enmod mpm_event rewrite proxy_fcgi setenvif php8.0<br />
  102. sudo a2enconf php8.0-fpm<br />
  103. # configure the MySQL database<br />
  104. sudo su<br />
  105. mysql_secure_installation</div>
  106. </li>
  107. <li>Press Enter to login as root</li>
  108. <li>Type Y and press Enter to set a root password, type the password twice to confirm</li>
  109. <li>Type Y and press Enter to remove anonymous users</li>
  110. <li>Type Y and press Enter to disallow root login remotely</li>
  111. <li>Type Y and press Enter to remove the test database</li>
  112. <li>Type Y and press Enter to reload privilege tables</li>
  113. <li>Run the following command to login into MySQL:
  114. <div class="codeBlock">mysql -u root -p</div>
  115. </li>
  116. <li>Authenticate with the root password set earlier</li>
  117. <li>Run the following commands to create the ShlinkIO database and database user
  118. <div class="codeBlock"># NOTE: update the password with a secure password<br />
  119. CREATE DATABASE shlinkio;<br />
  120. GRANT ALL ON shlinkio.* to &#39;shlinkio_rw&#39;@&#39;localhost&#39; IDENTIFIED BY &#39;$hlink10!&#39;;<br />
  121. FLUSH PRIVILEGES;<br />
  122. EXIT;<br />
  123. exit</div>
  124. </li>
  125. <li>Continue with the following commands to download and extract shlinkio
  126. <div class="codeBlock"># download latest shlink.io version<br />
  127. sudo wget https://github.com/shlinkio/shlink/releases/download/v2.6.2/shlink2.6.2_php8.0_dist.zip<br />
  128. # extract the zip archive<br />
  129. sudo unzip shlink2.6.2_php8.0_dist.zip -d /var/www<br />
  130. # rename the extracted folder<br />
  131. sudo mv /var/www/shlink* /var/www/shlinkio<br />
  132. # set the owner of the new shlinkio directory to www-data<br />
  133. sudo chown -R www-data:www-data /var/www/shlinkio<br />
  134. # run the shlinkio installer<br />
  135. sudo -u www-data php /var/www/shlinkio/bin/install</div>
  136. </li>
  137. <li>Type 0 for MySQL &gt; Press Enter</li>
  138. <li>Type shlinkio for the database name &gt; Press Enter</li>
  139. <li>Press enter to use localhost for the database host</li>
  140. <li>Press enter to accept the default MySQL port</li>
  141. <li>Type shlinkio_rw for the database username &gt; Press Enter</li>
  142. <li>Type the shlinkio_rw password created earlier &gt; Press Enter</li>
  143. <li>Press Enter at the Unix socket prompt</li>
  144. <li>Enter the default domain name to use for shortened URLs,</li>
  145. <li>Type 0 for http &gt; Press Enter</li>
  146. <li>Press Enter to validate long URLs</li>
  147. <li>Press Enter to accept the default shortened URL length</li>
  148. <li>Press Enter to say no to having shlink resolve page titles</li>
  149. <li>Press Enter to track orphan visits</li>
  150. <li>Press Enter at the GeoLite2 license key prompt</li>
  151. <li>Press Enter to anonymize report IP addresses</li>
  152. <li>Enter 301 for the kind of redirect &gt; Press Enter</li>
  153. <li>Press Enter to accept the default redirect cache value</li>
  154. <li>Press Enter to accept displaying a 404 for all 3 redirects options</li>
  155. <li>Press Enter to leave parameter name blank</li>
  156. <li>Type No to enable safety check &gt; Press Enter</li>
  157. <li>Type /shlinkio for the path &gt; Press Enter</li>
  158. <li>Press Enter at the integrations prompt</li>
  159. <li>With the installation completed, run the following command to create a shlinkio.conf apache configuration
  160. <div class="codeBlock"># download shlinkio web client<br />
  161. sudo wget https://github.com/shlinkio/shlink-web-client/releases/download/v3.1.0/shlink-web-client_3.1.0_dist.zip<br />
  162. # extract the zip archive<br />
  163. sudo unzip shlink-web-client_3.1.0_dist.zip<br />
  164. # move the extracted files to the web root<br />
  165. sudo mv ./shlink-web-client*/* /var/www/html<br />
  166. sudo nano /etc/apache2/sites-available/shlinkio.conf</div>
  167. </li>
  168. <li>Paste the following configuration into shlinkio.conf
  169. <p>Alias /shlinkio &quot;/var/www/shlinkio/public/&quot;<br />
  170. &lt;Directory /var/www/shlinkio/public&gt;<br />
  171. Options FollowSymlinks Includes ExecCGI<br />
  172. AllowOverride All<br />
  173. Require all granted<br />
  174. Order allow,deny<br />
  175. allow from all<br />
  176. &lt;/Directory&gt;<br />
  177. <directory shlinkio=""></directory></p>
  178. </li>
  179. <li>Press CTRL+O, Enter, CTRL+X to write the changes to shlinkio.conf</li>
  180. <li>Continue with the following commands to enable the site and restart Apache:
  181. <div class="codeBlock"># enable the shlinkio site<br />
  182. sudo a2ensite shlinkio<br />
  183. # restart apache2 service for the changes to take effect<br />
  184. sudo systemctl restart apache2<br />
  185. # generate an API key<br />
  186. sudo -u www-data php /var/www/shlinkio/bin/cli api-key:generate</div>
  187. </li>
  188. <li>Copy the generated API key to the clipboard</li>
  189. <li>Open a web browser and navigate to http://DNSorIP</li>
  190. <li>Click the add your first server link</li>
  191. <li>Enter a name for the server, the URL should be http://DNSorIP/shlinkio and paste the copied API key from earlier</li>
  192. </ol>
  193. </div>
  194. </div>
  195. </body>
  196. </html>