centos7にmysql5.7をインストールする

centos7にmysql5.7をいれる

DBが必要になったのでmysqlをインストールまでのメモです

mysqlがインストールできない

[vagrant@localhost ~]$ sudo yum -y install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.jaist.ac.jp
 * extras: www.ftp.ne.jp
 * remi-safe: repo1.sea.innoscale.net
 * updates: www.ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1:mariadb-5.5.52-1.el7.x86_64
--> Running transaction check
---> Package mariadb-libs.x86_64 1:5.5.52-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                          Arch                       Version                               Repository                Size
==================================================================================================================================
Installing:
 mariadb                          x86_64                     1:5.5.52-1.el7                        base                     8.7 M
Installing for dependencies:
 mariadb-libs                     x86_64                     1:5.5.52-1.el7                        base                     761 k

Transaction Summary
==================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 9.5 M
Installed size: 53 M
Downloading packages:
(1/2): mariadb-libs-5.5.52-1.el7.x86_64.rpm                                                                | 761 kB  00:00:00
(2/2): mariadb-5.5.52-1.el7.x86_64.rpm                                                                     | 8.7 MB  00:00:11
----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                             871 kB/s | 9.5 MB  00:00:11
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                             1/2
  Installing : 1:mariadb-5.5.52-1.el7.x86_64                                                                                  2/2
  Verifying  : 1:mariadb-5.5.52-1.el7.x86_64                                                                                  1/2
  Verifying  : 1:mariadb-libs-5.5.52-1.el7.x86_64                                                                             2/2

Installed:
  mariadb.x86_64 1:5.5.52-1.el7

Dependency Installed:
  mariadb-libs.x86_64 1:5.5.52-1.el7

Complete!

なぜかmariaDBがインストールされる

CentOS7にはデフォルトでmariaDBというのがはいっているとのこと
なのでそちらが優先でインストールされちゃうのかな
mariaDBmysqlは競合を起こすようなのでmysqlを入れる場合はmariaDBを削除する

一応確認
[vagrant@localhost ~]$ rpm -qa | grep -i "mariadb"
mariadb-libs-5.5.52-1.el7.x86_64
mariaDBを削除する
[vagrant@localhost ~]sudo yum -y remove mariadb-libs
古いmysqlがあったら削除する
[vagrant@localhost ~]rm -rf /var/lib/mysql/
リポジトリをインストールする
[vagrant@localhost ~]$wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
-bash: wget: command not found
wgetがないのでインストールする
[vagrant@localhost ~]$sudo yum -y install wget
再度実行
[vagrant@localhost ~]$ wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
--2017-03-27 10:04:49--  https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Resolving dev.mysql.com (dev.mysql.com)... 137.254.60.11
Connecting to dev.mysql.com (dev.mysql.com)|137.254.60.11|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm [following]
--2017-03-27 10:04:50--  https://repo.mysql.com//mysql57-community-release-el7-9.noarch.rpm
Resolving repo.mysql.com (repo.mysql.com)... 114.179.154.109
Connecting to repo.mysql.com (repo.mysql.com)|114.179.154.109|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 9224 (9.0K) [application/x-redhat-package-manager]
Saving to: ‘mysql57-community-release-el7-9.noarch.rpm’

100%[========================================================================================>] 9,224       --.-K/s   in 0s

2017-03-27 10:04:50 (375 MB/s) - ‘mysql57-community-release-el7-9.noarch.rpm’ saved [9224/9224]
[vagrant@localhost ~]$ sudo rpm -Uvh mysql57-community-release-el7-9.noarch.rpm
warning: mysql57-community-release-el7-9.noarch.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mysql57-community-release-el7-9  ################################# [100%]


