LoginSignup
8
8

More than 5 years have passed since last update.

Laravel5.2をインストールする手順とハマったとこ

Last updated at Posted at 2016-08-10

環境

nginx 1.10系
php 7.0.9
Laravel 5.2

導入時にハマった所

今回はインストールする際に、Laravelのドキュメントに則ってインストールしてみようと思ってインストールします。
https://laravel.com/docs/5.2/installation

composerのインストール

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

$ sudo mv composer.phar /usr/local/bin/composer

Laravelコマンドをcomposerでインストールする。


$ cd '.composerがあるディレクトリ'
$ composer global require "laravel/installer"

$ cd 'プロジェクトを作成したいディレクトリ'
$ ~/.composer/vendor/bin/laravel new AppName

# エラー発生
[RuntimeException]                                                       
The Zip PHP extension is not installed. Please install it and try again. 

※php のzipの拡張機能をインストールしてくださいとのこと。

Laravelのプロジェクトを作成する

エラーを解消するために、pearコマンドを入れて、同時にpeclコマンドを使えるようにする。

$ sudo yum install php-pear --disablerepo=* --enablerepo=remi,remi-php70

zlibをインストールする

$ sudo yum -y install zlib-devel

# zipをインストールする
$ sudo pecl install zip

downloading zip-1.13.4.tgz ...
Starting to download zip-1.13.4.tgz (316,354 bytes)
.................................................................done: 316,354 bytes
119 source files, building
running: phpize
Configuring for:
PHP Api Version:         20151012
Zend Module Api No:      20151012
Zend Extension Api No:   320151012
building in /var/tmp/pear-build-rootIeIa1c/zip-1.13.4
running: /var/tmp/zip/configure --with-php-config=/usr/bin/php-config
checking for grep that handles long lines and -e... /bin/grep
checking for egrep... /bin/grep -E
checking for a sed that does not truncate output... /bin/sed
checking for cc... no
checking for gcc... no
configure: error: in `/var/tmp/pear-build-rootIeIa1c/zip-1.13.4':
configure: error: no acceptable C compiler found in $PATH
See `config.log' for more details.
ERROR: `/var/tmp/zip/configure --with-php-config=/usr/bin/php-config' failed

# エラーが起きる

cc と gcc がインストールされていないので、インストールする

$ sudo yum -y install cc gcc

再度実行

$ sudo yum -y install zlib-devel

# zipをインストールする
$ sudo pecl install zip

# 略
Build process completed successfully
Installing '/usr/lib64/php/modules/zip.so'
install ok: channel://pecl.php.net/zip-1.13.4
configuration option "php_ini" is not set to php.ini location
You should add "extension=zip.so" to php.ini

php.iniにzip.soの拡張機能を追加してと指定される。


$sudo emacs /etc/php.ini

# 略
extension=zip.so

Laravelのプロジェクトを作成する


$ ~/.composer/vendor/bin/laravel new APPNAME
Crafting application...
PHP Warning:  file_put_contents(/var/www/gacd/laravel_e3070cc09718607bf5d079e3145a0f1a.zip): failed to open stream: Permission de
PHP Warning:  ZipArchive::extractTo(): Permission denied in /home/ema_eel/.composer/vendor/laravel/installer/src/NewCommand.php o
PHP Warning:  ZipArchive::close(): Invalid or uninitialized Zip object in /home/ema_eel/.composer/vendor/laravel/installer/src/Ne
Composer could not find a composer.json file in /var/www/gacd
To initialize a project, please create a composer.json file as described in the https://getcomposer.org/ "Getting Started" sectio
Application ready! Build something amazing.

作成するディレクトリに書き込み権限が無い。
書き込み権限を付与して再実行


$ ~/.composer/vendor/bin/laravel new test
Crafting application...
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
  - Installing jakub-onderka/php-console-color (0.1)
    Loading from cache

  - Installing vlucas/phpdotenv (v2.3.0)
    Loading from cache

  - Installing symfony/polyfill-mbstring (v1.2.0)
    Loading from cache

# 略

> php artisan key:generate
Application key ['KEY'] set successfully.
Application ready! Build something amazing.

パーミションの設定

Laravelでお馴染みのstorageとcacheの書き込み権限を付与

$ sudo chmod 777 -R APP_DIR/storage
$ sudo chmod 777 -R APP_DIR/bootstrap/cache

Lavaevlのバージョンを固定する

emacs composer.json

"require": {
        "php": ">=5.5.9",
        "laravel/framework": "5.2.42" # ここで末尾のバージョンまで固定してupdateした時にLaravelが更新されないようにする
    },

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