LoginSignup
1
2

More than 5 years have passed since last update.

vagrantでLAMP環境構築する

Last updated at Posted at 2018-07-01

共有ディレクトリ ホスト:~/work/php( ../)   ゲスト:/mnt/project
ドキュメントルート /var/www/html/のままで、この下にシンボリックリンク作成するようにする。

各種バージョン

バージョン
# cat /etc/redhat-release
CentOS release 6.9 (Final)

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

# php -v
PHP 5.6.36 (cli) (built: Apr 25 2018 10:11:47)
Copyright (c) 1997-2016 The PHP Group
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies
    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
    with Xdebug v2.5.5, Copyright (c) 2002-2017, by Derick Rethans

# httpd -v
Server version: Apache/2.2.15 (Unix)
Server built:   Oct 19 2017 16:43:38

# git --version
git version 1.7.1


vagrant upする前

使用するbox
centos/6

vagrant box add centos/6 #これいらないかも?
vagrant init centos/6
Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "centos/6"

  config.vm.network "private_network", ip: "192.168.33.10"

  config.vm.synced_folder "../", "/mnt/project",
  :owner => "vagrant", :group => "vagrant",
  :mount_options => ["dmode=777,fmode=666"]

  config.ssh.insert_key = false

  config.vm.provision :shell, :path => "./provisioning.sh", :privileged => true
end
./provisioning.sh
#!/bin/sh


###
### iptables
###

service iptables stop
chkconfig iptables off


###
### yum
###

yum -y update


###
### date
###

echo -e 'ZONE="Asia/Tokyo"\nUTC=false' > /etc/sysconfig/clock

cp /etc/localtime /etc/localtime.org

ln -sf  /usr/share/zoneinfo/Asia/Tokyo /etc/localtime


###
### mysql 5.6
###

yum -y erase mysql-libs

rpm -ivh http://ftp.riken.jp/Linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm

rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

yum install -y http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm

yum install -y mysql mysql-server mysql-devel



service mysqld start

/usr/bin/mysqladmin -u root password 'root'



###
### php 5.6  +  apache
###

yum install -y --enablerepo=epel libmcrypt libtidy

yum install -y --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof



###
### apache start
###

service httpd start

chkconfig httpd on


###
### git
###

yum install -y git-all


###
### link
###


mkdir /mnt/project/lesson
ln -fs /mnt/project/lesson /var/www/html/lesson

echo '<?php phpinfo();' > /var/www/html/index.php
echo 'hellolesson!' > /mnt/project/lesson/index.php

このままだと、puttyでログインする際うまくいかないので、これやっとく。
Vagrantで立てたVMにSSHするまで (Windows)


SELinuxの変更

ApacheのドキュメントルートをVagrantの共有フォルダにすると403 Forbiddenになる


AllowOverride None を AllowOverride All に変更

Fuelやるときは必要っぽい(そうじゃなければやらないくてよいかな?)
Windows で、vagrant を利用した FuelPHP 用 LAMP 環境構築
Vagrantで.htaccessファイルを有効にする設定


シンボリックリンク作成されてる場所

# 練習用
/mnt/project/lesson


php.ini変更

FW関係なしに、基本的なとこ

/etc/index.ini
;バッファリングのなんか
output_buffering=4096

error_reporting=E_ALL & ~E_NOTICE

default_charset="UTF-8"

date.timezone=Asia/Tokyo

session.use_only_cookies=On (1でよさそうだけど)

確認

1
2
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
2