【PHP】 PHPBrewでPHP7をインストール
環境 CentOS 7.0 phpbrew 1.20.5 PHP 7.0.1
PHPBrewを使って、PHP7を試してみる。
事前準備
PHPBrewを使うには、php-cli
の5.3以上が必要になる。
$ sudo yum install -y php-cli
そして、他に必要になるモジュールを追加。
Apacheと連携するので、httpdも追加。
httpdをインストールすると、同時にapxs(apacheに拡張モジュールを、コンパイルしてくれるツール)もインストールされる。
$ sudo yum install -y httpd httpd-devel $ sudo yum install -y bzip2-devel $ sudo yum install -y libxml2-devel $ sudo yum install -y libxslt-devel
apxsでモジュールを追加しるため、以下のディレクトリにパーミッションを付与。
sudo chmod -R oga+rw /usr/lib64/httpd/modules sudo chmod -R oga+rw /etc/httpd/conf
そして、GitHubからPHPBrewを取得する。PHPBrewはphpr形式で提供されているので、ファイルを取ってくれば動作する。
cd /usr/local/bin sudo curl -L -O https://github.com/phpbrew/phpbrew/raw/master/phpbrew sudo chmod +x phpbrew
必要に応じて、. ~/.bash_profile
をしておく。
PHPBrewを使ったPHPのインストール
まず初期化する
$ phpbrew init
インストールできるPHPのバージョンを確認
$ phpbrew known ===> Fetching release list... [==================================================================] 1.31/1.31KB 100% 7.0: 7.0.1, 7.0.0 ... 5.6: 5.6.16, 5.6.15, 5.6.14, 5.6.13, 5.6.12, 5.6.11, 5.6.10, 5.6.9 ... 5.5: 5.5.30, 5.5.29, 5.5.28, 5.5.27, 5.5.26, 5.5.25, 5.5.24, 5.5.23 ... 5.4: 5.4.45, 5.4.44, 5.4.43, 5.4.42, 5.4.41, 5.4.40, 5.4.39, 5.4.38 ... 5.3: 5.3.29, 5.3.28, 5.3.27, 5.3.26, 5.3.25, 5.3.24 ... You can run `phpbrew update` to get a newer release list.
このバージョンを選択できる。今回は最新の7.0.1をインストール。
yum install
とかだと、php-pdo,php-mysqlもyum
で導入できるが、phpbrew
だと独自のオプションを選択し導入する。
選択可能なオプションはいかのように確認できる。
$ phpbrew variants Variants: all, apxs2, bcmath, bz2, calendar, cgi, cli, ctype, curl, dba, debug, dom, embed, exif, fileinfo, filter, fpm, ftp, gcov, gd, gettext, gmp, hash, iconv, icu, imap, inifile, inline, intl, ipc, ipv6, json, kerberos, libgcc, mbregex, mbstring, mcrypt, mhash, mysql, opcache, openssl, pcntl, pcre, pdo, pgsql, phar, phpdbg, posix, readline, session, soap, sockets, sqlite, static, tidy, tokenizer, wddx, xml, xml_all, xmlrpc, zip, zlib, zts Virtual variants: dbs: sqlite, mysql, pgsql, pdo mb: mbstring, mbregex neutral: default: bcmath, bz2, calendar, cli, ctype, dom, fileinfo, filter, ipc, json, mbregex, mbstring, mhash, mcrypt, pcntl, pcre, pdo, phar, posix, readline, sockets, tokenizer, xml, curl, openssl, zip everything: dba, ipv6, dom, calendar, wddx, static, inifile, inline, cli, fpm, ftp, filter, gcov, zts, json, hash, exif, mbstring, mbregex, libgcc, pdo, posix, embed, sockets, debug, phpdbg, zip, bcmath, fileinfo, ctype, cgi, soap, pcntl, intl, phar, session, tokenizer, opcache, imap, tidy, kerberos, xmlrpc, pcre, mhash, mcrypt, zlib, curl, readline, gd, icu, openssl, mysql, sqlite, pgsql, xml, xml_all, gettext, iconv, bz2, ipc, gmp Using variants to build PHP: phpbrew install php-5.3.10 +default phpbrew install php-5.3.10 +mysql +pdo phpbrew install php-5.3.10 +mysql +pdo +apxs2 phpbrew install php-5.3.10 +mysql +pdo +apxs2=/usr/bin/apxs2
今回はPDOとMYSQLを選択し、PHP7.0.1を使えるようにする。
$ phpbrew install 7.0.1 +pdo +mysql +apxs2=/usr/bin/apxs ===> phpbrew will now build 7.0.1 ===> Loading and resolving variants... Checking distribution checksum... Checksum matched: c999d29cb8861aa71574a11e8c635691 ===> Distribution file was successfully extracted, skipping... Found existing Makefile, running make clean to ensure everything will be rebuilt. You can append --no-clean option after the install command if you don't want to rebuild. ===> Running make clean: make -C /home/vagrant/.phpbrew/build/php-7.0.1 --quiet clean ===> Applying patch - apxs2 module version name ... Found existing build.log, renaming it to /home/vagrant/.phpbrew/build/php-7.0.1/build.log.1451999982 ===> Configuring 7.0.1... Use tail command to see what's going on: $ tail -F /home/vagrant/.phpbrew/build/php-7.0.1/build.log ===> Building... Build finished: 3.3 minutes. Installing... ---> Creating php-fpm.conf ---> Creating php.ini ---> Copying /home/vagrant/.phpbrew/build/php-7.0.1/php.ini-development Found existing /home/vagrant/.phpbrew/php/php-7.0.1/etc/php.ini. ---> Found date.timezone is not set, patching... Congratulations! Now you have PHP with 7.0.1 as php-7.0.1 To use the newly built PHP, try the line(s) below: $ phpbrew use php-7.0.1 Or you can use switch command to switch your default php to php-7.0.1: $ phpbrew switch php-7.0.1 Enjoy!
これでphp7.0.1がコンパイルされる。 現在PHPBrewで使えるバージョンは以下で確認
$ phpbrew list * (system) php-7.0.1
ここで以下のコマンドを打っておく
$ . ~/.phpbrew/bashrc
一時的にバージョンを切り替える場合は
$ phpbrew use 7.0.1
デフォルトを変更するなら
$ phpbrew switch 7.0.1
とする。
$ php -v PHP 7.0.1 (cli) (built: Jan 5 2016 23:15:33) ( NTS ) Copyright (c) 1997-2015 The PHP Group Zend Engine v3.0.0, Copyright (c) 1998-2015 Zend Technologies
Apacheと連携
特に特別な事はなし。
httpd.conf
に以下の行を追加。
<IfModule mime_module> # etc. AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule>
AddType~の2行を、
その後、httpdをrestartすれば完了。
【Vagrant】 apacheの設定方法
環境 CentOS 7.0 apache2.4.6
httpdのインストール、起動はVagrantに限らず、通常のCentOS7の手順と同じ。
$ sudo yum install -y httpd httpd-devel $ sudo systemctl start httpd
自動起動の設定をするなら、
$ sudo systemctl enable httpd.service
これで状態を確認すると、
sudo systemctl status httpd ● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2016-01-05 22:33:04 JST; 6min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 3066 (httpd) Status: "Total requests: 10; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─3066 /usr/sbin/httpd -DFOREGROUND ├─3067 /usr/sbin/httpd -DFOREGROUND ├─3068 /usr/sbin/httpd -DFOREGROUND ├─3069 /usr/sbin/httpd -DFOREGROUND ├─3070 /usr/sbin/httpd -DFOREGROUND ├─3071 /usr/sbin/httpd -DFOREGROUND └─3072 /usr/sbin/httpd -DFOREGROUND Jan 05 22:33:03 localhost.localdomain systemd[1]: Starting The Apache HTTP Server... Jan 05 22:33:04 localhost.localdomain httpd[3066]: AH00558: httpd: Could not reliably determine the server's fully qualifi...ssage Jan 05 22:33:04 localhost.localdomain systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
さてこれにアクセスできるようにするには、Vagrantfileの以下の行からコメントをはずせばよい。
config.vm.network "private_network", ip: "192.168.33.10"
これで、vagrant reload
し、192.168.33.10
にブラウザからアクセスすればよい。
【Node.js】 いつの間にかバージョン表記が変わってた
環境 CentOS 7.0 Node.js 5.3.0
Node.jsを最新版にしようと思って、最新版を調べたら、バージョンが5.3.0?
□ CentOS7.0にNode.js最新版をインストール - takafumi blog
のときは0.12.2とかだったのに。
で気が付いたんですが、Node.jsとio.jsが統合したんでしたね。
バージョンがio.jsを引き継いで、3から4として扱われたらしい。
□ JavaScriptプラットフォーム「Node.js v4.0.0」がリリース、io.jsと統合し、今後は定期的なリリースに移行:CodeZine(コードジン)
インストール方法は変わりなし。
【Vagrant】 プロビジョニングで環境を自動構築
環境 Vagrant 1.8.1 VirtualBox 5.0.12
プロビジョニングの実行タイミング
はじめてvagrant up
を行ったときに、実行される処理。
2回目以降は以下のようなメッセージが表示されている。
==> default: flag to force provisioning. Provisioners marked to run always will still run.
明示的に、プロビジョニングを実行する場合は
vagrant up --provision
vagrant reload --provision
とする。
プロビジョニングの書き方
1. Vagrantfileにインラインで書く
以下のように書く。
Vagrant.configure("2") do |config| config.vm.provision "shell", inline: <<-SHELL echo 'HELLO!' date yum insatall -y mysql-server SHELL end
以下のようにも書ける。
script = <<SCRIPT echo 'HELLO!' date yum insatall -y mysql-server SCRIPT Vagrant.configure("2") do |config| config.vm.provision :shell, :inline => script end
2. 別ファイルに書く
Vagrant.configure("2") do |config| config.vm.provision "shell", path: "provision.sh" end
pathの部分はホスト側(Windows)のパスになる。
ただし実行するファイル(provision.sh)内のパスは、ゲスト側(CentOS)のパスになる事に注意。
chefやansibleも同様に書ける。
と言う事で作ってみた。
最小限の構成だけど、完全に自動化しようとすると結構大変。
これで今後は、デスクトップPCとノートPCの環境が統一できるかな?
【Vagrant】 独自のboxを作成する
環境 Vagrant 1.8.1 VirtualBox 5.0.12
既存のVMからboxイメージを作成する
ホスト側から以下のようにする。
PS> vagrant package --base VMName --output Custom.box ==> VMName: Attempting graceful shutdown of VM... VMName: Guest communication could not be established! This is usually because VMName: SSH is not running, the authenticationinformation was changed, VMName: or some other networking issue. Vagrant will force halt, if VMName: capable. ==> VMName: Forcing shutdown of VM... ==> VMName: Clearing any previously set forwarded p orts... ==> VMName: Exporting VM... ==> VMName: Compressing package to: Custom.box
--base
はVirtualBox上の名前
--output
は新しいboxの名前
【参考】
Vagrant:package作成時「VM not created. Moving on…」をエラーが出たら | ログってなんぼ
--output
が未指定だと、package.box
になる
新しいboxファイルを、vagrantのboxに登録する
PS> vagrant box add NewBox Custom.box ==> box: Box file was not detected as metadata. Adding it directly... ==> box: Adding box 'NewBox' (v0) for provider: box: Unpacking necessary files from: file://Custom.box box: Progress: 100% (Rate: 461M/s, Estimated time remaining: --:--:--) ==> box: Successfully added box 'NewBox' (v0) for 'virtualbox'! PS> vagrant box list NewBox (virtualbox, 0) bento/centos-7.1 (virtualbox, 2.2.2)
となる。