先日の"Raspberry Pi 3 Model B" LAMP化 : 準備編に続き、PHP と パッケージ管理(依存性管理)ツール Composer を導入します。
PHP 導入
Adminerについては、adminer の設置&設定をご覧ください。
PHP 7 インストール
$ sudo apt-get install php php-bcmath php-bz2 php-cgi php-cli php-common php-curl php-date php-db php-dev php-email-validator php-fpdf php-gd php-http-request2 php-intl php-json php-log php-markdown php-mbstring php-mcrypt php-mime-type php-mysql php-odbc php-pager php-pear php-pgsql php-phpdbg php-sqlite3 php-xml php-zip pkg-php-tools adminer cacti cacti-spine composer
以下の追加パッケージがインストールされます:
apache2 apache2-bin apache2-data apache2-utils autoconf automake autopoint
autotools-dev dbconfig-common dbconfig-mysql debhelper default-mysql-client
default-mysql-server dh-autoreconf dh-php dh-strip-nondeterminism fontconfig
fontconfig-config fonts-dejavu-core galera-3 gawk gettext git git-man
intltool-debian javascript-common jsonlint libaio1 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libarchive-zip-perl libarchive13
libcairo2 libcgi-fast-perl libcgi-pm-perl libcroco3 libdatrie1
libdbd-mysql-perl libdbi-perl libdbi1 libencode-locale-perl liberror-perl
libexporter-tiny-perl libfcgi-perl libfile-stripnondeterminism-perl
libfontconfig1 libgd3 libgraphite2-3 libharfbuzz0b libhtml-parser-perl
libhtml-tagset-perl libhtml-template-perl libhttp-date-perl
libhttp-message-perl libio-html-perl libjbig0 libjemalloc1 libjs-jquery
libjs-jquery-cookie libjs-jquery-jstree libjs-jquery-ui
libjs-jquery-ui-theme-ui-lightness liblist-moreutils-perl libltdl-dev
libltdl7 liblua5.2-0 liblwp-mediatypes-perl liblzo2-2 libmail-sendmail-perl
libmariadbclient18 libmcrypt4 libodbc1 libpango-1.0-0 libpangocairo-1.0-0
libpangoft2-1.0-0 libpci3 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5
libphp-adodb libpixman-1-0 libpq5 libreadline5 librrd8 libsensors4
libsigsegv2 libsnmp-base libsnmp30 libssl-dev libssl-doc
libsys-hostname-long-perl libterm-readkey-perl libthai-data libthai0
libtiff5 libtimedate-perl libtool liburi-perl libwebp6 libxcb-render0
libxcb-shm0 libxpm4 libxrender1 libxslt1.1 libzip4 lsof m4
mariadb-client-10.1 mariadb-client-core-10.1 mariadb-common
mariadb-server-10.1 mariadb-server-core-10.1 mysql-common php-auth-sasl
php-cli-prompt php-composer-ca-bundle php-composer-semver
php-composer-spdx-licenses php-doctrine-lexer php-json-schema php-mail
php-mdb2 php-net-smtp php-net-socket php-net-url2 php-psr-log php-snmp
php-symfony-console php-symfony-filesystem php-symfony-finder
php-symfony-polyfill-mbstring php-symfony-process php7.0 php7.0-bcmath
php7.0-bz2 php7.0-cgi php7.0-cli php7.0-common php7.0-curl php7.0-dev
php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql
php7.0-odbc php7.0-opcache php7.0-pgsql php7.0-phpdbg php7.0-readline
php7.0-snmp php7.0-sqlite3 php7.0-xml php7.0-zip po-debconf rrdtool shtool
snmp socat ssl-cert xml2
提案パッケージ:
www-browser apache2-doc apache2-suexec-pristine | apache2-suexec-custom
autoconf-archive gnu-standards autoconf-doc php-ldap moreutils
snmp-mibs-downloader fossil mercurial subversion dh-make gawk-doc
gettext-doc libasprintf-dev libgettextpo-dev git-daemon-run
| git-daemon-sysvinit git-doc git-el git-email git-gui gitk gitweb git-arch
git-cvs git-mediawiki git-svn lrzip libclone-perl libmldbm-perl
libnet-daemon-perl libsql-statement-perl libgd-tools libdata-dump-perl
libipc-sharedcache-perl libjs-jquery-ui-docs libtool-doc libmcrypt-dev
mcrypt libmyodbc odbc-postgresql tdsodbc unixodbc-bin lm-sensors gfortran
| fortran95-compiler gcj-jdk libwww-perl m4-doc mailx mariadb-test tinyca
ttf2pt1 php-mdb2-driver-fbsql php-mdb2-driver-ibase php-mdb2-driver-mssql
php-mdb2-driver-mysql php-mdb2-driver-mysqli php-mdb2-driver-oci8
php-mdb2-driver-odbc php-mdb2-driver-pgsql php-mdb2-driver-querysim
php-mdb2-driver-sqlite php-mdb2-driver-sqlsrv php-symfony-event-dispatcher
libmail-box-perl librrds-perl openssl-blacklist
推奨パッケージ:
php-sqlite
以下のパッケージが新たにインストールされます:
adminer apache2 apache2-bin apache2-data apache2-utils autoconf automake
autopoint autotools-dev cacti cacti-spine composer dbconfig-common
dbconfig-mysql debhelper default-mysql-client default-mysql-server
dh-autoreconf dh-php dh-strip-nondeterminism fontconfig fontconfig-config
fonts-dejavu-core galera-3 gawk gettext git git-man intltool-debian
javascript-common jsonlint libaio1 libapr1 libaprutil1
libaprutil1-dbd-sqlite3 libaprutil1-ldap libarchive-zip-perl libarchive13
libcairo2 libcgi-fast-perl libcgi-pm-perl libcroco3 libdatrie1
libdbd-mysql-perl libdbi-perl libdbi1 libencode-locale-perl liberror-perl
libexporter-tiny-perl libfcgi-perl libfile-stripnondeterminism-perl
libfontconfig1 libgd3 libgraphite2-3 libharfbuzz0b libhtml-parser-perl
libhtml-tagset-perl libhtml-template-perl libhttp-date-perl
libhttp-message-perl libio-html-perl libjbig0 libjemalloc1 libjs-jquery
libjs-jquery-cookie libjs-jquery-jstree libjs-jquery-ui
libjs-jquery-ui-theme-ui-lightness liblist-moreutils-perl libltdl-dev
libltdl7 liblua5.2-0 liblwp-mediatypes-perl liblzo2-2 libmail-sendmail-perl
libmariadbclient18 libmcrypt4 libodbc1 libpango-1.0-0 libpangocairo-1.0-0
libpangoft2-1.0-0 libpci3 libpcre16-3 libpcre3-dev libpcre32-3 libpcrecpp0v5
libphp-adodb libpixman-1-0 libpq5 libreadline5 librrd8 libsensors4
libsigsegv2 libsnmp-base libsnmp30 libssl-dev libssl-doc
libsys-hostname-long-perl libterm-readkey-perl libthai-data libthai0
libtiff5 libtimedate-perl libtool liburi-perl libwebp6 libxcb-render0
libxcb-shm0 libxpm4 libxrender1 libxslt1.1 libzip4 lsof m4
mariadb-client-10.1 mariadb-client-core-10.1 mariadb-common
mariadb-server-10.1 mariadb-server-core-10.1 mysql-common php php-auth-sasl
php-bcmath php-bz2 php-cgi php-cli php-cli-prompt php-common
php-composer-ca-bundle php-composer-semver php-composer-spdx-licenses
php-curl php-date php-db php-dev php-doctrine-lexer php-email-validator
php-fpdf php-gd php-http-request2 php-intl php-json php-json-schema php-log
php-mail php-markdown php-mbstring php-mcrypt php-mdb2 php-mime-type
php-mysql php-net-smtp php-net-socket php-net-url2 php-odbc php-pager
php-pear php-pgsql php-phpdbg php-psr-log php-snmp php-sqlite3
php-symfony-console php-symfony-filesystem php-symfony-finder
php-symfony-polyfill-mbstring php-symfony-process php-xml php-zip php7.0
php7.0-bcmath php7.0-bz2 php7.0-cgi php7.0-cli php7.0-common php7.0-curl
php7.0-dev php7.0-gd php7.0-intl php7.0-json php7.0-mbstring php7.0-mcrypt
php7.0-mysql php7.0-odbc php7.0-opcache php7.0-pgsql php7.0-phpdbg
php7.0-readline php7.0-snmp php7.0-sqlite3 php7.0-xml php7.0-zip
pkg-php-tools po-debconf rrdtool shtool snmp socat ssl-cert xml2
アップグレード: 0 個、新規インストール: 200 個、削除: 0 個、保留: 0 個。
┌────────────────────────┤ cacti を設定しています ├─────────────────────────┐
│ Cacti が自動的に設定するウェブサーバを選んでください。 │
│ │
│ ウェブサーバを手作業で設定したい場合は「どれでもない」を選んでください。 │
│ │
│ ウェブサーバ: │
│ │
│ apache2 │
│ lighttpd │
│ どれでもない │
│ │
│ │
│ <了解> │
│ │
└───────────────────────────────────────────────────────────────────────────┘
┌────────────────────────┤ cacti を設定しています ├─────────────────────────┐
│ │
│ cacti パッケージを使用する前に、データベースをインストールして設定する必 │
│ 要があります。これは必要に応じて dbconfig-common で処理することもできま │
│ す。 │
│ │
│ あなたが上級データベース管理者で、手動でこの設定を実行することがわかって │
│ いる場合、あるいはデータベースのインストールと設定が完了している場合は、 │
│ このオプションを拒否するべきです。何をすべきかの詳細は、 │
│ /usr/share/doc/cacti で提供されている可能性が最も高いです。 │
│ │
│ そうでなければ、おそらくこのオプションを選ぶべきです。 │
│ │
│ cacti 用のデータベースを dbconfig-common で設定しますか? │
│ │
│ <はい> <いいえ> │
│ │
└───────────────────────────────────────────────────────────────────────────┘
cacti 用 MySQL パスワードの設定
Package configuration
┌───────────────────────┤ Configuring cacti ├────────────────────────┐
│ Please provide a password for cacti to register with the database │
│ server. If left blank, a random password will be generated. │
│ │
│ MySQL application password for cacti: │
│ │
│ __________________________________________________________________ │
│ │
│ <Ok> <Cancel> │
│ │
└────────────────────────────────────────────────────────────────────┘
導入確認
$ php -v
PHP 7.0.27-0+deb9u1 (cli) (built: Jan 5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
Composer 導入
以前の記事、Composerの導入に沿って簡単に導入できます。
インストール
$ curl -sS http://getcomposer.org/installer | php
All settings correct for using Composer
Downloading...
Composer (version 1.6.5) successfully installed to: /home/rasp/composer.phar
Use it: php composer.phar
curl | opitons |
---|---|
-S, --show-error |
Show error. With -s, make curl show errors when they occur |
-s, --silent |
Silent mode (don't output anything) |
設定
作成された composer.phar ファイルをパスの通る場所に移動します。
base on PHP: Phar アーカイブの使用法: 導入 - Manual
Phar アーカイブは Java の JAR アーカイブと似た概念のものですが、 PHP アプリケーションで使用する際に必要な機能をより柔軟に使用できるよう改良しています。 Phar アーカイブを使用すると、PHP アプリケーションやライブラリを ひとつのファイルにまとめて配布できるようになります。 Phar アーカイブ形式のアプリケーションは、その他の PHP アプリケーションとまったく同様に扱えます。
<?php include 'coollibrary.phar'; ?>
$ sudo mv /home/rasp/composer.phar /usr/local/bin/composer
$ composer
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
/_/
Composer version 1.6.5 2018-05-04 11:44:59
Usage:
command [options] [arguments]
Options:
-h, --help Display this help message
-q, --quiet Do not output any message
-V, --version Display this application version
--ansi Force ANSI output
--no-ansi Disable ANSI output
-n, --no-interaction Do not ask any interactive question
--profile Display timing and memory usage information
--no-plugins Whether to disable plugins.
-d, --working-dir=WORKING-DIR If specified, use the given directory as working directory.
-v|vv|vvv, --verbose Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
Available commands:
about Shows the short information about Composer.
archive Creates an archive of this composer package.
browse Opens the package's repository URL or homepage in your browser.
check-platform-reqs Check that platform requirements are satisfied.
clear-cache Clears composer's internal package cache.
clearcache Clears composer's internal package cache.
config Sets config options.
create-project Creates new project from a package into given directory.
depends Shows which packages cause the given package to be installed.
diagnose Diagnoses the system to identify common errors.
dump-autoload Dumps the autoloader.
dumpautoload Dumps the autoloader.
exec Executes a vendored binary/script.
global Allows running commands in the global composer dir ($COMPOSER_HOME).
help Displays help for a command
home Opens the package's repository URL or homepage in your browser.
info Shows information about packages.
init Creates a basic composer.json file in current directory.
install Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.
licenses Shows information about licenses of dependencies.
list Lists commands
outdated Shows a list of installed packages that have updates available, including their latest version.
prohibits Shows which packages prevent the given package from being installed.
remove Removes a package from the require or require-dev.
require Adds required packages to your composer.json and installs them.
run-script Runs the scripts defined in composer.json.
search Searches for packages.
self-update Updates composer.phar to the latest version.
selfupdate Updates composer.phar to the latest version.
show Shows information about packages.
status Shows a list of locally modified packages, for packages installed from source.
suggests Shows package suggestions.
update Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
upgrade Upgrades your dependencies to the latest version according to composer.json, and updates the composer.lock file.
validate Validates a composer.json and composer.lock.
why Shows which packages cause the given package to be installed.
why-not Shows which packages prevent the given package from being installed.
確認
$ composer -V
Composer version 1.6.5 2018-05-04 11:44:59
$ whereis composer
composer: /usr/local/bin/composer