3
0

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.

PHPのビルトインウェブサーバーを使って、Laravelの環境構築とアプリケーション実行をしてみた

Last updated at Posted at 2019-03-21

概要

LaravelではPHPのもつビルトインウェブサーバー機能を使って、簡単にアプリケーションを実行できます。
必要な環境構築とアプリケーション実行をまとめました。


前提条件

  • バージョン
    • OS: MacOS 10.14.2
    • PHP: 7.1.19
  • 更新日
    • 2019/03/21

実際の手順

1. composerのインストール

  • composerをインストールします
  • ここではcurlでインストールします。brewなどでもできます
  • composer --versionでバージョン情報が出てこれば成功です
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
chmod a+x /usr/local/bin/composer
composer --version

2. laravelインストーラのインストール

  • composerを使ってlaravelインストーラをインストールします
composer global require "laravel/installer=~1.1"

3. 環境変数PATHの変更

  • 環境変数PATHを変更し、sourceコマンドで反映します
echo "export PATH=~/.composer/vendor/bin:$PATH" >> ~/.bash_profile
source ~/.bash_profile

4. ディレクトリの作成、移動

  • プロジェクトを置きたい場所にディレクトリを作成します
  • ここではホームディレクトリ直下にlaravelディレクトリを作成し、laravelディレクトリへ移動します
cd ~
mkdir laravel
cd laravel

5. laravelコマンドを使ってプロジェクトの作成

  • ここではプロジェクト名をstartlaravelとします
laravel new startlaravel
  • あるいはこちらでも可能です(上か下、どちらかのコマンドを実行してください)
composer create-project --prefer-dist laravel/laravel startlaravel

6. サーバの実行

  • 先ほど作ったプロジェクト内に移動し、artisanコマンドでサーバを実行します
  • --port= でポート番号を指定できます。つけない場合は8000に繋がります
cd startlaravel
php artisan serve --port=8101

7. 確認

  • http://localhost:8101/ を開きます
  • (8101は上記で指定したポート番号を設定してください)
  • 以下の図のように表示すれば成功です
  • 停止させる場合は、ターミナルでcontrol + cを押してください

実行図.png

注意事項

  • ビルトインウェブサーバーは、テストや動作確認用に用意されているものなので、決して本番環境での利用は行わないでください。

参照

以下の本やサイトを参考にしました。

PHPフレームワーク Laravel入門
PHPのビルトインサーバで動かしたい

3
0
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
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?