---
title: "Deploy YOURLS"
description: "The de facto standard self-hosted URL shortener."
category: "Other"
url: https://railway.com/deploy/yourls
---

# Deploy YOURLS

The de facto standard self-hosted URL shortener.

**[Deploy YOURLS on Railway](https://railway.com/template/yourls)**

- **Creator:** Rees
- **Category:** Other
- **Total deploys:** 24

## Template content

### yourls

- **Image:** yourls:latest
- **Public domain:** Yes

### MySQL https://devicons.railway.app/i/mysql.svg

- **Image:** mysql:9
- **Start command:** `docker-entrypoint.sh mysqld --innodb-use-native-aio=0 --disable-log-bin --performance_schema=0 --innodb-buffer-pool-size=1G`

## Documentation

# Deploy and Host YOURLS on Railway

**YOURLS** is a set of PHP scripts that will allow you to run **Y**our **O**wn **URL** **S**hortener, on **your** server. You'll have full control over your data, detailed stats, analytics, plugins, and more. It's free and open-source.

## About Hosting YOURLS

### Post-Deployment Setup

Once both services are running, click on the `yourls` service and visit the `.railway.app` domain generated for it. You can also add your own domain now, if you prefer.

When you visit the URL, **you should see a “Forbidden” message**

&gt; **If you see a Railway error**, you’ll need to configure the ports for your app:
&gt; 
&gt; 1.  In Railway, click on the `yourls` service.
&gt; 2.  Navigate to **Settings**, then scroll down to **Networking**.
&gt; 3.  Click on the Edit Icon, then click on **→ Edit Port**.
&gt; 4.  If port `80` is showing, select that one. Otherwise, click **\+ Custom Port**, then enter `80`.
&gt; 5.  Click on **Update**, and your domain should now work!

From the domain with the “Forbidden” message, add `/admin` to the end of the URL. This should redirect you to an installation page.

1.  Click on the **Install YOURLS** button.
2.  Once everything is successful, click on the **YOURLS Administration Page** link.
3.  Your username and password are created as part of the template.
    1.  In Railway, click on the `yourls` service.
    2.  Navigate to **Variables**, then scroll down until you see `YOURLS_PASS`.
        - _Note that there is a variable with the name_ YOURLS_DB_PASS _— ignore this one._
    3.  Hover over the variable and click the Copy button that appears.
    4.  Head back to the login page and enter `admin` as the username (unless you changed it in the Variables tab) and the password you copied.
4.  You should now be signed in to your YOURLS instance!

## Dependencies for YOURLS Hosting

### Deployment Dependencies

| Service | Version | Purpose | Source Image |
| --- | --- | --- | --- |
| YOURLS | latest | URL shortener | [Docker Hub](https://hub.docker.com/_/yourls) |
| MySQL | 9   | Database | [Docker Hub](https://hub.docker.com/_/mysql) |

### Environment Variables

| Variable | Required | Default Value &amp; Description |
| --- | --- | --- |
| `YOURLS_SITE` | Yes | `https://${{RAILWAY_PUBLIC_DOMAIN}}`<br>YOURLS instance URL, no trailing slash, lowercase. |
| `YOURLS_USER` | Yes | `admin`<br>YOURLS instance username. |
| `YOURLS_PASS` | Yes | `${{ secret(32, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") }}`<br>YOURLS instance password. |
| `YOURLS_DB_HOST` | No  | `${{MySQL.MYSQLHOST}}`<br>Host for the database. |
| `YOURLS_DB_USER` | No  | `${{MySQL.MYSQLUSER}}`<br>User for the database. |
| `YOURLS_DB_PASS` | No  | `${{MySQL.MYSQLPASSWORD}}`<br>Password for the database. |
| `YOURLS_DB_NAME` | No  | `${{MySQL.MYSQL_DATABASE}}`<br>Database name. The database must have been created before installing YOURLS. |
| `YOURLS_DB_PREFIX` | No  | `undefined`<br>Database tables prefix, defaults to yourls_. Only set this when you need to override the default table prefix. |

### Resource Requirements

- **Memory**: Minimal
- **CPU**: Minimal
- **Storage**: No volume; database grows with usage

## Troubleshooting

For common issues and community support, visit the [Railway Community Forum](https://station.railway.com/templates/yourls-44c7cc8f).

## Template Changelog

- **5 July, 2025**
    - Added descriptions to all environment variables and correctly marked optional ones

- **29 Jun, 2025**
    - Created template

---

## Common Use Cases

- **Brand-consistent marketing campaigns** - Use your own domain for all shortened links to maintain brand recognition and trust
- **Analytics and tracking** - Monitor click-through rates, geographic data, and referrer information for marketing insights  
- **Internal link management** - Create memorable short links for internal documentation, resources, and team sharing
- **Social media optimization** - Generate clean, trackable links for social media posts and email campaigns
- **API integration** - Programmatically create and manage short URLs through YOURLS' comprehensive REST API

## Why Deploy YOURLS on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying YOURLS on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.

## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/yourls
