GNU/Linux >> Linux の 問題 >  >> Cent OS

CentOS8にYOURLSセルフホストURL短縮サービスをインストールする方法

YOURLSは、PHPで記述された無料のオープンソースのセルフホストURL短縮サービスです。 TinyURLやBitlyと非常によく似ており、独自のURL短縮サービスを実行できます。また、短いURLにブランドを追加することもできます。プライベートリンクとパブリックリンク、カスタムURLキーワード、履歴クリックレポート、Ajaxedインターフェース、Jsonpサポートなど、豊富な機能セットを提供します。

このチュートリアルでは、Let'sEncryptSSLを使用してCentOS8にYOURLSをインストールする方法を示します。

前提条件
  • CentOS8を実行しているサーバー。
  • サーバーIPで指定された有効なドメイン名。
  • ルートパスワードがサーバーに設定されます。

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のデータベースとユーザーを作成する必要があります。まず、次のコマンドを使用して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 Webルートに変更し、次のコマンドを使用して最新バージョンの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 database username */
define( 'YOURLS_DB_USER', 'yourlsuser' );
 
/** MySQL database password */
define( 'YOURLS_DB_PASS', 'password' );
 
/** The name of the database for YOURLS
 ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */
define( 'YOURLS_DB_NAME', 'yourlsdb' );
 
/** MySQL hostname.
 ** If using a non standard port, specify it like 'hostname:port', eg. 'localhost:9999' or '127.0.0.1:666' */
define( 'YOURLS_DB_HOST', 'localhost' );
 
/** MySQL tables prefix
 ** YOURLS will create tables using this prefix (eg `yourls_url`, `yourls_options`, ...)
 ** Use lower case letters [a-z], digits [0-9] and underscores [_] only */
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

次の行を追加します:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /yourls-loader.php [L]
</IfModule>

ファイルを保存して閉じてから、次のコマンドを使用して適切な権限と所有権を付与します。

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で有効になっているため、YOURLSWebサイト用に構成する必要があります。

次のコマンドで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=http
firewall-cmd --permanent --add-service=https
firewall-cmd --reload

完了したら、次のステップに進むことができます。

あなたにアクセス

次に、Webブラウザーを開き、URLhttp://yourls.example.com/adminを使用してYOURLSにアクセスします。次のページが表示されます:

YOURLSのインストールをクリックします ボタン。次のページが表示されます:

YOURLS管理ページ」をなめる 」。 YOURLSログインページが表示されます:

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

SSLを暗号化してLet'sでYOURLSを保護

次に、システムにCertbotユーティリティをインストールして、YOURLSWebサイト用のLet'sEncryptSSLをダウンロードしてインストールする必要があります。

次のコマンドを使用して、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

次に、次のコマンドを使用して、YOURLSWebサイトの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.conf

以下に示すように、HTTPトラフィックを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): 2

2と入力し、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

これで、URLhttps://yourls.example.comを使用してYOURLSWebサイトに安全にアクセスできます。

結論

おめでとう!これで、CentOS8にNginxとLet'sEncrypt SSLを使用してYOURLSを正常にインストールできました。これで、YOURLSを使用して独自のURL短縮サービスを簡単にホストできます。ご不明な点がございましたら、お気軽にお問い合わせください。


Cent OS
  1. CentOS7にXWikiをインストールする方法

  2. Ubuntu20.04にYOURLSURL短縮サービスをインストールする方法

  3. CentOS6にNginxをインストールします

  1. CentOS8にMongoDBをインストールする方法

  2. CentOS7にNginxをインストールする方法

  3. CentOS8にNginxをインストールする方法

  1. CentOS7にMagento2.1をインストールする方法

  2. CentOS7にStreamaをインストールする方法

  3. CentOS7にRestyaboardをインストールする方法