LoginSignup
18

More than 5 years have passed since last update.

Mac 上で Vagrant を使って CentOS6 + nginx + PHP5.5 をセットアップ

Posted at

nginx と PHP5 を利用したく、Vagrant ではありますが環境構築しましたので、メモしておきます。

※ 下記記事の焼き直しです。
http://qiita.com/hmukaida/items/8836a96ce5cbe88019b7

参考

Vagrant体験入門ハンズオン手順 - 2014/04/24 DevLove関西

事前準備

  • 上記の参考より、VirtualBox と Vagrant をインストールしてください。

Vagrant 基本セットアップ

自分の環境でのメモ踏まえて記載してまいります。
OS は CentOS6.5を採用します。まずはディレクトリを作成して、対象の box を追加します。

$ mkdir CentOS65
$ cd centOS65
$ vagrant box add CentOS65 https://github.com/2creatives/vagrant-centos/releases/download/v6.5.3/centos65-x86_64-20140116.box

ここで box の list を確認します。「CentOS65」あります。

$ vagrant box list
CentOS65 (virtualbox, 0)

次に初期設定にて Vagrantfile を生成します。

$ vagrant init CentOS65
$ ls
Vagrantfile

Shell を使って各種インストール

ここで Vagrantfile を編集します。

  • 1) yum update
  • 2) NTP 設定
  • 3)timezone 設定
  • 4)nginx for centos6 インストール
  • 5)php5.5 インストール
  # SHELL
  config.vm.provision "shell", inline: <<-EOT
        # 1) yum update
        sudo yum -y update

        # 2) NTP
        sudo yum -y install ntp
        cp -a /vagrant/ntp.conf /etc/ntp.conf
        /sbin/service ntpd restart
        /sbin/chkconfig ntpd on

        # 3)timezone
        cp -p /usr/share/zoneinfo/Japan /etc/localtime
        # iptables off
        /sbin/iptables -F
        /sbin/service iptables stop
        /sbin/chkconfig iptables off

        # 4)nginx for centos6
        rpm -ivh http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
        sudo yum -y install nginx
        cp -a /vagrant/default.conf /etc/nginx/conf.d/default.conf
        /sbin/service nginx restart
        /sbin/chkconfig nginx on

        # 5)php5.5
        sudo rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
        sudo rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
        sudo yum -y install php php-pdo php-mysql php-mbstring php-xml --enablerepo=remi-php55

  EOT

/vagrant/ntp.conf

ntp.conf は下記の通り変更しています。

server -4 ntp.nict.jp
server -4 ntp1.jst.mfeed.ad.jp
server -4 ntp2.jst.mfeed.ad.jp
server -4 ntp3.jst.mfeed.ad.jp

/vagrant/default.conf

nginx の conf ファイルはまだ変更していませんが、ここにオリジナルの設定を記載しておきます。

仮想環境再起動

$ vagrant reload

プロビジョニングを実施します。

$ vagrant provision

ブラウザで http://192.168.33.10にアクセスし、nginx の Welcome ページが表示されれば成功です。

$ open http://192.168.33.10

動作検証が甘いですが、加筆修正あれば随時致します。

参考2

インストール面では下記参考にさせていただきました。ありがとうございました。

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
18