11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Vagrant+ubuntu14.04にLaravel環境を構築する

Posted at

Vagrant + VirtualBox(ubuntu14.04)にLaravel環境を構築した時のメモ

Host環境

Mac OS X 10.9.5
Vagrant 1.6.3
VirtualBox 4.3.12

Guest環境

ubuntu14.04(trusty64)
php 5.5
mysql 5.6
nginx 1.4.6
laravel 4.2.0

仮想マシン構築

仮想マシン初期化

host $ vagrant box add ubuntu/trusty64
host $ cd /path/to/example
host $ vagrant init

VagrantFileを編集する

VagrantFile
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  ...
  config.vm.box = "ubuntu/trusty64"
  ...
  config.vm.network "private_network", ip: "192.168.33.10"
  ...
  # Laravel4でapp/storageにアクセス権限を与えるために777にする
  config.vm.synced_folder "./", "/vagrant", {:mount_options => ['dmode=777','fmode=777']}
  ...
  # mysql5.6のインストールでメモリが必要なのでメモリを確保
  config.vm.provider "virtualbox" do |vb|
    vb.customize ["modifyvm", :id, "--memory", 1024]
  end
  ...
end

仮想マシン起動

host $ vagrant up

sshするとWarningが出力される

_____________________________________________________________________
WARNING! Your environment specifies an invalid locale.
 This can affect your user experience significantly, including the
 ability to manage packages. You may install the locales by running:

   sudo apt-get install language-pack-ja
     or
   sudo locale-gen ja_JP.UTF-8

To see all available language packs, run:
   apt-cache search "^language-pack-[a-z][a-z]$"
To disable this message for all users, run:
   sudo touch /var/lib/cloud/instance/locale-check.skip
_____________________________________________________________________

言われるままにインストールする

guest $ sudo apt-get install language-pack-ja

php5.5のインストール

php5.5のリポジトリを取得

  • Nginxでphpを動かすためにphp5-fpm
  • Mysqlと接続するのでphp5-mysql
  • Laravelで必要なphp5-mcrypt

をそれぞれインストール

guest $ sudo add-apt-repository ppa:ondrej/php5
guest $ sudo apt-get update
guest $ sudo apt-get install php5-fpm php5-mysql php5-mcrypt

バージョン確認

guest $ php -v
PHP 5.5.17-1+deb.sury.org~trusty+1 (cli) (built: Sep 19 2014 11:27:38) 
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
    with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2014, by Zend Technologies

mysql5.6のインストール

guest $ sudo apt-get install mysql-server-5.6

途中パスワードを聞かれるので適当に。
ここではパスワードを空で進める。

バージョン確認

guest $ mysql -uroot -p
Enter password: #空
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 44
Server version: 5.6.19-0ubuntu0.14.04.1 (Ubuntu)
...

nginxのインストール

guest $ sudo apt-get install nginx

バージョン確認

guest $ nginx -v
nginx version: nginx/1.4.6 (Ubuntu)

Laravelのインストール

Laravel4をComposerでインストールする

Composerのインストール

guest $ curl -sS https://getcomposer.org/installer | php
guest $ sudo mv composer.phar /usr/local/bin/composer

Laravelをインストール

guest $ cd /vagrant
guest $ composer create-project laravel/laravel --prefer-dist

nginxにドキュメントルートを設定

Laravel4をNginxで動かすより引用

guest $ sudo vim /etc/nginx/sites-enabled/default
default
server {
        listen 80 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /vagrant/laravel/public;

        # Make site accessible from http://localhost/
        server_name localhost;

        # 末尾のスラッシュの削除
        rewrite ^(.+)/$ $1;

        location / {
                try_files $uri /index.php?$query_string;
        }

        location ~ ^/index.php$ {
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            fastcgi_split_path_info ^(.+\.php)(.+)$;
            fastcgi_pass unix:/var/run/php5-fpm.sock;
            fastcgi_index index.php;
        }

        location ~ /\.ht {
                deny all;
        }
}

nginxを再起動

guest $ sudo service nginx restart

画面確認をする

以下のURLにアクセス
http://192.168.33.10/

Done!!
簡単ですね。

11
12
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
11
12

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?