How can we help?
YOURLS: Branded URL Shortener on a Dedicated Server
Introduction
Run a branded URL shortener with YOURLS on a ServerStadium dedicated server (or ServerStadium VM). This guide sets up YOURLS on Ubuntu 24.04 with Nginx, PHP 8.3, MariaDB/MySQL, and automatic HTTPS via Let’s Encrypt—so your team gets short links, click analytics, and a simple admin UI on your own domain.
Prerequisites
- A ServerStadium dedicated server or VM running Ubuntu 24.04.
- A domain like
sho.rt
oryourls.example.com
pointing to your server’s public IP. - SSH access with a sudo-capable user and an email address for Let’s Encrypt notices.
Step 1 — Install Nginx, PHP-FPM, and MariaDB
sudo apt update && sudo apt -y upgrade
sudo apt -y install nginx mariadb-server \
php8.3-fpm php8.3-mysql php8.3-curl php8.3-xml php8.3-mbstring php8.3-gd php8.3-zip php8.3-intl \
unzip curl certbot python3-certbot-nginx
sudo systemctl enable --now nginx mariadb php8.3-fpm
Step 2 — Create the Database
sudo mysql_secure_installation
sudo mysql -e "CREATE DATABASE yourls DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER 'yourlsuser'@'localhost' IDENTIFIED BY 'ChangeThisStrongPassword!';"
sudo mysql -e "GRANT ALL PRIVILEGES ON yourls.* TO 'yourlsuser'@'localhost'; FLUSH PRIVILEGES;"
Step 3 — Download YOURLS (Latest Stable) and Deploy
This uses the current stable release (1.10.2). Adjust if a newer stable version is available.
sudo mkdir -p /var/www/yourls
cd /tmp
wget -O yourls.tar.gz https://github.com/YOURLS/YOURLS/archive/refs/tags/1.10.2.tar.gz
tar -xzf yourls.tar.gz
sudo rsync -a YOURLS-1.10.2/ /var/www/yourls/
sudo chown -R www-data:www-data /var/www/yourls
Step 4 — Configure YOURLS
# Create the user config directory
sudo mkdir -p /var/www/yourls/user
# Generate a cookie key
CK=$(openssl rand -base64 48)
# Write config.php (edit domain, users, and passwords as needed)
sudo tee /var/www/yourls/user/config.php >/dev/null < 'ChangeThisStrongPassword!' // set a strong password
);
/* Optional locale and timezone */
// define( 'YOURLS_LANG', '' );
// define( 'YOURLS_HOURS_OFFSET', 0 );
EOF
sudo chown www-data:www-data /var/www/yourls/user/config.php
sudo chmod 440 /var/www/yourls/user/config.php
Step 5 — Nginx Server Block + PHP-FPM
sudo tee /etc/nginx/sites-available/yourls >/dev/null <<'EOF'
server {
listen 80;
listen [::]:80;
server_name yourls.example.com;
root /var/www/yourls;
index index.php;
# YOURLS loader: route all unmatched paths to yourls-loader.php
location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
# Security: deny access to hidden files (except .well-known for ACME)
location ~ /\.(?!well-known) {
deny all;
}
}
EOF
sudo ln -s /etc/nginx/sites-available/yourls /etc/nginx/sites-enabled/yourls
sudo nginx -t && sudo systemctl reload nginx
Step 6 — Enable HTTPS (Let’s Encrypt)
sudo certbot --nginx -d yourls.example.com --redirect -m you@example.com --agree-tos -n
Step 7 — Run the Installer & Log In
- Open
https://yourls.example.com/admin/install.php
to create the database tables. - Then go to
https://yourls.example.com/admin/
and log in with the admin user configured inconfig.php
. - Create your first branded short link and share it!
Optional: Public API & Plugins
- For team usage only, keep YOURLS private (default). If you want a public API, set
define('YOURLS_PRIVATE_API', false);
inconfig.php
. - Explore plugins (rate limiting, QR codes, custom keywords) from the YOURLS ecosystem to extend functionality.
Firewall & Service Checks
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo systemctl status nginx php8.3-fpm --no-pager
Troubleshooting
- Blank/403 at root: YOURLS intentionally doesn’t show a homepage—use
/admin/
for the UI. Short URLs still resolve from the root. - PHP errors: Ensure PHP 8.1+ is installed and FPM socket path matches your version (Ubuntu 24.04 uses
/run/php/php8.3-fpm.sock
). - Short links 404: Confirm your Nginx block contains
try_files $uri $uri/ /yourls-loader.php$is_args$args;
and you reloaded Nginx. - HTTPS fails: Check DNS A/AAAA records and re-run
certbot --nginx
. Inspect logs viajournalctl -u nginx -n 100 --no-pager
.
Want an easy, affordable start? Choose an instant ServerStadium dedicated server and brand your links today.
Conclusion
With YOURLS on ServerStadium, you control your data, domain, and analytics—all secured over HTTPS. For more help or information about ServerStadium services, visit our knowledge base or the ServerStadium website.