LoginSignup
2
1

More than 5 years have passed since last update.

Vagrant環境のCentOSにLaravelをインストール

Last updated at Posted at 2018-05-10

はじめに

このドキュメントでは、Laravelのインストールドキュメントに従ってインストールするための準備について記述しています。

Laravel
https://readouble.com/laravel/

準備

composerをインストール

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '544e09ee996cdf60ece3804abc52599c22b1f40f4323403c44d44fdfdd586475ca9813a858088ffbc1f233e9b180f061') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

実行したディレクトリにcomposer.pharが作成されるので/usr/bin/composerとして移動します。
パスが通っているのでコマンドが実行できるようになります。

$ composer [command]

php-zipをインストール

以下のエラーが出る場合はPHPバージョンに応じてリポジトリを指定してインストールします。

Problem 1
- laravel/installer v2.0.1 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- laravel/installer v2.0.0 requires ext-zip * -> the requested PHP extension zip is missing from your system.
- Installation request for laravel/installer ^2.0 -> satisfiable by laravel/installer[v2.0.0, v2.0.1].

$ sudo yum -y install --enablerepo=remi --enablerepo=remi-php71 php-zip

Laravelをインストール

$ composer global require "laravel/installer"

Laravelのパス設定

$ vi ~/.bash_profile

# パスを追加して保存します
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$HOME/.config/composer/vendor/bin/

# 再読み込みして設定を反映します
$ source ~/.bash_profile

以上で完了です。

補足

もしプロジェクトの作成で以下のようなエラーが出たときは、

$ laravel new blog

Problem 1
- Installation request for phar-io/manifest 1.0.1 -> satisfiable by phar-io/manifest[1.0.1].
- phar-io/manifest 1.0.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 2
- Installation request for phpunit/php-code-coverage 6.0.4 -> satisfiable by phpunit/php-code-coverage[6.0.4].
- phpunit/php-code-coverage 6.0.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 3
- Installation request for phpunit/phpunit 7.1.5 -> satisfiable by phpunit/phpunit[7.1.5].
- phpunit/phpunit 7.1.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
Problem 4
- Installation request for theseer/tokenizer 1.1.0 -> satisfiable by theseer/tokenizer[1.1.0].
- theseer/tokenizer 1.1.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.

php-domをインストールします。

$ sudo yum -y install --enablerepo=remi --enablerepo=remi-php71 php-dom

migrate for MySQL

$ php artisan migrate

migrateを実行する際、Laravelのデフォルト設定がutf8mb4の文字コードになっているので以下のエラーが発生した場合はMySQLの設定を行う必要があります。

SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes

対応方法は下記を参照してください。

LaravelでMysqlのcharsetをutf8mb4にしてエラーが出るときの対応方法

エラーにより不完全に実行された場合、migrationsテーブルに実行履歴が残らず再度実行した際にテーブルが作成済みであるエラーなどが起こるので、その場合は手動で変更を戻し(テーブルの削除などを行ってから)実行します。

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