1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

久々にさくらVPSにwordpress乗っけてみる

Last updated at Posted at 2020-07-24

概要

潰していたさくらVPSが、気付いたら1年も経過!!
課金されておりました(>_<)
さて、この1年雪犬は何をしていたのでしょうか?笑


知識があまりない方へ注意
私は全くサーバの知識も深くありませんので、やっている事がセキュリティ甘い!!とプロの方は感じている可能性がございますので、あしからず><
こちらのサイトなどを参考に書かせていただきます。


と、いう事で、今回は初心者にだって出来る!方法で行こうかな。と!

OSインストール

  1. さくらコンパネへログインし、「標準OS」の「CentOS8 x85_64」を選択
    image.png

  2. パスワードを入力
    ここで入力するパスワードはrootパスワードと言って、超大切なパスワードになります。
    パスワードジェネレーターなどを使って、設定しておきます。
    ★ただし、さくらVPSで使える記号が限られているので注意。

  3. 「スタートアップスクリプト」で「Wordpress」を選択し、「設定内容を確認する」
    image.png

サーバの設定

# hostnamectl set-hostname [サーバー名]
# dnf update
  1. サーバー名の変更
  2. サーバのアップデート

★ブラウザから、IPアドレスで接続すればwordpressのインストール画面に飛べるよ!

SSH を有効化する

1.起動されたら、「コンソール」のどちらで良いので開き、ログインする
login: rootと入力し、Enterキーを押す
次の行で、先程設定したrootパスワードを入力し、Enterキーを押す。
★黒い画面でビビらない。

2.ユーザの作成

# useradd ユーザー名
# passwd ユーザー名

★同じユーザー名を入力する事
New password: と聞かれるので、入力する。
入力しても何も変化ないので、気をつけて!

3.管理者権限をあげる
# visudoでファイルを開き、最終行に以下を追加する

ユーザー名  ALL=(ALL)       ALL

★vi は、iで入力開始して、ESCキーで入力終了して、:wqで保存して、:qで閉じます。

4.ssh へのroot でのログインを禁止する設定
# vi /etc/ssh/sshd_configでファイルを開き、PermitRootLogin noを「no」に変更する

5.sshd の再起動
systemctl restart sshd
★firewalld のsshdは既に設定済みのため、ここで設定せず。

6.SSH 出来るので、自分のPCからSSHをする!
Mac ならTerminal を開き、ssh ユーザー名@IPアドレスを入力
その後、英語で言われたらyesと入力し、パスワードを入力聞かれたら、設定したパスワードを入力する。

これでログインが出来る!!

SSL を設定

こちらを参考にしてます。
1.SSL設定ファイルの変更

/etc/httpd/conf.d/ssl.conf
# vi /etc/httpd/conf.d/ssl.conf
DocumentRoot "/var/www/wordpress"
ServerName www.hoge.com:443
SSLCertificateFile /etc/letsencrypt/live/www.hoge.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/www.hoge.com/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/www.hoge.com/chain.pem

2.wordpress の設定ファイルを変更
さくらで作成されたファイルがあるので、[wp-*****.conf]というようなファイルを変更しましょう
ファイル名を変更し、ファイルを編集します。

# mv  vi /etc/httpd/conf.d/wp-123.conf  vi /etc/httpd/conf.d/hoge.com
# vi  vi /etc/httpd/conf.d/hoge.com
<VirtualHost *:80>
 DocumentRoot /var/www/hoge.com
 ServerName www.hoge.com
  RewriteEngine On
  RewriteCond %{HTTPS} off
  RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 AllowEncodedSlashes On
 <Directory />
     Options FollowSymLinks
     AllowOverride None
 </Directory>
 <Directory "/var/www/hoge.com">
    Options FollowSymLinks MultiViews ExecCGI
    AllowOverride All
    Order allow,deny
    allow from all
 </Directory>
</VirtualHost>

こんな感じで設定されていると思いますので、ない部分は追記。
[hoge.com] の部分は自分のドメインにする!

★firewalld は既に有効化され、http/https/ssh などは既に通信可になっている

SSL証明書の取得

こちらを参考にしましたので、こちらのサイトを一読されるのをおすすめします!!
注意: ドメインの設定・サーバ稼働中が前提となります
Let's Encryptを利用します。
★90日間有効になるため、その後再度作業が必要!!

1.証明書を取得するためのツール Certbot クライアントをインストール

# dnf module -y install python36
# dnf -y install gcc mod_ssl python3-virtualenv redhat-rpm-config augeas-libs libffi-devel openssl-devel
# curl -O https://dl.eff.org/certbot-auto
# mv certbot-auto /usr/local/bin/
# chmod 700 /usr/local/bin/certbot-auto

2.証明書を取得
certbot-auto certonly --webroot -w /var/www/[wordpressのあるディレクトリ] -d [自分のドメイン]というふうに指定する。

# certbot-auto certonly --webroot -w /var/www/wp -d www.hoge.com
Enter email address (used for urgent renewal and security notices) 
(Enter 'c' to cancel): root@hoge.com
(A)gree/(C)ancel: A
(Y)es/(N)o: Y
- Congratulations!

Congratulations が見えたら、成功(>ω<)b

最後に、Apacheの再起動 systemctl restart httpdをしてね!

最後に

セキュリティを高めるために こちら などを参考にされると良いかと思います(´・ω・`)

お疲れさまでしたー
ではではでは、雪犬-snowdog-でした!ばーい★

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?