[vagrant@localhost ~]$ sudo yum -y install mysql-community-server
Loaded plugins: fastestmirror
mysql-connectors-community                                                                                 | 2.5 kB  00:00:00
mysql-tools-community                                                                                      | 2.5 kB  00:00:00
mysql57-community                                                                                          | 2.5 kB  00:00:00
(1/3): mysql-connectors-community/x86_64/primary_db                                                        |  13 kB  00:00:00
(2/3): mysql-tools-community/x86_64/primary_db                                                             |  32 kB  00:00:00
(3/3): mysql57-community/x86_64/primary_db                                                                 |  96 kB  00:00:00
Loading mirror speeds from cached hostfile
 * base: www.ftp.ne.jp
 * epel: ftp.jaist.ac.jp
 * extras: www.ftp.ne.jp
 * remi-safe: repo1.sea.innoscale.net
 * updates: www.ftp.ne.jp
Resolving Dependencies
--> Running transaction check
---> Package mysql-community-server.x86_64 0:5.7.17-1.el7 will be installed
--> Processing Dependency: mysql-community-common(x86-64) = 5.7.17-1.el7 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Processing Dependency: mysql-community-client(x86-64) >= 5.7.9 for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Processing Dependency: net-tools for package: mysql-community-server-5.7.17-1.el7.x86_64
--> Running transaction check
---> Package mysql-community-client.x86_64 0:5.7.17-1.el7 will be installed
--> Processing Dependency: mysql-community-libs(x86-64) >= 5.7.9 for package: mysql-community-client-5.7.17-1.el7.x86_64
---> Package mysql-community-common.x86_64 0:5.7.17-1.el7 will be installed
---> Package net-tools.x86_64 0:2.0-0.17.20131004git.el7 will be installed
--> Running transaction check
---> Package mysql-community-libs.x86_64 0:5.7.17-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                            Arch               Version                                Repository                     Size
==================================================================================================================================
Installing:
 mysql-community-server             x86_64             5.7.17-1.el7                           mysql57-community             162 M
Installing for dependencies:
 mysql-community-client             x86_64             5.7.17-1.el7                           mysql57-community              24 M
 mysql-community-common             x86_64             5.7.17-1.el7                           mysql57-community             271 k
 mysql-community-libs               x86_64             5.7.17-1.el7                           mysql57-community             2.1 M
 net-tools                          x86_64             2.0-0.17.20131004git.el7               base                          304 k

Transaction Summary
==================================================================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 188 M
Installed size: 848 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-common-5.7.17-1.el7.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Public key for mysql-community-common-5.7.17-1.el7.x86_64.rpm is not installed
(1/5): mysql-community-common-5.7.17-1.el7.x86_64.rpm                                                      | 271 kB  00:00:00
(2/5): mysql-community-libs-5.7.17-1.el7.x86_64.rpm                                                        | 2.1 MB  00:00:01
(3/5): net-tools-2.0-0.17.20131004git.el7.x86_64.rpm                                                       | 304 kB  00:00:00
(4/5): mysql-community-client-5.7.17-1.el7.x86_64.rpm                                                      |  24 MB  00:00:03
(5/5): mysql-community-server-5.7.17-1.el7.x86_64.rpm                                                      | 162 MB  00:00:28
----------------------------------------------------------------------------------------------------------------------------------
Total                                                                                             6.1 MB/s | 188 MB  00:00:30
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-9.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : mysql-community-common-5.7.17-1.el7.x86_64                                                                     1/5
  Installing : mysql-community-libs-5.7.17-1.el7.x86_64                                                                       2/5
  Installing : mysql-community-client-5.7.17-1.el7.x86_64                                                                     3/5
  Installing : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                      4/5
  Installing : mysql-community-server-5.7.17-1.el7.x86_64                                                                     5/5
  Verifying  : mysql-community-server-5.7.17-1.el7.x86_64                                                                     1/5
  Verifying  : net-tools-2.0-0.17.20131004git.el7.x86_64                                                                      2/5
  Verifying  : mysql-community-client-5.7.17-1.el7.x86_64                                                                     3/5
  Verifying  : mysql-community-libs-5.7.17-1.el7.x86_64                                                                       4/5
  Verifying  : mysql-community-common-5.7.17-1.el7.x86_64                                                                     5/5

Installed:
  mysql-community-server.x86_64 0:5.7.17-1.el7

