LoginSignup
1
0

More than 5 years have passed since last update.

Cloud9にPHP7 + Lumenをインストール

Last updated at Posted at 2017-12-03

PHPでAPIを作りたかったので LARAVEL ベースの軽量フレームワーク Lumen を使いました。

今回はAPIだけなのでマイクロフレームワークを選択しました

Cloud9にはデフォルトではPHP5系がインストールされているので7系をインストールしLumenをインストールします

PHP7インストール

まずはこのサイトを元にPHP7をインストール

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install libapache2-mod-php7.0
sudo a2dismod php5
sudo a2enmod php7.0
sudo apt-get install php7.0-dom
sudo apt-get install php7.0-mbstring
sudo apt-get install php7.0-zip

PHPのバージョン確認

以下のコマンドでPHP7がインストールされている確認

php -v

# 以下のように表示されていれば正常にインストールされている
PHP 7.0.26-1+ubuntu14.04.1+deb.sury.org+1 (cli) (built: Nov 29 2017 10:01:47) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.26-1+ubuntu14.04.1+deb.sury.org+1, Copyright (c) 1999-2017, by Zend Technologies

MySQL用ドライバーインストール

PHP7のMySQL用ドライバーをインストールする

sudo apt-get install php7.0-mysql

Lumenをインストール

Composerを使ってLumenをインストールします
今回はtestと言うプロジェクト名で作ります

composer create-project --prefer-dist laravel/lumen test

Lumenの初期設定

.envファイルの設定

APPKEYの設定とDBの設定を行います
DBの設定はCloud9の初期設定状態となってます。

APP_ENV=local
APP_DEBUG=true
- APP_KEY=
+ APP_KEY="EttTJfhKALNC_37cggwwbbRu6QeXXzsaj9c4fnfK_ZN2jz6Ly8ML_6UQKLP7_-2Q"
APP_TIMEZONE=UTC

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
- DB_DATABASE=homestead
- DB_USERNAME=homestead
- DB_PASSWORD=secret
+ DB_DATABASE=c9
+ DB_USERNAME=root
+ DB_PASSWORD=

CACHE_DRIVER=file
QUEUE_DRIVER=sync

MySQLの起動

初期起動時にはMySQLは起動していないので以下コマンドにてMySQLを起動します

mysql-ctl start

apacheのルートディレクトリの変更

apacheのルートディレクトリをLumenのpublicディレクトリに変更します。

sudo vi /etc/apache2/sites-enabled/001-cloud9.conf  

以下のように/etc/apache2/sites-enabled/001-cloud9.confのDocumentRootを/home/ubuntu/workspace/{プロジェクト名}/publicに変更します

/etc/apache2/sites-enabled/001-cloud9.conf
<VirtualHost *:8080>
-    DocumentRoot /home/ubuntu/workspace
+   DocumentRoot /home/ubuntu/workspace/test/public
    ServerName https://${C9_HOSTNAME}:443

    LogLevel info

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

    <Directory /home/ubuntu/workspace>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

ServerName https://${C9_HOSTNAME}
search hit BOTTOM, continuing at TOP  

起動確認

アセット_1.png
上記スクリーンショットの通り「Run Project」を押下し

https://{プルジェクト名}-{ユーザ名}.c9users.io/

にアクセスし以下の通り表示されれば完了です
アセット 1.png

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