Your Own URL Shortener
YOURLS is a set of PHP scripts that will allow you to run Your Own URL Shortener, on your server. You'll have full control over your data, detailed stats, analytics, plugins, and more. It's free and open-source.
- Getting Started
- Setup
- Usage
- Architecture
- Community news, tips and tricks
- Contributing
- Backers
- Sponsors
- License
Check out the complete documentation on docs.yourls.org. It contains everything from beginners to experts.
- Download YOURLS: Clone or download the YOURLS repository from GitHub.
- Configure your server: Make sure your server meets the requirements:
- PHP 7.2 or greater
- MySQL 5.0 or greater
mod_rewriteenabled
- Create a database: Create a new MySQL database and a user with full privileges.
- Configure YOURLS:
- Rename
user/config-sample.phptouser/config.php. - Open
user/config.phpand fill in the required database settings. - Customize the other settings to your liking.
- Rename
- Install YOURLS: Open your browser and navigate to
http://your-site.com/admin/install.php. - Secure your installation:
- Make sure the
user/config.phpfile is not publicly accessible. - Change the default username and password in
user/config.php. - Delete the
admin/install.phpfile after the installation is complete.
- Make sure the
The admin interface is located at http://your-site.com/admin/. From here, you can:
- Shorten URLs: Add new short URLs and custom keywords.
- Manage URLs: View, edit, and delete existing short URLs.
- View stats: See detailed statistics for each short URL, including clicks, referrers, and geographic location.
- Manage plugins: Activate and deactivate plugins to extend the functionality of YOURLS.
- Use tools: Access the bookmarklets and API information.
YOURLS provides a simple API that allows you to shorten URLs, get stats, and more. The API is located at http://your-site.com/yourls-api.php.
For more information on how to use the API, see the API documentation.
YOURLS includes a Python FastMCP server (mcp_server.py) that exposes URL shortening, expansion, and statistics capabilities via the Model Context Protocol.
- Install requirements:
pip install mcp httpx pydantic - Set environment variables:
YOURLS_API_URL(default:http://localhost:8000/yourls-api.php)YOURLS_SIGNATURE(orYOURLS_USERNAMEandYOURLS_PASSWORD)
Run the server:
python mcp_server.pyThe server provides three tools:
shorten_url: Shortens a long URL using the YOURLS API.expand_url: Expands a short URL or keyword to its original long URL.get_url_stats: Retrieves statistics for a specific short URL.
YOURLS comes with handy bookmarklets for easier link shortening and sharing. To use them, drag and drop the links from the Tools page in the admin interface to your browser's toolbar.
The YOURLS application is structured as follows:
/admin: Contains the files for the admin interface./includes: Contains the core application files, including the functions for handling URLs, the database, and the API./user: Contains user-specific files, such as the configuration file and any custom plugins or pages./(root): Contains the main entry points for the application, including the redirection handler, the API, and the admin interface.
- Read and subscribe to the The Official YOURLS Blog
- Check what the user community makes: plugins, tools, guides and more on Awesome YOURLS
- Engage users and ask for help in our community discussions
- Keep track of development: "Star" and "Watch" this project, follow commit messages
If you are a new developer looking to contribute to YOURLS, welcome! The following guide will help you set up your development and testing environment.
- PHP 7.4+ (8.x recommended)
- Composer
- MySQL or MariaDB
- Xdebug (optional, for coverage and header testing)
To run the PHPUnit test suite, you need a dedicated test database:
-
Install and Configure Database: Install MariaDB/MySQL and start the service. Create an empty database named
yourls_tests:mysql -u root -e "CREATE DATABASE yourls_tests;" mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY ''; FLUSH PRIVILEGES;"
-
Configure Test Credentials: Copy the sample test configuration:
cp tests/data/config/yourls-tests-config-sample.php tests/yourls-tests-config.php
Edit
tests/yourls-tests-config.php:- Set the database username to
rootand password to an empty string''. - Set the database name to
yourls_tests. - Update
YOURLS_ABSPATHto your local repository directory path (e.g.,'/app'). Do not use global sed replacements as they can break configurations.
- Set the database username to
-
Install Dependencies: Navigate to the
tests/directory and install PHPUnit via Composer. If you encounter platform check issues with newer PHP versions, use the--ignore-platform-reqsflag:cd tests/ composer install --ignore-platform-reqs cd ..
-
Run Tests: Execute the test suite from the repository root:
php tests/vendor/bin/phpunit -c phpunit.xml.dist
includes/: Core functions, classes, and logic. Database interactions useYDB(which extends Aura SQL).admin/: Admin interface pages and AJAX handlers.tests/: PHPUnit test suite.yourls-api.php/includes/functions-api.php: The API surface.
Note on modifications: When adding new API actions, register them in $api_actions in yourls-api.php, define the callback in includes/functions-api.php, and update tests/tests/api/FuncTest.php to maintain adequate test coverage.
Feature suggestion? Bug to report?
Before opening any issue, please search for existing issues (open and closed) and read the Contributing Guidelines.
Do you use and enjoy YOURLS? Become a backer and show your support to our open source project.
Does your company use YOURLS? Ask your manager or marketing team if your company would be interested in supporting our project. Your company logo will show here. Help support our open-source development efforts by becoming a sponsor.
Free software. Do whatever the hell you want with it. YOURLS is released under the MIT license.
This repository utilizes a deterministic AI-Human orchestration framework to eliminate semantic ambiguity. Key artifacts include:
AGENTS.md: Embedded Project Management persona constrained by Feature Control Frames (FCF).DOMAIN_GLOSSARY.md: Strict bounded vocabulary definitions.CONSTRAINTS.md: Hard epistemic limits and architectural rules.docs/adr/: Architecture Decision Records capturing historical context.
