LoginSignup
0
0

More than 1 year has passed since last update.

ConoHa VPSで複数サイト(今回はlaravel )を管理する

Posted at

ConoHaで複数サイトを管理する手順

初めに

既にVPSサーバーを持っているので他のサーバーを借りるとお金がかかるのでポート番号を解放して公開したい
スクールでやったけど言われるがままだったので改めて学習。今回はLaravelのプロジェクトを公開したい。
全体的に以下記事を参考
https://qiita.com/ChairoHack/items/06a2e1357b646acb41c7

ポートを解放

ssh root@kazpp.com
#ssh接続

cd /etc/httpd/conf
vi httpd.conf
#ポート番号の8081を今回対象にしたいので以下の内容を追加

Listen 8081
<VirtualHost *:8081>
 ServerName 118.27.14.189
 DocumentRoot /home/kazuki/laravelpractice
 ErrorLog "logs/wordpress.com-error_log"
 CustomLog "logs/wordpress.com-access_log" common
<Directory "/home/kazuki/laravelpractice">
 Require all granted
</Directory>
</VirtualHost>

# ポート8081を解放
firewall-cmd --zone=public --add-port=8081/tcp --permanent
#️ リロード
firewall-cmd --reload
#ポートが解放されたか確認
firewall-cmd --list-all

public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: dhcpv6-client http ssh
  ports: 8080/tcp 8081/tcp          👈8081が存在することを確認
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

#プロジェクトを置くディレクトリを作成
mkdir /home/kazuki/laravelpractice
#サイトが表示されるかテスト
touch /home/kazuki/laravelpractice/test.php
#念のため、一般ユーザーへ切り替え
su kazuki
#Apacheの再起動
systemctl restart httpd

参考:https://qiita.com/inakadegaebal/items/14b2884389712e89b4a6

composerのインストール

# Composerのインストーラーをダウンロード
[root@ ~]sudo wget https://getcomposer.org/installer -O composer-installer.php
# Composerのインストール
[root@ ~]php composer-installer.php --filename=composer --install-dir=/usr/local/bin
# Composerのアップデート
[root@ ~]composer self-update
# Composerのバージョンの確認
[root@ ~]composer --version
Composer version 2.2.4 2022-01-08 12:30:42

公開サーバにGitをダウンロード

CentOSのサーバにGitを導入する時の備忘録。yum install git で入る Git は少し古いので、新しいバージョンを入れる方法を記載

依存関係があるライブラリ(curl、zlib、openssl、expat、libiconv あたり)を導入する

sudo yum -y install gcc curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-ExtUtils-MakeMaker autoconf

yumからインストールする場合、インストール可能なGitのバーションを確認する。デフォルトのyumのデフォルトのレポジトリではバーションが古いのでiusレポジトリを一時的に使用する。

[root@ ~]vi /etc/yum.repos.d/ius.repo
# [ius]
# name = IUS for Enterprise Linux 7 - $basearch
# baseurl = https://repo.ius.io/7/$basearch/
# enabled = 1
# repo_gpgcheck = 0
# gpgcheck = 1
# gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

# [ius-debuginfo]
# name = IUS for Enterprise Linux 7 - $basearch - Debug
# baseurl = https://repo.ius.io/7/$basearch/debug/
# enabled = 0
# repo_gpgcheck = 0
# gpgcheck = 1
# gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

# [ius-source]
# name = IUS for Enterprise Linux 7 - Source
# baseurl = https://repo.ius.io/7/src/
# enabled = 0
# ↑0であることを確認
# repo_gpgcheck = 0
# gpgcheck = 1
# gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-IUS-7

# 可能なGitのバージョンを確認
[root@ ~]# yum list --enablerepo=ius | grep git2
# git224.x86_64                            2.24.4-1.el7.ius         @ius
# git224-core.x86_64                       2.24.4-1.el7.ius         @ius
# git224-core-doc.noarch                   2.24.4-1.el7.ius         @ius
# git224-perl-Git.noarch                   2.24.4-1.el7.ius         @ius
# bluez-tools.x86_64                       0.2.0-0.7.git20170912.7cb788c.el7
# bluez-tools-debuginfo.x86_64             0.2.0-0.7.git20170912.7cb788c.el7

