LoginSignup
1
1

More than 5 years have passed since last update.

自前でlaravelの環境構築 vagrant+php7+ubuntu14+mysql+apache2.4+elasticsearchとかとか

Last updated at Posted at 2016-12-14

laravelの環境構築いつもいろんなサイト調べてからちまちまコマンド入力するのめんどくさいのでまとめました。

vagrant

以下のubuntu14を使います。

vagrant box add ubuntu14 https://cloud-images.ubuntu.com/vagrant/trusty/current/trusty-server-cloudimg-amd64-vagrant-disk1.box

vagrant init ubuntu14

vagrant up

Failed to mount folders in Linux guest. This is usually because
the "vboxsf" file system is not available. Please verify that
the guest additions are properly installed in the guest and
can work properly. The command attempted was:

mount -t vboxsf -o uid=`id -u vagrant`,gid=`getent group vagrant | cut -d: -f3` vagrant /vagrant
mount -t vboxsf -o uid=`id -u vagrant`,gid=`id -g vagrant` vagrant /vagrant

The error output from the last command was:

stdin: is not a tty

このエラーメッセージが出たら

vagrant plugin install vagrant-vbguest という風にプラグインを入れてあげて下さい。

vagrant ssh

ユーザー権限移行

sudo su -

apt-getの更新

apt-get -y update

apache入れる

apt-get install python-software-properties
apt-get update
apt-add-repository ppa:ondrej/apache2
パッケージを更新
apt-get -y update
apt-get -y install apache2

php7入れる

(ubutu ver 15.04だとサポートされていないようです)
apt-add-repository ppa:ondrej/php
apt-get -y update
apt-get -y install php7.0
apt-get -y install php7.0-mysql php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-intl

php7でインストール可能なライブラリは以下のコマンドで確認出来ます。
sudo apt-cache search php7-*

mysql入れる

apt-get install mysql-server

redis入れる

add-apt-repository -y ppa:chris-lea/redis-server
apt-get -y update
apt-get -y install redis-server

composer 入れる

curl入れる

apt-get install curl
curl -sS https://getcomposer.org/installer | php

git入れる

add-apt-repository ppa:git-core/ppa
apt-get install git
git version

vagrant 共有設定

ゲスト側のvagrantというディレクトリがデフォルトで共有されているので
一旦rm -rf /var/www/htmlで削除してやってから
ln -fs /vagrant /var/www/html
ln -fs /vagrant/laravel/ var/www/
とする

apache設定

(hogeweb-siteは変更して下さい)
composer create-project laravel/laravel /var/www/hogeweb-site/ –prefer-dist

/var/www/hogeweb-site にプロジェクトが作成されます。

vi /etc/httpd/conf.d/hogeweb-site.conf

<VirtualHost *:80>
        ServerName myapp.com
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/hogeweb-site/public

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <Directory "/var/www/hogeweb-site/public">
                AllowOverride All
        </Directory>
</VirtualHost>

httpd.confにServerNameを設定する。

vi /etc/httpd/conf/httpd.conf

Apacheの実行ユーザを変更する

Vagrant上で開発している場合は、Apacheの実行ユーザをvagrantに変更します。Ubuntu14のApacheにはenvvarsというファイルで実行ユーザを変更できます。envvarsは環境変数を管理するファイルのようです。

$ sudo vi /etc/apache2/envvars
envvarsを以下のとおり変更します。

export APACHE_RUN_USER=vagrant
export APACHE_RUN_GROUP=vagrant

ここまでほぼ自動でやってくれるhomesteadさんやっぱ神ですわ

elasticsearch入れる

add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java7-installer
update-rc.d elasticsearch defaults 95 10
apt-get install elasticsearch=2.1.1
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
これで反応確かめる
curl 'http://localhost:9200/_nodes/process?pretty'

これitamaeとかに記述しておきたい
毎回やるのめんどいし笑

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