LoginSignup
3
3

More than 3 years have passed since last update.

【開発環境構築】誰でもお手軽LAMP環境Scotch-box 3.5 使ってみる

Last updated at Posted at 2019-06-27

「ローカルにLAMP環境を勉強用に用意したいけどまた1から作るのめんどくさいなー」
ポチポチ

【ラクしてLAMPとかの環境を用意したい人のためのScotch Box】
https://qiita.com/naru0504/items/a14681b030816135b868?sb2

【ラクして環境構築するためのScotch-Boxが2.0になってかなり進化してた。】
https://qiita.com/naru0504/items/560a150943d2251e1ae8

「LAMP環境をラクに用意したいとか思っていたら、いいものを見つけました。」

調べてみたところ現在はVersion3.5がリリースされているみたいです。

ということで実際に導入してみました。

前提条件

私のPC環境

$ sw_vers
ProductName:    Mac OS X
ProductVersion: 10.12.4
BuildVersion:   16E195

Scotch Boxに関して

公式サイト
https://box.scotch.io/
リポジトリ
https://github.com/scotch-io/scotch-box

本文

インストール

公式サイト手順どおりやっていきましょう。

$ cd [インストールしたいディレクトリ]
$ git clone https://github.com/scotch-io/scotch-box.git
$ cd scotch-box
$ vagrant up
    ...
    default: Guest Additions Version: 5.1.21
    default: VirtualBox Version: 5.2
==> default: [vagrant-hostsupdater] Checking for host entries
==> default: [vagrant-hostsupdater] Writing the following entries to (/etc/hosts)
==> default: [vagrant-hostsupdater]   192.168.33.10  scotchbox  # VAGRANT: c545e317eb29acab529f8d8c2d591bb2 (default) / 10c73402-26f2-42d6-98a2-a122365b9dd3
==> default: [vagrant-hostsupdater] This operation requires administrative access. You may skip it by manually adding equivalent entries to the hosts file.
# PCのパスワードを入力
Password:

インストール終わったら  
下記URLにアクセス
http://192.168.33.10/

image01.jpg

TOPページが表示されましたね。

SSHログインしてみよう

$ vagrant ssh
...
MMMMMMMMMMMMMMMXl.:kXNWMMMMMMMMMMMMMMWWXOc.cXMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMXx:;;:clooddddddddoolc:;;:dKWMMMMMMMMMMMMMMM
MMMMMMMMMMMMMMMMMWXOdl:;,,.........,;:cdkXWMMMMMMMMMMMMMMMMM
  ______                      _        ______                ______
 / _____)            _       | |      (____  \              (_____ \
( (____   ____ ___ _| |_ ____| |__     ____)  ) ___ _   _    _____) )___ ___
 \____ \ / ___) _ (_   _) ___)  _ \   |  __  ( / _ ( \ / )  |  ____/ ___) _ \
 _____) | (__| |_| || |( (___| | | |  | |__)  ) |_| ) X (   | |   | |  | |_| |
(______/ \____)___/  \__)____)_| |_|  |______/ \___(_/ \_)  |_|   |_|   \___/

For help, please visit box.scotch.io or scotch.io. Follow us on Twitter @scotch_io and @whatnicktweets.

Last login: Wed May 31 01:25:33 2017 from 10.0.2.2
$ 

sshでログインできました。
LAMP環境構成されているか確認してみよう。


# OS
$ cat /etc/issue
Ubuntu 16.04.2 LTS \n \l

# Apache
$ apachectl -v
Server version: Apache/2.4.18 (Ubuntu)
Server built:   2017-05-05T16:32:00

# PHP
$ php -v
PHP 7.0.18-0ubuntu0.16.04.1 (cli) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.18-0ubuntu0.16.04.1, Copyright (c) 1999-2017, by Zend Technologies

# MySQL
$ mysql --version
mysql  Ver 14.14 Distrib 5.7.18, for Linux (x86_64) using  EditLine wrapper

全部入ってる!!!

ドキュメントルートを設定しよう

/etc/apache2/sites-available/000-default.conf
の設定を書き得えればいいみたい

念の為デフォルト設定をコピー

$ cp 000-default.conf 000-default_origin.conf

000-default.confを編集

$ sudo vim 000-default.conf
<VirtualHost *80:>  
    ServerAdmin webmaster@localhost  
    DocumentRoot /var/www/public  
    ErrorLog ${APACHE_LOG_DIR}/error.log  
    CustomLog ${APACHE_LOG_DIR}/access.log combined  
    <Directory "/var/www/public">  
        Options Indexes FollowSymLinks  
        AllowOverride all  
        Require all granted  
    </Directory>  
</VirtualHost>  

↓↓↓

<VirtualHost *80:>    
    ServerAdmin webmaster@localhost  
    DocumentRoot /var/www/html  
    ErrorLog ${APACHE_LOG_DIR}/error.log  
    CustomLog ${APACHE_LOG_DIR}/access.log combined  
    <Directory "/var/www/html">  
        Options Indexes FollowSymLinks  
        AllowOverride all  
        Require all granted  
    </Directory>  
</VirtualHost>  

Apacheを再起動しましょう

# シンタックスチェック
$ apachectl configtest
Syntax OK
# Apacheリスタート
$ sudo service apache2 restart

試しにHTMLを配置してあげましょう。

$ cd /var/www/
$ sudo mkdir html
$ cd html
# 最初からvimも入ってる!
$ vim index.html

Hello World
~                                  
"index.html" 1L, 12C  

:wqで保存後
http://192.168.33.10/
にアクセスするとHello Worldが表示されると思います。

初期画面はどこにいったの?

あくまで一例ですが僕は

# 名前を変更  
$ mv /var/www/public/index.php /var/www/public/doc.php  
# ファイルを移動  
$ mv /var/www/public/index.php /var/www/public/doc.php /var/www/html/  

http://192.168.33.10/doc.php
に移動させました。
他にもポート開けてあげるとかの方法はあると思います。

synced_folderについて

公式のVagrantfileで既にsynced_folderが適応されているので

config.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"] 

ホスト側から編集してもリアルタイムで反映されてると思います。

最後に

WEB界隈は開発環境構築が簡単と聞きますが躓く人も多々いると思うのでお役に立てたら光栄です。
Scotch-boxBOXを使用しないVarant環境構築方法は別記事で書こうとは思ってます。
タイポや嘘が紛れてたら指摘頂けると幸いです。
お読み頂きありがとうございました。

参考記事

【ラクしてLAMPとかの環境を用意したい人のためのScotch Box】
https://qiita.com/naru0504/items/a14681b030816135b868?sb2

【ラクして環境構築するためのScotch-Boxが2.0になってかなり進化してた。】
https://qiita.com/naru0504/items/560a150943d2251e1ae8

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