インストールガイド · 5 min read · Nov 29, 2025
CentOS 8にYOURLS自己ホスト型URL短縮サービスをインストールする方法

YOURLSは、PHPで書かれた無料のオープンソースの自己ホスト型URL短縮サービスです。TinyURLやBitlyに非常に似ており、自分自身のURL短縮サービスを運営することができます。また、短縮URLにブランドを追加することも可能です。プライベートおよびパブリックリンク、カスタムURLキーワード、履歴クリックレポート、Ajaxインターフェース、Jsonpサポートなど、豊富な機能を提供しています。
このチュートリアルでは、Let’s Encrypt SSLを使用してCentOS 8にYOURLSをインストールする方法を示します。
前提条件
- CentOS 8を実行しているサーバー。
- サーバーIPにポイントされた有効なドメイン名。
- サーバーに設定されたrootパスワード。
LEMPサーバーのインストール
まず、サーバーにNginx、MariaDB、PHPおよび必要なPHP拡張をインストールする必要があります。以下のコマンドで全てをインストールできます。
dnf install nginx mariadb-server php php-fpm php-json php-common php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-pear php-bcmath git unzip wget -yすべてのパッケージがインストールされたら、PHP-FPM設定ファイル/etc/php-fpm.d/www.confを編集し、ユーザーをapacheからnginxに変更します。
nano /etc/php-fpm.d/www.conf次の行を変更します。
user = nginx
group = nginxファイルを保存して閉じたら、Nginx、MariaDB、PHP-FPMサービスを起動し、システム再起動時に自動的に起動するように有効にします。
systemctl start nginx
systemctl enable nginx
systemctl start mariadb
systemctl enable mariadb
systemctl start php-fpm
systemctl enable php-fpm完了したら、次のステップに進むことができます。
YOURLS用のデータベースを作成
次に、YOURLS用のデータベースとユーザーを作成する必要があります。まず、以下のコマンドでMariaDBにログインします。
mysqlログインしたら、以下のコマンドでデータベースとユーザーを作成します。
MariaDB [(none)]> CREATE DATABASE yourlsdb;
MariaDB [(none)]> GRANT ALL PRIVILEGES ON yourlsdb.* TO 'yourlsuser'@'localhost' IDENTIFIED BY 'password';次に、特権をフラッシュし、以下のコマンドでMariaDBから退出します。
MariaDB [(none)]> FLUSH PRIVILEGES;
MariaDB [(none)]> \qこの時点で、MariaDBはインストールされ、設定されています。
YOURLSのインストール
まず、ディレクトリをNginxのウェブルートに変更し、以下のコマンドでYOURLSの最新バージョンをダウンロードします。
cd /var/www/html
git clone https://github.com/YOURLS/YOURLS.git次に、以下のコマンドでサンプル設定ファイルの名前を変更します。
cd YOURLS/user/
cp config-sample.php config.php次に、config.phpファイルを編集し、データベース設定を定義します。
nano config.php次の行を変更します。
/** MySQLデータベースのユーザー名 */
define( 'YOURLS_DB_USER', 'yourlsuser' );
/** MySQLデータベースのパスワード */
define( 'YOURLS_DB_PASS', 'password' );
/ YOURLS用のデータベース名
小文字のアルファベット[a-z]、数字[0-9]、アンダースコア[_]のみを使用 */
define( 'YOURLS_DB_NAME', 'yourlsdb' );
/ MySQLホスト名。
非標準ポートを使用する場合は、'hostname:port'のように指定します。例:'localhost:9999'または'127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );
/ MySQLテーブルのプレフィックス
YOURLSはこのプレフィックスを使用してテーブルを作成します(例:`yourls_url`、`yourls_options`、...)
** 小文字のアルファベット[a-z]、数字[0-9]、アンダースコア[_]のみを使用 */
define( 'YOURLS_DB_PREFIX', 'yourls_' );
define( 'YOURLS_SITE', 'http://yourls.example.com' );
$yourls_user_passwords = array(
'admin' => 'yourpassword',完了したらファイルを保存して閉じます。次に、以下のコマンドで.htaccessファイルを作成します。
nano /var/www/html/YOURLS/.htaccess次の行を追加します。
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
ファイルを保存して閉じたら、以下のコマンドで適切な権限と所有権を与えます。
chown -R nginx:nginx /var/www/html/YOURLS
chmod -R 775 /var/www/html/YOURLS完了したら、次のステップに進むことができます。
YOURLS用のNginxの設定
次に、YOURLS用の新しいNginx仮想ホスト設定ファイルを作成します。
nano /etc/nginx/conf.d/yourls.conf次の行を追加します。
server {
listen 80;
server_name yourls.example.com;
root /var/www/html/YOURLS;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ /yourls-loader.php$is_args$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_index index.php;
fastcgi_pass unix:/run/php-fpm/www.sock;
}
}ファイルを保存して閉じたら、以下のコマンドでNginxとPHP-FPMサービスを再起動します。
systemctl restart nginx
systemctl restart php-fpm以下のコマンドでNginxのステータスを確認することもできます。
systemctl status nginx次のような出力が得られるはずです。
? nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
Drop-In: /usr/lib/systemd/system/nginx.service.d
??php-fpm.conf
Active: active (running) since Tue 2020-10-20 09:37:40 EDT; 5min ago
Process: 12864 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Process: 12862 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 12860 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Main PID: 12871 (nginx)
Tasks: 3 (limit: 12523)
Memory: 5.5M
CGroup: /system.slice/nginx.service
??12871 nginx: master process /usr/sbin/nginx
??12872 nginx: worker process
??12873 nginx: worker process
Oct 20 09:37:40 centos systemd[1]: Stopped The nginx HTTP and reverse proxy server.
Oct 20 09:37:40 centos systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 20 09:37:40 centos nginx[12862]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Oct 20 09:37:40 centos nginx[12862]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Oct 20 09:37:40 centos systemd[1]: Started The nginx HTTP and reverse proxy server.SELinuxとファイアウォールの設定
デフォルトでは、SELinuxはCentOS 8で有効になっています。したがって、YOURLSウェブサイト用に設定する必要があります。
以下のコマンドでSELinuxを設定できます。
setsebool httpd_can_network_connect on -P
chcon -R -u system_u -t httpd_sys_rw_content_t -r object_r /var/www/html/YOURLS次に、以下のコマンドでファイアウォールを通過させるためにポート80と443を許可します。
firewall-cmd --permanent --add-service=httpfirewall-cmd --permanent --add-service=https
firewall-cmd --reload完了したら、次のステップに進むことができます。
YOURLSにアクセス
今、ウェブブラウザを開き、URL http://yourls.example.com/adminを使用してYOURLSにアクセスします。次のページが表示されるはずです。

Install YOURLSボタンをクリックします。次のページが表示されるはずです。

“YOURLS Administration Page”をクリックします。YOURLSのログインページが表示されるはずです。

config.phpで定義した管理者のユーザー名とパスワードを入力し、Loginボタンをクリックします。次のページにYOURLSダッシュボードが表示されるはずです。

Let’s Encrypt SSLでYOURLSを保護
次に、YOURLSウェブサイト用にLet’s Encrypt SSLをダウンロードしてインストールするために、Certbotユーティリティをシステムにインストールする必要があります。
以下のコマンドでCertbotクライアントをインストールできます。
wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 0755 /usr/local/bin/certbot-auto次に、以下のコマンドでYOURLSウェブサイト用のSSL証明書を取得してインストールします。
certbot-auto --nginx -d yourls.example.com上記のコマンドは、最初にサーバーに必要な依存関係をすべてインストールします。インストールが完了すると、メールアドレスを提供し、以下のように利用規約に同意するように求められます。
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for yourls.example.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/conf.d/yourls.confHTTPトラフィックをHTTPSにリダイレクトするかどうかを選択します。
Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 22を入力してEnterを押して続行します。インストールが成功裏に完了すると、次の出力が得られるはずです。
Redirecting all traffic on port 80 to ssl in /etc/nginx/conf.d/yourls.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://yourls.example.com
You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=yourls.example.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/yourls.example.com/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/yourls.example.com/privkey.pem
Your cert will expire on 2020-06-11. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again with the "certonly" option. To non-interactively renew *all*
of your certificates, run "certbot-auto renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-leこれで、URL https://yourls.example.comを使用してYOURLSウェブサイトに安全にアクセスできるようになりました。
結論
おめでとうございます!CentOS 8にNginxとLet’s Encrypt SSLを使用してYOURLSを正常にインストールしました。これで、YOURLSを使用して自分自身のURL短縮サービスを簡単にホストできます。質問があればお気軽にお尋ねください。
新しい投稿を受信箱で受け取る
スパムはありません。いつでも購読を解除できます。