Install PHP5.6 (Homebrew)
2017.01.26開発環境のPHPを5.3.3から5.6.29にバージョンアップさせた際の備忘録。
これまでHomebrewを使用してインストールしたPHP5.3.3を使用していたが、さすがに5.6系以上のものが依頼されるサーバーでのデフォルト環境となってきたため変更しました。
逆に言うとこれまでもう古くなってしまったPHP5.3系をデフォルトで使用しているレンタルサーバーなども存在したためここまでバージョンアップを引っ張っていました。
バージョン切り替えを行えるように設定すればそれで良いのだがそれはまた別の機会に。
最終的にPHPは5.6系に、MySQLは5.7系、Apacheは2.4系、PHPのモジュール関連では最低限必要なimagick、mcryptをPEARはMDB2、pager、HTTP_Request2、Mail_Queueをインストール。(ApacheはMacにデフォルトで用意されているものを使用)
Homebrew
PHP
MySQL
Apache
# Homebrew Update $ brew update Updated 1 tap (caskroom/cask). # Formula Upgrade # この作業は行わなくてもよい アップグレードしたいFormulaのみ個別に処理する方が混乱がない PHP70は後ほど削除 $ brew upgrade Updating Homebrew... ==> Upgrading 18 outdated packages, with result: (略),imagemagick 7.0.4-5, mysql 5.7.17, homebrew/php/php53 5.3.29, homebrew/php/php53-imagick 3.3.0, (略) : : Error: Cannot install homebrew/php/php53 because conflicting formulae are installed. php70: because different php versions install the same binaries. Please `brew unlink php70` before continuing. Unlinking removes a formula's symlinks from /usr/local. You can link the formula again after the install finishes. You can --force this install, but the build may fail or cause obscure side-effects in the resulting software. # PHP70をアンインストール $ brew uninstall php70 Uninstalling /usr/local/Cellar/php70/7.0.14... (332 files, 38.8M) $ rm -rf /usr/local/etc/php/7.0 # リポシトリを更新 $ brew tap homebrew/php Updating Homebrew... $ brew tap homebrew/dupes # PHP56のインストールオプションを確認 $ brew options php56 --with-cgi Enable building of the CGI executable (implies --without-fpm) --with-debug Compile with debugging symbols --with-enchant Build with enchant support --with-gmp Build with gmp support --with-homebrew-curl Include Curl support via Homebrew --with-homebrew-libressl Include LibreSSL instead of OpenSSL via Homebrew --with-homebrew-libxml2 Include Libxml2 support via Homebrew --with-homebrew-libxslt Include LibXSLT support via Homebrew --with-httpd22 Enable building of shared Apache 2.2 Handler module --with-httpd24 Enable building of shared Apache 2.4 Handler module --with-imap Include IMAP extension --with-libmysql Include (old-style) libmysql support instead of mysqlnd --with-mssql Include MSSQL-DB support --with-pdo-oci Include Oracle databases (requries ORACLE_HOME be set) --with-pear Build with PEAR --with-phpdbg Enable building of the phpdbg SAPI executable --with-postgresql Build with postgresql support --with-thread-safety Build with thread safety --without-bz2 Build without bz2 support --without-fpm Disable building of the fpm SAPI executable --without-ldap Build without LDAP support --without-legacy-mysql Do not include the deprecated mysql_ functions --without-mysql Remove MySQL/MariaDB support --without-pcntl Build without Process Control support --without-unixodbc Build without unixODBC support --HEAD Install HEAD version # PHP56をインストール MacOS 10.11.6 にインストールされている Apache は 2.4.18 PEAR と postgresql をオプション指定 # --with-httpd24 を付けないと /usr/local/Cellar/php56/5.6.29_5/libexec/apache2/libphp5.so が作成されないので注意 # インストール後、自分で httpd.confを修正するので --homebrew-apxs は付けない (勝手に設定ファイルをいじられたくない) $ brew install php56 --with-httpd24 --with-pear --with-postgresql ==> Installing php56 from homebrew/php ==> Tapping homebrew/apache Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-apache'... : : ==> Installing homebrew/php/php56 --with-postgresql --with-httpd24 --with-pear ==> Downloading https://php.net/get/php-5.6.29.tar.bz2/from/this/mirror Already downloaded: /Users/oldone/Library/Caches/Homebrew/php56-5.6.29 ==> ./configure --prefix=/usr/local/Cellar/php56/5.6.29 -- localstatedir=/usr/local/var --sysconfdir=/usr/local/etc/php/5.6 --with-config-file-path=/usr/lo ==> make ==> make install ==> /usr/local/Cellar/php56/5.6.29/bin/pear config-set php_ini /usr/local/etc/php/5.6/php.ini system ==> Caveats To enable PHP in Apache add the following to httpd.conf and restart Apache: LoadModule php5_module /usr/local/opt/php56/libexec/apache2/libphp5.so The php.ini file can be found in: /usr/local/etc/php/5.6/php.ini ✩✩✩✩ PEAR ✩✩✩✩ If PEAR complains about permissions, 'fix' the default PEAR permissions and config: chmod -R ug+w /usr/local/opt/php56/lib/php pear config-set php_ini /usr/local/etc/php/5.6/php.ini system ✩✩✩✩ Extensions ✩✩✩✩ If you are having issues with custom extension compiling, ensure that you are using the brew version, by placing /usr/local/bin before /usr/sbin in your PATH: PATH="/usr/local/bin:$PATH" PHP56 Extensions will always be compiled against this PHP. Please install them using --without-homebrew-php to enable compiling against system PHP. ✩✩✩✩ PHP CLI ✩✩✩✩ If you wish to swap the PHP you use on the command line, you should add the following to ~/.bashrc, ~/.zshrc, ~/.profile or your shell's equivalent configuration file: export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" ✩✩✩✩ FPM ✩✩✩✩ To launch php-fpm on startup: mkdir -p ~/Library/LaunchAgents cp /usr/local/opt/php56/homebrew.mxcl.php56.plist ~/Library/LaunchAgents/ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.php56.plist The control script is located at /usr/local/opt/php56/sbin/php56-fpm OS X 10.8 and newer come with php-fpm pre-installed, to ensure you are using the brew version you need to make sure /usr/local/sbin is before /usr/sbin in your PATH: PATH="/usr/local/sbin:$PATH" You may also need to edit the plist to use the correct "UserName". Please note that the plist was called 'homebrew-php.josegonzalez.php56.plist' in old versions of this formula. : : # 必要なモジュールをインストール(とりあえず mcrypt と imagick ) $ brew install php56-imagick php56-mcrypt Updating Homebrew... ==> Installing php56-imagick from homebrew/php ==> Downloading https://homebrew.bintray.com/bottles-php/php56-imagick-3.4.2.el_capitan.bottle.tar.gz : : # Homebrew からのインストールは終了
# PHP56 インストール時の表示の通り、PEARの設定、パーミッション変更 $ chmod -R ug+w /usr/local/opt/php56/lib/php $ pear config-set php_ini /usr/local/etc/php/5.6/php.ini # 初期インストール済みライブラリ確認 $ pear list Installed packages, channel pear.php.net: ========================================= Package Version State Archive_Tar 1.4.0 stable Console_Getopt 1.4.1 stable PEAR 1.10.1 stable Structures_Graph 1.1.1 stable XML_Util 1.3.0 stable $ pear channel-update pear.php.net Updating channel "pear.php.net" Channel "pear.php.net" is up to date $ pear list-upgrades pear.php.net Available Upgrades (stable): ========================================= Channel Package Local Remote Size pear.php.net Archive_Tar 1.4.0 (stable) 1.4.2 (stable) 21kB $ pear upgrade Archive_Tar $ pear install MDB2 $ pear install pager $ pear install HTTP_Request2 $ pear install Mail_Queue $ pear list-upgrades $ nano .bash_profile #Homebrew PHP Path #export PATH="$(brew --prefix homebrew/php/php53)/bin:$PATH" export PATH="$(brew --prefix homebrew/php/php56)/bin:$PATH" $ php -v PHP 5.6.29 (cli) (built: Jan 24 2017 16:15:22) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies $ php -m [PHP Modules] bcmath bz2 calendar Core ctype curl date dba dom ereg exif fileinfo filter ftp gd gettext hash iconv imagick json ldap libxml mbstring mcrypt mhash mysql mysqli mysqlnd odbc openssl pcntl pcre PDO pdo_mysql PDO_ODBC pdo_pgsql pdo_sqlite pgsql Phar posix readline Reflection session shmop SimpleXML soap sockets SPL sqlite3 standard sysvmsg sysvsem sysvshm tokenizer wddx xml xmlreader xmlrpc xmlwriter xsl zip zlib [Zend Modules]
$ mysql --version mysql Ver 14.14 Distrib 5.7.17, for osx10.11 (x86_64) using EditLine wrapper $ mysql_upgrade -u root -p Enter password: Checking if update is needed. Checking server version. Running queries to upgrade MySQL server. Checking system database. mysql.columns_priv OK mysql.db OK mysql.engine_cost OK mysql.event OK mysql.func OK mysql.general_log OK mysql.gtid_executed OK mysql.help_category OK mysql.help_keyword OK mysql.help_relation OK mysql.help_topic OK mysql.innodb_index_stats OK mysql.innodb_table_stats OK mysql.ndb_binlog_index OK mysql.plugin OK mysql.proc OK mysql.procs_priv OK mysql.proxies_priv OK mysql.server_cost OK mysql.servers OK mysql.slave_master_info OK mysql.slave_relay_log_info OK mysql.slave_worker_info OK mysql.slow_log OK mysql.tables_priv OK mysql.time_zone OK mysql.time_zone_leap_second OK mysql.time_zone_name OK mysql.time_zone_transition OK mysql.time_zone_transition_type OK mysql.user OK Upgrading the sys schema. Checking databases. : : Upgrade process completed successfully. Checking if update is needed. $ cp /usr/local/Cellar/mysql/5.6.21/my.cnf /usr/local/Cellar/mysql/5.7.17/my.cnf $ mysql.server restart Shutting down MySQL ..... SUCCESS! Starting MySQL ..... SUCCESS! $ ps ax | grep mysql 395 ?? S 0:00.03 /bin/sh /usr/local/opt/mysql/bin/mysqld_safe --bind-address=127.0.0.1 --datadir=/usr/local/var/mysql 543 ?? S 0:01.76 /usr/local/Cellar/mysql/5.7.17/bin/mysqld --basedir=/usr/local/Cellar/mysql/5.7.17 --datadir=/usr/local/var/mysql --plugin-dir=/usr/local/Cellar/mysql/5.7.17/lib/plugin --bind-address=127.0.0.1 --log-error=/usr/local/var/mysql/oldone-Mac-mini.local.err --pid-file=/usr/local/var/mysql/oldone-Mac-mini.local.pid 789 s000 S+ 0:00.01 grep mysql
$ sudo nano /etc/apache2/httpd.conf : : #LoadModule php5_module libexec/apache2/libphp5.so #LoadModule php5_module /usr/local/Cellar/php53/5.3.29/libexec/apache2/libphp5.so LoadModule php5_module /usr/local/Cellar/php56/5.6.29/libexec/apache2/libphp5.so : : $ which apachectl /usr/local/bin/apachectl $ sudo /usr/sbin/apachectl restart $ ps ax | grep httpd 557 ?? Ss 0:00.24 /usr/sbin/httpd -D FOREGROUND 576 ?? S 0:00.12 /usr/sbin/httpd -D FOREGROUND 610 ?? S 0:00.04 /usr/sbin/httpd -D FOREGROUND 611 ?? S 0:00.01 /usr/sbin/httpd -D FOREGROUND 612 ?? S 0:00.23 /usr/sbin/httpd -D FOREGROUND 614 ?? S 0:00.03 /usr/sbin/httpd -D FOREGROUND 615 ?? S 0:00.01 /usr/sbin/httpd -D FOREGROUND 616 ?? S 0:00.00 /usr/sbin/httpd -D FOREGROUND 617 ?? S 0:00.00 /usr/sbin/httpd -D FOREGROUND 795 s000 R+ 0:00.00 grep httpd