wiki:sysadmin:yourls_url_shortener_tutorial
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
wiki:sysadmin:yourls_url_shortener_tutorial [2025/01/07 12:37] – removed - external edit (Unknown date) 127.0.0.1 | wiki:sysadmin:yourls_url_shortener_tutorial [2025/01/07 12:38] (current) – ↷ Links adapted because of a move operation Greg | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Self-Hosted URL Shortener with YOURLS ====== | ||
+ | |||
+ | This tutorial will walk you through how to setup a URL shortener using YOURLS. Because it is a PHP-based app, you will need three things: | ||
+ | |||
+ | * Web server to handle the HTTP requests | ||
+ | * PHP interpreter to handle the application code | ||
+ | * Database to store data | ||
+ | |||
+ | To handle these three requirements, | ||
+ | |||
+ | **Note:** All of the commands shown below should be run as root, or prefixed with `sudo` to get root privileges. Some CAN be run without root, but for ease of use this guide will be assuming you're running as root. | ||
+ | |||
+ | ===== Step 1: Download and " | ||
+ | |||
+ | The first thing you need to do to install any software is download it. Head on over to the [[https:// | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Now we need to extract the ZIP file and put it in place so that Apache can read it. I tend to follow the [[https:// | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Then extract that YOURLS ZIP file that you downloaded a moment ago: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | **Note:** if the above command fails, try installing the unzip command with '' | ||
+ | |||
+ | If all goes well, you should now have a directory located at `/ | ||
+ | |||
+ | <code bash>cp user/ | ||
+ | |||
+ | And then open that new file up in your favorite text-editor, | ||
+ | |||
+ | <code bash>vim user/ | ||
+ | |||
+ | You'll be presented with a bunch of configuration options (using PHP code syntax) that you can modify to your heart' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | There are some more configuration options to look over if you please, but this is all we need to look at for now. Go ahead and save and close the config file, and get ready to install Apache. | ||
+ | |||
+ | ===== Step 2: Install Apache ===== | ||
+ | |||
+ | The second thing we need to do is to install Apache to handle HTTP requests to this server. Thankfully, installing Apache with a base configuration is really easy on most Linux distributions, | ||
+ | |||
+ | <code bash>apt install -y apache2</ | ||
+ | |||
+ | And you can check the status of the service like so: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | If all went well, then Apache is installed and running with a default configuration. Simply open up a web browser, and enter %%" | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | But of course, this isn't YOURLS, and the page we did get is kinda useless! Now we need to configure Apache to use/display your YOURLS site. Open up the Apache default site config: | ||
+ | |||
+ | <code bash>vim / | ||
+ | |||
+ | In the VirtualHost, | ||
+ | |||
+ | < | ||
+ | |||
+ | Then save and close the file. YOURLS also makes use of the Apache rewrite module, so we need to enable it with: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Then to load the updated configuration, | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | And if you refresh your web browser, it should now be showing something else... | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | It's just a bunch of code! That's not right... Well, by default Apache has no idea what to do with PHP code, so it's just serving the PHP files as a static plain text file. | ||
+ | |||
+ | ===== Step 3: Install PHP ===== | ||
+ | |||
+ | To get PHP working with Apache, we need to both install PHP and the Apache PHP module to link it all together. To do that, run: | ||
+ | |||
+ | <code bash>apt install -y php libapache2-mod-php</ | ||
+ | |||
+ | Then enable the newly installed mod-php for Apache like so: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | **Note:** it's usually just '' | ||
+ | |||
+ | And again, restart Apache to reload the config: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | One last thing before you open up your web browser is you will want to make the www-data user the owner of the website files. This is so it can install the app properly (mainly putting in place the '' | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Now open up your web browser again and go to the same address as before and prepend "/ | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | This is normal. YOURLS requires a database to run, and we haven' | ||
+ | |||
+ | ===== Step 4: Configure a Database with MySQL ===== | ||
+ | |||
+ | Finally, we just need to setup a database so YOURLS has a way to store information. As far as I can tell, YOURLS only supports MySQL/ | ||
+ | |||
+ | <code bash>apt install -y mariadb-server</ | ||
+ | |||
+ | And you can check the status of the service with: | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | While not strictly required, it's recommended to run the '' | ||
+ | |||
+ | Now that MariaDB is ready to roll, let's login and create a database for YOURLS. | ||
+ | |||
+ | <code bash> | ||
+ | |||
+ | Create a new database: | ||
+ | |||
+ | <code sql> | ||
+ | |||
+ | Create a new user for the database: | ||
+ | |||
+ | <code sql> | ||
+ | |||
+ | Grant all privileges on the YOURLS database to the new user: | ||
+ | |||
+ | <code sql> GRANT ALL PRIVILEGES ON yourls.* TO ' | ||
+ | |||
+ | And finally flush the database privileges. This is important so permission changes take effect! | ||
+ | |||
+ | <code sql> | ||
+ | |||
+ | And now exit with '' | ||
+ | |||
+ | With our database configured, let's head back to that '' | ||
+ | |||
+ | <code bash>vim / | ||
+ | |||
+ | And towards the top of the file should be several settings for the database configuration. Change the settings to match the following: | ||
+ | |||
+ | < | ||
+ | YOURLS_DB_USER => yourls | ||
+ | YOURLS_DB_PASS => secretpassword | ||
+ | YOURLS_DB_NAME => yourls | ||
+ | YOURLS_DB_HOST => localhost | ||
+ | </ | ||
+ | |||
+ | Now save and close the file, then refresh your browser. If all goes well, you should be at the YOURLS login page! | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | Enter your credentials, | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | At this point, your YOURLS installation is complete, and you can start shortening URLS! | ||
+ | |||
+ | ===== Step 5: Finishing Touches ===== | ||
+ | |||
+ | Now that YOURLS is running, there is one last set of tweaks I'd recommend to make your YOURLS experience better. Head on over to the Plugins page via the " | ||
+ | |||
+ | {{ wiki: | ||
+ | |||
+ | You can also enable the '' | ||
+ | |||
+ | Have fun! | ||