Dependency Installed:
  mysql-community-client.x86_64 0:5.7.17-1.el7                    mysql-community-common.x86_64 0:5.7.17-1.el7
  mysql-community-libs.x86_64 0:5.7.17-1.el7                      net-tools.x86_64 0:2.0-0.17.20131004git.el7

Complete!

インストールできた

バージョンの確認
[vagrant@localhost ~]$ mysqld --version
mysqld  Ver 5.7.17 for Linux on x86_64 (MySQL Community Server (GPL))
mysqlログインする
[vagrant@localhost ~]$mysql -uroot
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

なんか失敗する
調べてみるとパスワードは初回起動時にログファイルに作られるのでそれでログインするみたい
有名どころだけど古いバージョンのサイトをみてたからつまずいた

パスワードの確認
[vagrant@localhost ~]$ sudo cat /var/log/mysqld.log | grep 'temporary password'
2017-03-27T10:32:26.278899Z 1 [Note] A temporary password is generated for root@localhost: rLw3>lfut?1q
再度ログインする
[vagrant@localhost ~]$ mysql -uroot -prLw3>lfut?1q
mysql: [Warning] Using a password on the command line interface can be insecure.
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

コマンドラインでパスワードつきはだめみたい 履歴のこってセキュリティー上あぶないからかな

[vagrant@localhost ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 22
Server version: 5.7.17

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

こっちでパスワードをいれたらはいれた

少し動かしてみる

mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

パスワードをリセットしなさいとのこと
このパスワードは一時的にアクセスするためのものみたい

次のコマンドでパスワードを再設定する
[vagrant@localhost ~]$mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:  ;<-ここで先程確認したパスワードをいれる

そのあとパスワードを入力、確認をして再設定をおこなう

[vagrant@localhost ~]$ mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 5.7.17 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
4 rows in set (0.00 sec)

これでmysqlがインストールできました。
結構まえにためしたときは簡単にいれられたのですが
5.7?からなのか設定方法がけっこう変わったのですね

PHPUnitで簡単なテストをする2 バグ?

前回PHPUnitの簡単なテストを試してみました。

PHPUnitのdataProvider機能を使ったりしてたら気になる状態になった

テストコード

<?php

require_once ('vendor/autoload.php');

use PHPUnit\Framework\TestCase;

class testHoge extends TestCase
{
    /**
     * @dataProvider testdataProvider
     */
    public function testunittest($a, $expected)
    {
        $this->assertEquals($expected, -1);
    }

    public function testdataProvider()
    {
        return [
            [0, 0],
        ];
    }
}
?>

dataProviderを使ったコードでこれを動かすと

[vagrant@localhost html]$ vendor/bin/phpunit tests/testHoge.php
PHPUnit 5.5.7 by Sebastian Bergmann and contributors.

F.                                                                  2 / 2 (100%)

Time: 241 ms, Memory: 4.00MB

There was 1 failure:

1) testHoge::testunittest with data set #0 (0, 0)
Failed asserting that -1 matches expected 0.

/var/www/html/tests/hogeTest.php:14

FAILURES!
Tests: 2, Assertions: 1, Failures: 1.

テストは1つしかやってないはずなのに2つチェックが入ってる

1つ目は失敗してるのであってるのだが2つ目のはどこをチェックしてるんだろ

しかも成功しちゃってるし

んー  なんだろこれ

PHPUnitで簡単なテストをする

前回PHPUnitのインストールまでやったので簡単なサンプルまでを試すメモです

準備

ディレクトリ構成

composerでPHPUnitいれたらvendeorができるので 追加でメイン用とテスト用のphpを作る

www/
├src/
│ └message.php
├tests/
│ └messageTest.php
├vendor/
│ └︙
├composer.json
├composer.lock

message.php

メイン用

<?php

class Message
{
    private $message;

    public function __construct(string $message)
    {
        $this->message = $message;
    }

    public function get()
    {
        return $this->message;
    }
}
?>

messageTest.php

テスト用

