Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

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

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

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
8
Help us understand the problem. What are the problem?