LoginSignup
1
0

More than 5 years have passed since last update.

HomebrewでCakePHP環境構築〜Apache編

Last updated at Posted at 2018-02-03

httpd.confの設定

パスは/usr/local/etc/httpd/httpd.conf。早速編集する。

しかし前提となる知識が明らかに不足しているため、正直なところ途中から自分で何の作業をしているのか、わからなくなってきた。

以下のサイト様には大変お世話になった。それでもパス1つ違うだけで素人は慌ててしまう・・・

MacにHomebrewでPHP, Apache, MySQLを導入する

以下の内容を、記述したりコメントを外したりする。サーバーやドキュメントルートの設定は何となく理解できるが、途中から知識が怪しくなってくる。

Listen 80
ServerName localhost:80

下記のモジュールについての記述は、後に間違いだと判明する・・・

LoadModule php7_module /usr/local/opt/php71/libexec/apache2/libphp7.so #記述間違い

後半で説明するが、念のため正しい記述をここに載せておく。

LoadModule php7_module /usr/libexec/apache2/libphp7.so

まだ修正は続く。

DocumentRoot "/usr/local/var/www/htdocs"
<Directory "/usr/local/var/www/htdocs">
DirectoryIndex index.php index.html
AddType application/x-httpd-php .php
Include /usr/local/etc/httpd/extra/httpd-vhosts.conf

上記のInclude /usr/local/etc/httpd/extra/httpd-vhosts.confはバーチャルホストを利用するためのものらしい。バーチャルホストって何・・・?参考にリンクを貼っておく。

バーチャルホスト - Wikipedia

次は/usr/local/etc/httpd/extra/httpd-vhosts.confへ移動し、ファイルを編集する。最終的に、コメントされていない箇所は以下の記述だけになる。

<VirtualHost *:80>
  ServerName sample.local
  DocumentRoot /usr/local/var/www/htdocs
  DirectoryIndex index.php index.html
  <Directory "/usr/local/var/www/htdocs">
    AllowOverride All
    Allow from All
  </Directory>
</VirtualHost>

とにかく進む。

モジュールがおかしい

先ほどhttpd.confにphp71のモジュールlibphp7.soを記述したが、そこでエラーになる。なお、同箇所をコメントアウトすると正常に起動する。

$ sudo apachectl start
Password:
httpd: Syntax error on line 178 of /usr/local/etc/httpd/httpd.conf: Cannot load /usr/local/opt/php71/libexec/apache2/libphp7.so into server: dlopen(/usr/local/opt/php71/libexec/apache2/libphp7.so, 10): image not found

このモジュールだが、本来であればPHPインストール時にオプションで指定して入れられるものらしい。今回はモジュール単体でインストールする方法が見つけられなかったので、PHPを再インストールすることにした。

PHPの再インストール

まずはPHPインストール時のオプションを確認する。

$ brew options php71
--with-cgi
    Enable building of the CGI executable (implies --without-fpm)
--with-debug
    Compile with debugging symbols
--with-embed
    Compile with embed support (built as a static library)
--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-httpd
    Enable building of shared Apache 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
--with-webp
    Build with webp support
--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

今回必要なオプションはこれ。この環境構築も行き当たりばったりだが、こういうときに先を見据えていればよかったと後悔する。

--with-httpd
    Enable building of shared Apache Handler module

既存のPHPをアンインストール。強制的に実行する。

$ brew uninstall --ignore-dependencies php71
Uninstalling /usr/local/Cellar/php71/7.1.13_24... (349 files, 39.4MB)

そしてオプション付きで再インストールする。

$ brew install php71 --with-httpd
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (homebrew/core, homebrew/php).
==> New Formulae
libbitcoin-consensus
==> Updated Formulae
以下略

エラーメッセージと思しき表示もあったが、brew doctorの方が見やすいのでそちらをチェック。アドバイス通り、brew install php71を実行する。

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formula are missing dependencies.
You should `brew install` the missing dependencies:
  brew install php71

Run `brew missing` for more details.

$ brew install php71
==> Installing php71 from homebrew/php
==> Downloading https://homebrew.bintray.com/bottles-php/php71-7.1.13_24.high_si
Already downloaded: /Users/yuki/Library/Caches/Homebrew/php71-7.1.13_24.high_sierra.bottle.tar.gz
==> Pouring php71-7.1.13_24.high_sierra.bottle.tar.gz
==> Caveats
The php.ini file can be found in:
    /usr/local/etc/php/7.1/php.ini
以下略

今度は大丈夫。

$ brew doctor
Your system is ready to brew.

再びhttpd.confの設定

念のためモジュールの場所を確認する。

$ locate libphp7.so
/usr/libexec/apache2/libphp7.so

Σ(゚д゚lll)
そもそもモジュールの有無というより、場所の指定が問題だったのか・・・

正しいパスを設定後sudo apachectl startを実行すると、正常に起動した。

終了はsudo apachectl stopで。

$ sudo apachectl start
$ sudo apachectl stop

こちらもなんとか完了。

1
0
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
1
0