<?php

require_once ('vendor/autoload.php');
require_once (dirname(__FILE__) .'/../src/message.php');

use PHPUnit\Framework\TestCase;

class MessageTest extends TestCase
{
    public function testGet()
    {
        $message = new Message('hello, world');
        $this->assertEquals('hello, world', $message->get());
    }
}
?>

コマンド

testsフォルダを指定して***Test.phpを調べてくれる

$ vendor/bin/phpunit /tests
PHPUnit 5.5.4 by Sebastian Bergmann and contributors.

W.                                                                  2 / 2 (100%)

Time: 204 ms, Memory: 4.00MB

There was 1 warning:

1) Warning
No tests found in class "PHPUnit\Framework\TestCase".

WARNINGS!
Tests: 2, Assertions: 1, Warnings: 1.

とりあえずはテストできてるみたいだけどWARNINGSが気になる。
呼び出し方がまちがってる?

原因探るためいろいろ入れたり消したりしてたらWARNINGSが消えて何で解消できたのがか不明。

ComposerとPHPUnitのインストール

PHP使うならComposer使うといいとよく見るので導入してみました。

このエントリーはComposerのインストールとComposerでPHPUnitの導入までのメモです

composerのインストール

公式のインストール方法 https://getcomposer.org/download/

インストールをもっと簡単に

[vagrant@localhost html]$curl -sS https://getcomposer.org/installer | php

パスにあるディレクトリに移動させる

[vagrant@localhost html]$mv composer.phar /usr/local/bin/composer

composerのアップデート

[vagrant@localhost html]$composer self-update

composerのインストールはこれで完了

composer.jsonの作成

とりあえずPHPUnitを指定したのをつくる

{
    "require-dev": {
        "phpunit/phpunit": "5.5.*"
    }
}

composer installでパッケージのインストール

[vagrant@localhost html]$composer install

エラー発生

[vagrant@localhost html]$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - phpunit/phpunit 5.5.7 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.6 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.5 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.4 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.3 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.2 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.1 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - phpunit/phpunit 5.5.0 requires ext-dom * -> the requested PHP extension dom is missing from your system.
    - Installation request for phpunit/phpunit 5.5.* -> satisfiable by phpunit/phpunit[5.5.0, 5.5.1, 5.5.2, 5.5.3, 5.5.4, 5.5.5, 5.5.6, 5.5.7].

  To enable extensions, verify that they are enabled in your .ini files:
    - /etc/php.ini
    - /etc/php.d/20-bz2.ini
    - /etc/php.d/20-calendar.ini
    - /etc/php.d/20-ctype.ini
    - /etc/php.d/20-curl.ini
    - /etc/php.d/20-exif.ini
    - /etc/php.d/20-fileinfo.ini
    - /etc/php.d/20-ftp.ini
    - /etc/php.d/20-gettext.ini
    - /etc/php.d/20-iconv.ini
    - /etc/php.d/20-json.ini
    - /etc/php.d/20-phar.ini
    - /etc/php.d/20-sockets.ini
    - /etc/php.d/20-tokenizer.ini
  You can also run `php --ini` inside terminal to see which files are used by PHP in CLI mode.

DOM Extensionがないようなのでインストールするも失敗する