# Gitをダウンロード
[root@ ~]# yum -y install --enablerepo=ius git224
[root@ ~]# git --version
git version 2.24.4

GitへSSH接続するようにする

このままgit cloneすると以下のようなエラーが発生する

[kazuki@ laravelpractice]$ git clone https://github.com/■/laravelpractice.git
fatal: could not create work tree dir 'laravelpractice': 許可がありません
[kazuki@ ~]$ ssh -T git@github.com
The authenticity of host 'github.com (52.69.186.44)' can't be established.
ECDSA key fingerprint is SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM.
ECDSA key fingerprint is MD5:7b:99:81:1e:4c:91:a5:0d:5a:2e:2e:80:13:3f:24:ca.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'github.com,52.69.186.44' (ECDSA) to the list of known hosts.
Permission denied (publickey).

サーバ上でGitHubを使えるようにするためには、GitHubと本番サーバがSSH接続できるように設定しないといけない。
秘密鍵・公開鍵を作成する。

[kazuki@ ~]$ cd .ssh
# 秘密鍵・公開鍵の作成を行う
[kazuki@ ~]$ ssh-keygen -m pem
# 以下enter連打
Generating public/private rsa key pair.
Enter file in which to save the key (/home/kazuki/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/kazuki/.ssh/id_rsa.
Your public key has been saved in /home/kazuki/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:ylUI/765qmMHMAqmK3c01M6kHQl9VmhdFHo3enCUIS0 kazuki@

# 公開キーを確認
[kazuki@ ~]$ cat ~/.ssh/id_rsa.pub

# 以下ファイルに転記
[kazuki@ ~]$ vi ~/.ssh/authorized_keys
[kazuki@ ~]$ cat ~/.ssh/authorized_keys

ここまでできたらGitHubに公開鍵を登録する。
GitHub 右上のプロフィール画像をクリックして「Settings 」メニューを開いて「SSH and GPD keys」メニューを開くと「New SSH Key」ボタンがあるのでクリック。その画面で先ほど公開鍵 (id_rsa.pub) の文字列を登録

# 再度SSH接続できるかチェック
[kazuki@ ~]$ ssh -T git@github.com
Warning: Permanently added the ECDSA host key for IP address '13.114.40.48' to the list of known hosts.
Hi ■! You've successfully authenticated, but GitHub does not provide shell access.

再度git cloneしたがまた怒られた
sh
[kazuki@ ~]$ git clone https://github.com/■/laravelpractice.git
Cloning into 'laravelpractice'...
Username for 'https://github.com': ■
Password for 'https://■@github.com':
remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.
fatal: Authentication failed for 'https://github.com/■/laravelpractice.git/'

アクセストークンの設定をする必要があるようなので設定。
GitHub 右上のプロフィール画像をクリックして「Settings 」メニューを開いて「Developer settings」メニューを開くと「Personal access tokens」ボタンがあるのでクリックしてアクセストークンを取得。アクセストークンを以下のようにURLに組み込んで再度clone

[kazuki@ ~]$ git clone https://[アクセストークン]@github.com/■/laravelpractice.git
Cloning into 'laravelpractice'...
remote: Enumerating objects: 323, done.
remote: Counting objects: 100% (323/323), done.
remote: Compressing objects: 100% (259/259), done.
remote: Total 323 (delta 43), reused 323 (delta 43), pack-reused 0
Receiving objects: 100% (323/323), 646.85 KiB | 9.95 MiB/s, done.
Resolving deltas: 100% (43/43), done.
[kazuki@ ~]$ ls
composer-installer.php  laravelpractice  portfolio

laravelプロジェクト公開の下準備

0
0
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
0
0