VirtualBox上にWeb開発環境を作る
参考書籍
小笠原 種高. ゼロからわかる Linux Webサーバー超入門[Apache HTTP Server対応版]
VirtualBox,CentOSインストール
参考書籍の『CHAPTER 2 サーバーを構築しよう』に従って下記を実施
- VirtualBoxのダウンロード
- VirtualBoxのインストール
- CentOS7 のイメージ の ダウンロード
- 仮想マシン(仮想コンピューター)の作成
- CentOS7のインストール
結果
1~5まで書籍通りでOK
参考
VirtualBoxのダウンロードサイト
VirtualBox:VirtualBox-6.1.16-140961-Win.exe
CentOS7のイメージのダウンロードサイト
Centos:CentOS-8.2.2004-x86_64-dvd1.iso
apacheインストールしてブラウザアクセス出来るようにする
yumを使ってapacheをインストール
yum install httpd
インストール時の問題(1)
yum install httpd
下記アラームが発生
could not retrieve mirrorlist http //mirrorlist.centos.org/
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
下記を参考にDNSとGATEWAYを設定
VirtualBoxのCentOS7で yum install したら Could not retrieve mirrorlist となった時の対応方法
インストール時の問題(2)
上記対策後、下記アラームは残ったまま
One of the configured repositories failed (Unknown),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=<repoid> ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable <repoid>
or
subscription-manager repos --disable=<repoid>
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
下記を参考に
Mac + DockerでCentOSを立ち上げたらyumが全く使えなかった話
/etc/yum.repos.d/CentOS-Base.repoの$releaseverを'7'で直書きに変更
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://mirror.centos.org/centos/7/updates/$basearch/
※[base],[updates],[extras]の3か所とも変更実施
正常にインストール完了
Apacheを起動させる
起動コマンド
systemctl start httpd
起動確認コマンド
systemctl status httpd
自動起動させる
systemctl enable httpd
自動起動の確認
systemctl is-enabled httpd
viでhtmlファイルを作成する
systemctl start httpd
systemctl status httpd
systemctl enable httpd
systemctl is-enabled httpd
書籍通りでOK
ファイウォールでポートを開放する
publicゾーンにhttp,httpsを許可
firewall-cmd --zone = public --add-service = http --permanent
firewall-cmd --zone = public --add-service = https --permanent
リロード
firewall-cmd --reload
ipアドレスを確認する
ip a
~~~省略
inet xxx.xxx.xxx.xxx/xx brd xxx.xxx.xxx.255 .....
~~~省略
ipアドレスを使ってブラウザからアクセスする
プラウザに"xxx.xxx.xxx.xxx/index.html"
を入力する
結果
上記で作成したhtmlがただしく表示される
SSHでアクセスする
SSH機能をサーバーにインストール
標準インストールでSSHがインストールされているので作業不要
SSHクライアント(TeraTerm)のインストール
書籍通りで問題なし
Filezilaでのファイルやりとり
※参考書籍はWinSCPを使っているがここでは既にインストールされているFilezilaを使って接続する
<ファイル>⇒<サイトマネージャー>⇒<新しいサイト>を選択
- プロトコル:SFTP
- ホスト:上記で調べたIPアドレスを設定
- ログオンタイプ:パスワードを尋ねる
- ユーザー:root
PHP環境を構築する
インストール
yum install php
Apache再起動
yum install php
設定を反映させるため
'''shell
systemctl restart httpd
```
※書籍はyum restart httpdになっているが誤記
PHPファイルブラウザで確認
- PHPファイルを"/var/www/html"かに作成する
- ブラウザで確認する
結果
ただしく表示された
課題
バージョンが5系なので7系を使用する方法を確認する
参考
CentOS7のPHPを5.6/7.0/7.1/7.2/7.3系にバージョンアップする
SQLサーバーを構築する
参考
Author And Source
この問題について(VirtualBox上にWeb開発環境を作る), 我々は、より多くの情報をここで見つけました https://qiita.com/Stchan/items/acc4a4cfe3c1ffd5fc8f著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .