12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Mac OS X El CapitanにNginx + phpenv + php-build + php-fpmの環境を構築する手順

Last updated at Posted at 2016-05-24

phpenv

brew だとなぜかうまくいかない... (phpenvにパスが通らなかった)

gitからインストールするとうまくいくのでこちらから

git clone https://github.com/CHH/phpenv.git
phpenv/bin/phpenv-install.sh

例によって~/.bash_profileに追記

export PATH="/Users/your_name/.phpenv/bin:$PATH"
eval "$(phpenv init -)"

php-build

php-buildを~/.phpenvの中にインストール

git clone git://github.com/CHH/php-build.git $HOME/.phpenv/plugins/php-build

インストールしてパスを通す

cd $HOME/.phpenv/plugins/php-build
./install.sh

欲しいphpのバージョンをインストール & ビルド

php-build -i development 7.0.6 $HOME/.phpenv/versions/7.0.6

エラーがでる。

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
configure: WARNING: unrecognized options: --with-mysql
configure: WARNING: This bison version is not supported for regeneration of the Zend/PHP parsers (found: 2.3, min: 204, excluded: ).
configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
-----------------------------------------

libmcrypt?

brew reinstall libmcrypt

まだエラーがでる。

-----------------
|  BUILD ERROR  |
-----------------

Here are the last 10 lines from the log:

-----------------------------------------
/var/tmp/php-build/source/7.0.6/ext/date/php_date.c:3756:5: note: use function 'llabs' instead
                                abs((utc_offset % 60)));
                                ^~~
                                llabs
6 warnings generated.
/var/tmp/php-build/source/7.0.6/ext/openssl/openssl.c:44:10: fatal error: 'openssl/evp.h' file not found
#include <openssl/evp.h>
         ^
1 error generated.
make: *** [ext/openssl/openssl.lo] Error 1
-----------------------------------------

The full Log is available at '/tmp/php-build.7.0.6.20160524133129.log'.
[Warn]: Aborting build.

以下でシンボリックリンクの修正をして解決。

brew install openssl
brew install libxml2
brew link openssl --force
brew link libxml2 —-force

php-fpm

php-buildができればOK ~/.phpenv/versions/sbin/以下にバージョンごと実行ファイルができる。php-build便利。

.defaultファイルをコピー

cp ~/.phpenv/versions/7.0.6/etc/php-fpm.d/www.conf.default ~/.phpenv/versions/7.0.6/etc/php-fpm.d/www.conf
cp ~/.phpenv/versions/7.0.6/etc/php-fpm.conf.default ~/.phpenv/versions/7.0.6/etc/php-fpm.conf

php-fpm 起動

~/.phpenv/versions/7.0.6/sbin/php-fpm

nginx

brewでインストール

brew install nginx
brew update nginx

nginx.confには以下のようなサーバーディレクティブを追記

/usr/local/etc/nginx/nginx.conf

server {
        listen       1234;
        server_name  localhost;

        root         /var/www/html;

        location / {
            index        index.html;
        }
}

nginx 起動

nginx  # http://localhost:1234 → /var/www/html/index.html

参考記事

PHPバージョン管理のphpenvをMacにインストールで複数ver使う PHP5.6/PHP7
http://qiita.com/aoioooii/items/2263c79284c612c7d6ed

Mac OS X El Capitan上でphp-buildするメモ
http://qiita.com/hnw/items/62380e713d318906f0cd

phpenvでphpをインストールしている時にopensslエラーが出る場合の解決メモ
http://qiita.com/truffaz76/items/73613b86c0f8637dee59

nginx + php-fpm で設定したが index.php にアクセスするとNOT FOUND(404)になってしまう
http://blog.livedoor.jp/saba_nano/archives/28213171.html

12
8
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
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?