[vagrant@localhost html]$sudo yum -y install php-xml

Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                                         | 3.6 kB  00:00:00
epel/x86_64/metalink                                                                                                                         | 5.1 kB  00:00:00
epel                                                                                                                                         | 4.3 kB  00:00:00
extras                                                                                                                                       | 3.4 kB  00:00:00
remi-safe                                                                                                                                    | 2.9 kB  00:00:00
updates                                                                                                                                      | 3.4 kB  00:00:00
(1/5): epel/x86_64/updateinfo                                                                                                                | 748 kB  00:00:00
(2/5): extras/7/x86_64/primary_db                                                                                                            | 122 kB  00:00:00
(3/5): updates/7/x86_64/primary_db                                                                                                           | 2.9 MB  00:00:00
(4/5): remi-safe/primary_db                                                                                                                  | 908 kB  00:00:01
(5/5): epel/x86_64/primary_db                                                                                                                | 4.6 MB  00:00:05
Determining fastest mirrors
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-safe: mirror.smartmedia.net.id
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package php-xml.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.24)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.22)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.13)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libxslt.so.1()(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Processing Dependency: libexslt.so.0()(64bit) for package: php-xml-5.4.16-42.el7.x86_64
--> Running transaction check
---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
---> Package php-xml.x86_64 0:5.4.16-42.el7 will be installed
--> Processing Dependency: php-common(x86-64) = 5.4.16-42.el7 for package: php-xml-5.4.16-42.el7.x86_64
--> Finished Dependency Resolution
Error: Package: php-xml-5.4.16-42.el7.x86_64 (base)
           Requires: php-common(x86-64) = 5.4.16-42.el7
           Installed: php-common-7.0.15-1.el7.remi.x86_64 (@remi-php70)
               php-common(x86-64) = 7.0.15-1.el7.remi
           Available: php-common-5.4.16-42.el7.x86_64 (base)
               php-common(x86-64) = 5.4.16-42.el7
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

remiでphpをインストールしてたのでremi-php70を指定した方法で再度インストール

[vagrant@localhost html]$sudo yum -y install --enablerepo=remi-php70 php-xml
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-php70: mirror.smartmedia.net.id
 * remi-safe: mirror.smartmedia.net.id
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package php-xml.x86_64 0:7.0.16-1.el7.remi will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================
 Package                             Arch                               Version                                        Repository                              Size
====================================================================================================================================================================
Installing:
 php-xml                             x86_64                             7.0.16-1.el7.remi                              remi-php70                             204 k

Transaction Summary
====================================================================================================================================================================
Install  1 Package

Total download size: 204 k
Installed size: 854 k
Downloading packages:
php-xml-7.0.16-1.el7.remi.x86_64.rpm                                                                                                         | 204 kB  00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : php-xml-7.0.16-1.el7.remi.x86_64                                                                                                                 1/1
  Verifying  : php-xml-7.0.16-1.el7.remi.x86_64                                                                                                                 1/1

Installed:
  php-xml.x86_64 0:7.0.16-1.el7.remi

Complete!

入った

念のため確認

[vagrant@localhost html]$ yum list installed | grep php
php.x86_64                       7.0.16-1.el7.remi              @remi-php70
php-cli.x86_64                   7.0.16-1.el7.remi              @remi-php70
php-common.x86_64                7.0.16-1.el7.remi              @remi-php70
php-json.x86_64                  7.0.16-1.el7.remi              @remi-php70
php-xml.x86_64                   7.0.16-1.el7.remi              @remi-php70

再度composer installするもエラー

[vagrant@localhost ~]$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 25 installs, 0 updates, 0 removals
    Failed to download symfony/yaml from dist: The zip extension and unzip command are both missing, skipping.
The php.ini used by your command-line PHP is: /etc/php.ini
    Now trying to download from source
  - Installing symfony/yaml (v3.2.4) Cloning 9724c68464


  [RuntimeException]
  Failed to clone https://github.com/symfony/yaml.git, git was not found, check that it is installed and in your PATH env.
  sh: git: command not found


install [--prefer-source] [--prefer-dist] [--dry-run] [--dev] [--no-dev] [--no-custom-installers] [--no-autoloader] [--no-scripts] [--no-progress] [--no-suggest] [-v|vv|vvv|--verbose] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--ignore-platform-reqs] [--] [<packages>]...

zipとunzipがないのかな

[vagrant@localhost html]$ sudo yum -y install zip unzip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.iij.ad.jp
 * epel: ftp.jaist.ac.jp
 * extras: ftp.iij.ad.jp
 * remi-safe: mirror.smartmedia.net.id
 * updates: ftp.iij.ad.jp
Resolving Dependencies
--> Running transaction check
---> Package unzip.x86_64 0:6.0-16.el7 will be installed
---> Package zip.x86_64 0:3.0-11.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================================================
 Package                               Arch                                   Version                                    Repository                            Size
