NeutralAxisTwitter

YOURLS for Self-hosted Short URLs

by on Dec.19, 2009, under Blogging, Linux
Visited 4035 times, 8 so far today

yourlsIf you don’t want to depend on an external short URL service like bit.ly or tinyurl.com and you have access to your MySQL database, you can install and run your own with YOURLS.  I managed to get it up and running in about an hour in Linux.  The instructions at yourls.org mentions that an installation alongside WordPress is a bit different than the one described for a standard site.  I found that to be true, and have described what I found worked after the break.

YOURLS is a free download at yourls.org.  The procedure I’ll outline worked for me with the intention of using YOURLS in conjunction with WordPress.  Depending on your WordPress installation, you may have to make some changes.

  1. Through whatever means you choose, create a new MySQL database named yourls and assign a username and password.  If you don’t know how to create a database, you can find that elsewhere.  If you’re using Linux, phpmyadmin is a good tool for working with MySQL databases.
  2. Download the zip file from yourls.org/download
  3. Unzip the YOURLS archive into a folder so all the internal files and folders are in a folder with a short name, like ‘y’.  For instance, the path might be /var/www/y/contents of archive.
  4. Copy includes/config-sample.php to includes/config.php
  5. Open includes/config.php with a raw text editor (like Notepad) and fill in the required settings.  I’ll only list the settings that changed from their default.
    • YOURLS_DB_USER
      your MySQL username
      Example: 'joe'
    • YOURLS_DB_PASS
      your MySQL password
      Example: 'MySeCreTPaSsW0rd'
    • YOURLS_SITE
      Your (short) domain URL, no trailing slash.  If you’re buying a new short domain put it here, or you can use your regular domain.  Also notice that this includes the folder where the YOURLS files are.
      Example: 'http://yoursite.com/y'
    • YOURLS_HOURS_OFFSET
      Timezone GMT offset
      Example: '-5'  -6 is correct for me, but it was offsetting wrong.  Changed it to +1 and its now showing the right local time.
    • YOURLS_COOKIEKEY
      A random secret hash used to encrypt cookies. You don’t have to remember it, make it long and complicated. Hint: generate a unique one at http://yourls.org/cookie
      Example: 'qQ4KhL_pu|s@Zm7n#%:b^{A[vhm'
    • yourls_user_passwords
      A list of username(s) and password(s) allowed to access the site if private.  You'll want it to be private.  I started out with it public, thinking I didn't want to mess with a login, but within the first few minutes I saw a short URL show up that I hadn't made.  I don't know if that was someone else somehow doing it, or if I did it accidentally, but it was weird.
      Example: 'joe' => 'mypassword'
  6. Upload the /y folder and all its contents to be in the same folder as WordPress' wp-contents, wp-includes, etc.
  7. Cross your fingers and point your browser to http://yoursite.com/y/admin/index.php
  8. In my case, I got a report that the database was configured correctly, but that it failed to create the .htaccess file.  Instructions were given to manually create it and I placed it into the /y/ folder with the /y/ folder added into its paths.

    # BEGIN YOURLS
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /y/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([0-9A-Za-z]+)/?$ /y/yourls-go.php?id=$1 [L]
    RewriteRule ^([0-9A-Za-z]+)\+/?$ /y/yourls-infos.php?id=$1 [L]
    </IfModule>
    # END YOURLS
  9. At that point, it should be ready.  You can again go to http://yoursite.com/y/admin/index.php and you'll see a web interface to manually create short URLS.

At that point you have YOURLS installed.  Now to integrate it with WordPress, you need to log into WordPress and install the YOURLS: WordPress to Twitter plugin by OZH.

Pages: 1 2

:, ,


Tweet ThisFacebook ShareRight Click & Copy URL

1 Comment for this entry

Leave a Reply

See Commenting Guidelines

Spam protection by WP Captcha-Free

Visit our friends!

A few highly recommended friends...