03.04

You and Urls and Browser Plugins


Someone recently offered to pay me to write them a url shortening backend/script to use for themselves. Not only did I decide to not charge them for it, but I decided to write a chrome extension so you can use it with as little hassle as possible.

For the tl;dr; crowd: download the url shortening script and the chrome extension to use with your shiny new shortener. Instructions are included.

The following instructions are included in the README.txt of the tar file. But here they are for convenience, and for any questions: leave them in the comments. NOTE: these instructions are if you want a default installation setup. This assumes you want all the default table, user name, and password. It’s probably a good idea to change them, but that’s up to you.

Step 0: Things You Need

You’re going to need a url. Probably a short one? There are tons of crazy tld’s available. i chose ablu.us cause it’s moderately close, yours might work even better.

Apache with mod_rewrite. Or equivalent server/rewrite setup.

PHP.

Step 1: The Database

You’re going to need to create the database for your service. NOTE: the user@server$ and mysql> are the prompts you should  see (clearly user@server$ will be different for you).

user@server$ msyql -u root -p

mysql> CREATE DATABASE `uploads`;

mysql> GRANT ALL PRIVILEGES ON `uploads`.* TO 'uploads_user'@localhost IDENTIFIED BY 'uploads_pass';

mysql> FLUSH PRIVILEGES;

msyql> quit;

This will create the database we need to install things in the next step.

Step 2: Installation

If you table name, username, or password you need to edit config.php accordingly. There are also a number of other things you can customize in config.php like the alphabet used to chose characters from, the length of the shortened url.

One thing you MUST change the $site_url in config.php. Otherwise it will insert things into your database, but not give you the correct link back.

Visit /install of the folder from above from your browser (http://yourdoma.in/install). If you kept the defaults from the above step, you don’t need to change any of these fields.

Click “Install >>”. And barring any database errors, you should have a working url shortening service!

NOTE: You may want to consider removing the /install folder after this step. It’s not necessary as running it again won’t destroy any data, but you never know.

Chrome Extension

The chrome extension is pretty easy to use. The first time you try to use it, it will tell you to Set Shortener. You have two choices here: If you want to use your own service you just created, enter the following:

yourdomain/up.php?site=

If you want to use MY service, enter:

ablu.us/s/up.php?site=

I’m considering doing a Firefox addon as well, but creating one of those is a bit more involved.

This extension will work with any url shortening api that returns just the plain text of the short url. Examples include http://fizl.ushttp://is.gd.

That’s It!

You have your own url shortening service!

I am running a modified version of this on my own site: http://ablu.us/s/. The main ablu.us is an image uploader. Feel free to use it if you so chose, but I just created it for my own personal use for some coding practice.

Leave any questions in the comments below, and i’ll try to get to them.

Follow me on twitter: @helloandre


Leave a Reply