====================================================================================================================================================================
Installing:
 unzip                                 x86_64                                 6.0-16.el7                                 base                                 169 k
 zip                                   x86_64                                 3.0-11.el7                                 base                                 260 k

Transaction Summary
====================================================================================================================================================================
Install  2 Packages

Total download size: 429 k
Installed size: 1.1 M
Downloading packages:
(1/2): unzip-6.0-16.el7.x86_64.rpm                                                                                                           | 169 kB  00:00:00
(2/2): zip-3.0-11.el7.x86_64.rpm                                                                                                             | 260 kB  00:00:00
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                               2.8 MB/s | 429 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : unzip-6.0-16.el7.x86_64                                                                                                                          1/2
  Installing : zip-3.0-11.el7.x86_64                                                                                                                            2/2
  Verifying  : zip-3.0-11.el7.x86_64                                                                                                                            1/2
  Verifying  : unzip-6.0-16.el7.x86_64                                                                                                                          2/2

Installed:
  unzip.x86_64 0:6.0-16.el7                                                         zip.x86_64 0:3.0-11.el7

Complete!

composer installがやっとできた

[vagrant@localhost html]$ composer install
Loading composer repositories with package information
Updating dependencies (including require-dev)
Package operations: 25 installs, 0 updates, 0 removals
  - Installing symfony/yaml (v3.2.4) Downloading: 100%
  - Installing sebastian/version (2.0.1) Downloading: 100%
  - Installing sebastian/resource-operations (1.0.0) Downloading: 100%
  - Installing sebastian/recursion-context (1.0.2) Downloading: 100%
  - Installing sebastian/object-enumerator (1.0.0) Downloading: 100%
  - Installing sebastian/global-state (1.1.1) Downloading: 100%
  - Installing sebastian/exporter (1.2.2) Downloading: 100%
  - Installing sebastian/environment (2.0.0) Downloading: 100%
  - Installing sebastian/diff (1.4.1) Downloading: 100%
  - Installing sebastian/comparator (1.2.4) Downloading: 100%
  - Installing doctrine/instantiator (1.0.5) Downloading: 100%
  - Installing phpunit/php-text-template (1.2.1) Downloading: 100%
  - Installing phpunit/phpunit-mock-objects (3.4.3) Downloading: 100%
  - Installing phpunit/php-timer (1.0.9) Downloading: 100%
  - Installing phpunit/php-file-iterator (1.4.2) Downloading: 100%
  - Installing sebastian/code-unit-reverse-lookup (1.0.0) Downloading: 100%
  - Installing phpunit/php-token-stream (1.4.11) Downloading: 100%
  - Installing phpunit/php-code-coverage (4.0.6) Downloading: 100%
  - Installing webmozart/assert (1.2.0) Downloading: 100%
  - Installing phpdocumentor/reflection-common (1.0) Downloading: 100%
  - Installing phpdocumentor/type-resolver (0.2.1) Downloading: 100%
  - Installing phpdocumentor/reflection-docblock (3.1.1) Downloading: 100%
  - Installing phpspec/prophecy (v1.6.2) Downloading: 100%
  - Installing myclabs/deep-copy (1.6.0) Downloading: 100%
  - Installing phpunit/phpunit (5.5.4) Downloading: 100%
symfony/yaml suggests installing symfony/console (For validating YAML files using the lint command)
sebastian/global-state suggests installing ext-uopz (*)
phpunit/phpunit-mock-objects suggests installing ext-soap (*)
phpunit/php-code-coverage suggests installing ext-xdebug (>=2.4.0)
phpunit/phpunit suggests installing phpunit/php-invoker (~1.1)
Writing lock file
Generating autoload files

PHPUnitの確認

vendor内にPHPUnitができてたのでこれをつかうのかな?

[vagrant@localhost html]$ vendor/bin/phpunit --version
PHPUnit 5.5.4 by Sebastian Bergmann and contributors.

