Upgrading YOURLS and Database Upgrade Errors Fix

Today YOURLS 1.4 was released, but the database upgrade script created some errors for some people, dead links, and the stats are not working. We can fix all that. Be sure to logout of the old version you will be upgrading from before starting the upgrade, or you might see the Install YOURLS page and link, rather than the Upgrade YOURLS page and link. First lets go over the changes in the config.php file.

There have been some changes to the config.php file, which you will create from the includes/config-sample.php file. If you are upgrading you have a few unexpected steps to upgrade our config.php file. Open up the new config-sample.php to create a new config.php file, then copy the data entries for each existing field into the new config.php file. You will need to copy and paste the lines for YOURLS_DB_TABLE_URL and YOURLS_DB_TABLE_NEXTDEC into the new config.php file, then after upgrading the database you’ll need to remove the YOURLS_DB_TABLE_NEXTDEC entry from the config.php file.
Go to yoursite dot com/admin/upgrade.php, and if everything in your config.php file is correct your should see the following.

This is where the upgrade script creates new tables, but it failed to create a new .htaccess file for me, so I had to create it myself.

Once the upgrade process is completed you should see the following page.

Fixing Database Errors and Statistics Errors with .htaccess
During the upgrade you might run into an error that says something like:
Huho… Could not update rown with url='http://www.nerdgrind.com/ajay-bhatt-co-creator-of-usb-port-on-conan/', from keyword '77' to keyword '25'
The entry is in the database, but during the upgrade process the example entry above was changed from a url ending in 25 to a new short url ending in 77. To fix this problem you’ll need to add an entry to your .htaccess file. For the example above we would add:
Redirect permanent /25 http://ngurl.me/77
Notice how the old short url ending "25" comes before the new short url ending "77". We are redirecting from the old url to the new url. These redirect lines will need to come before the lines that run YOURLS. A properly listed code would look like the following:
#Redirecting database 1.3 to 1.4 upgrade errors

Redirect permanent /26 http://ngurl.me/78
Redirect permanent /24 http://ngurl.me/76
Redirect permanent /25 http://ngurl.me/77

#End database redirect url correction

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9A-Za-z]+)/?$ yourls-go.php?id=$1 [L]
RewriteRule ^([0-9A-Za-z]+)+/?$ yourls-infos.php?id=$1 [L]
# END ShortURL

For those people, like myself, who the script failed to create a new .htaccess file, we were pointed to a the .htaccess example page for help. That’s where I noticed the reason my new stat links were resulting in a 404 error page. A new line pointing to the stats script (yourls-infos.php) needs to be added to the .htaccess file. The new line should be:
RewriteRule ^([0-9A-Za-z]+)+/?$ yourls-infos.php?id=$1 [L]
You can see in the example above exactly where the new line should be listed in the .htaccess file.
This new line to make the statistics work was not mentioned on the Install/Upgrade YOURLS page, but now you know.
Click here to learn how to backup your YOURLS database.

Leave a Comment