なんかすごい遠回りしたけど導入できたと思う

はてぶに無限スクロールをつけるchrome-extension作った

1週間ぶりです

はてなブックマークって昔は新着ページに自動読み込みがあったはずなんですが
いまのタイル形式になってからきえちゃったみたいなんですよね。
タイル形式になってから、Greasemonkeyautopagerizeも効かないし。
もしかして機能はあって当たり前すぎて検索にも引っかからないだけなのか
あったら教えてー

プログラム始めて勉強のついでに作ってみました。

javascriptとか初心者だから調べながらやりました。
もうちょいきれいに書けたらなと思います。

github.com

使い方

  1. get cloneかdownloadする
  2. Chomeの拡張機能のでペロッパーモードにチェックをいれる
  3. 「パッケージ化されていない拡張機能を読み込む」から先程のファイルを選択する

これだけでとりあえずは動くはず。
最低限の機能(次ページ追加)だけなので
アイコンは適当だし(絵かけない)
オプションとかもないです、
読み込み中マークもでません (ちょっと待つと追加される)
あ、リストレイアウトも対応してません。(タイルレイアウトだけ)

最後に
はてなの開発の人、公式でつくってほしいです

とりあえずPHPでHelloWorld

やっと環境ができたので、

プログラムで最初にやるのはHelloWorldの表示させることでしょうか

<?php
echo "HelloWorld";
?>

まあ、表示するだけなら上ので終わりなんですよね


なので練習問題的なのを探してそれをやってみました

<?php
/**
 *
 * ループでHello World!5回表示する
 *
 * http://vipprog.net/wiki/exercise.html#eb2c4338
 *
 */
for ($i=0; $i<5; $i++) {
    echo "HelloWorld!".nl2br("\n");
}

?>

classを使うとこんな感じ?

<?php
/**
 *
 * ループでHello World!5回表示する
 *
 * http://vipprog.net/wiki/exercise.html#eb2c4338
 *
 */
class HelloWorldObj {
    private $count = 0;
    private $text = "HelloWorld!";

    public function getText() {
        return $this->text;
    }

    public function setCount($count) {
        $this->count = $count;
    }

    public function loopEcho() {
        for ($i=0; $i<$this->count; $i++) {
            echo $this->getText().nl2br("\n");
        }
    }
}
$HelloWorld = new HelloWorldObj();
$HelloWorld->setCount(5);
$HelloWorld->loopEcho();
?>

次は順番で行くとfizzbuzzかな

あとnl2brがnewline to breakって意味だってわかった

Vagrantの共有フォルダで403Forbiddenエラーがでる

Vagrantの共有フォルダをhttpdのDocumentRootとして扱う

これならWindows上でファイル編集できるからやりやすそうと思ってVagrantfileを編集してみた

config.vm.synced_folder "../data/var/www/html", "/var/www/html"

これで/html/index.htmlとか作って表示をさせたかった

アクセスしてみると403エラー

アクセスしてみると次の403エラーで表示できなかった

Forbidden
You don't have permission to access /index.html on this server.

表示させるには?

SELinuxを無効にすればとりあえずは表示するようになった

SELinuxの操作

SELinuxの確認

# getenforce
Enforcing
enforcing
SELinux機能,アクセス制限が有効
permissive
SELinuxは警告を出力、アクセス制限は無効
disabled
SELinux機能、アクセス制限がが無効

SELinuxを一時的に有効、無効にする

SELinuxを一時的に無効にする

# setenforce 0

SELinuxを一時的に有効にする

# setenforce 1

上の設定はサーバー再起動すると元に戻る

SELinuxの設定

サーバーを再起動させても設定を保持したい場合は設定ファイルを変更しないといけない

;; 設定ファイルの場所
# vi /etc/selinux/config

でファイルを開いたあとSELINUX=***の箇所を変更する

;; 有効
SELINUX=enforcing
;; 無効
SELINUX=disabled

変更したあとサーバーを再起動させる

ps

SELinuxを有効のまま表示させる方法は結局わからなかった