mac の開発環境構築 〜PHP〜

方針

apacheが入りましたので、お次は私にとって使用頻度が最も高いPHPをインストールします。

バージョンの確認

まずはデフォルトのPHPバージョンの確認

$ php -v
PHP 5.3.2 (cli) (built: Aug  7 2010 00:04:41) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

portsの確認

次にMacPortsでインストールできるPHPバージョンの確認

$ port search php
・・・
php4 @4.4.9 (lang, php, www)
    PHP: Hypertext Preprocessor

php5 @5.3.3 (lang, php, www)
    PHP: Hypertext Preprocessor
・・・

インストール時に指定できる variants を確認

$ port variants php5
php5 has the variants:
   apache: Add Apache 1 web server module
     * conflicts with apache2 no_web
[+]apache2: Add Apache 2.2 web server module
     * conflicts with apache no_web
   debug: Enable debug support (useful to analyze a PHP-related core dump)
   fastcgi: Add FastCGI web server binary
     * conflicts with no_web
   gmp: Obsolete; install php5-gmp port instead
   imap: Obsolete; install php5-imap port instead
   ipc: Add semaphore, shared memory and IPC functions
   macports_snmp: Obsolete; install php5-snmp port instead
   mssql: Obsolete; install php5-mssql port instead
   mysql4: Obsolete; install php5-mysql port instead
   mysql5: Obsolete; install php5-mysql port instead
   mysqlnd: Obsolete; install php5-mysql port instead
   no_web: Don't include any web server support
     * conflicts with apache apache2 fastcgi
   oracle: Obsolete; install php5-oracle port instead
   pcntl: Obsolete; install php5-pcntl port instead
   pear: Add PEAR
   postgresql82: Obsolete; install php5-postgresql port instead
   postgresql83: Obsolete; install php5-postgresql port instead
   pspell: Obsolete; install php5-pspell port instead
   snmp: Obsolete; install php5-snmp port instead
   sockets: Obsolete; install php5-sockets port instead
   sqlite: Obsolete; install php5-sqlite port instead
   suhosin: Add Suhosin patch
   tidy: Obsolete; install php5-tidy port instead
   universal: Build for multiple architectures

ほとんど「Obsolete」になっていてもう使えないもよう。代わりに php5-**** でインストールする必要があるみたいです。

PHPインストール

とりあえず、+apache2 と +pear だけ一緒にインストールしましょう。

$  sudo port install php5 +apache2 +pear

インストールの最後に、次のような指示がきました。

To customize php, copy
/opt/local/etc/php5/php.ini-development (if this is a development server) or
/opt/local/etc/php5/php.ini-production (if this is a production server) to
/opt/local/etc/php5/php.ini and then make changes.

If this is your first install, you need to activate PHP in your web server.

To enable PHP in Apache, run
  cd /opt/local/apache2/modules
  /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so

php.iniの作成

指示に従ってまずはphp.iniファイルを作成します。

$ sudo cp /opt/local/etc/php5/php.ini-development /opt/local/etc/php5/php.ini

apacheにPHPを追加

$ cd /opt/local/apache2/modules
$ /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
[activating module `php5' in /opt/local/apache2/conf/httpd.conf]
unable to open configuration file

!!sudoをつけ忘れたw 直接設定ファイルを編集することに。

phpモジュールの読み込みを追加

$ sudo vi /opt/local/apache2/conf/httpd.conf

# phpモジュールの読み込み
LoadModule php5_module modules/libphp5.so

# mod_php.confの読み込み
Include conf/extra/mod_php.conf

index.php を有効に

$ sudo vi /opt/local/apache2/conf/httpd.conf

#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
<IfModule dir_module>
    # DirectoryIndex index.html
    DirectoryIndex index.php index.html index.html.var
</IfModule>

バージョンの確認

インストールされたPHPのバージョン確認も忘れずに。(ターミナル再起動してね)

$ php -v
PHP 5.3.3 (cli) (built: Oct 26 2010 17:02:06) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

date.timezoneを設定

phpinfo で確認するとdate関数でエラーが表示されていたのでphp.ini の date.timezone を以下のように設定します。

$ sudo vi /opt/local/etc/php5/php.ini 

date.timezone = Asia/Tokyo

参考サイト:Mac OS X(Snow Leopard)のMacPortsでApache2, PHP5, MySQL5をインストールし直した

インストールログ

$  sudo port install php5 +apache2 +pear
Password:
--->  Computing dependencies for php5
--->  Dependencies to be installed: autoconf213 gawk m4 perl5 perl5.8 gsed libtool automake autoconf help2man p5-locale-gettext libxml2 mhash pkgconfig
--->  Fetching gawk
--->  Attempting to fetch gawk-3.1.8.tar.bz2 from ftp://ftp.dti.ad.jp/pub/GNU/gawk
--->  Verifying checksum(s) for gawk
--->  Extracting gawk
--->  Configuring gawk
--->  Building gawk
--->  Staging gawk into destroot
--->  Installing gawk @3.1.8_0
--->  Activating gawk @3.1.8_0
--->  Cleaning gawk
--->  Fetching m4
--->  Attempting to fetch m4-1.4.15.tar.bz2 from ftp://ftp.dti.ad.jp/pub/GNU/m4
--->  Verifying checksum(s) for m4
--->  Extracting m4
--->  Configuring m4
--->  Building m4
--->  Staging m4 into destroot
--->  Installing m4 @1.4.15_0
--->  Activating m4 @1.4.15_0
--->  Cleaning m4
--->  Fetching perl5.8
--->  Attempting to fetch perl-5.8.9.tar.bz2 from http://distfiles.macports.org/perl5.8
--->  Verifying checksum(s) for perl5.8
--->  Extracting perl5.8
--->  Applying patches to perl5.8
--->  Configuring perl5.8
--->  Building perl5.8
--->  Staging perl5.8 into destroot
--->  Installing perl5.8 @5.8.9_3
--->  Activating perl5.8 @5.8.9_3
--->  Cleaning perl5.8
--->  Fetching perl5
--->  Verifying checksum(s) for perl5
--->  Extracting perl5
--->  Configuring perl5
--->  Building perl5
--->  Staging perl5 into destroot
--->  Installing perl5 @5.8.9_0
--->  Activating perl5 @5.8.9_0
--->  Cleaning perl5
--->  Fetching autoconf213
--->  Attempting to fetch autoconf-2.13.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/autoconf
--->  Verifying checksum(s) for autoconf213
--->  Extracting autoconf213
--->  Configuring autoconf213
--->  Building autoconf213
--->  Staging autoconf213 into destroot
--->  Installing autoconf213 @2.13_1
--->  Activating autoconf213 @2.13_1
--->  Cleaning autoconf213
--->  Fetching gsed
--->  Attempting to fetch sed-4.2.1.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/sed
--->  Verifying checksum(s) for gsed
--->  Extracting gsed
--->  Configuring gsed
--->  Building gsed
--->  Staging gsed into destroot
--->  Installing gsed @4.2.1_0
--->  Activating gsed @4.2.1_0
--->  Cleaning gsed
--->  Fetching p5-locale-gettext
--->  Attempting to fetch gettext-1.05.tar.gz from ftp://ftp.cpan.org/pub/CPAN/modules/by-module/Locale
--->  Verifying checksum(s) for p5-locale-gettext
--->  Extracting p5-locale-gettext
--->  Applying patches to p5-locale-gettext
--->  Configuring p5-locale-gettext
--->  Building p5-locale-gettext
--->  Staging p5-locale-gettext into destroot
--->  Installing p5-locale-gettext @1.05_3
--->  Activating p5-locale-gettext @1.05_3
--->  Cleaning p5-locale-gettext
--->  Fetching help2man
--->  Attempting to fetch help2man-1.38.2.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/help2man
--->  Verifying checksum(s) for help2man
--->  Extracting help2man
--->  Configuring help2man
--->  Building help2man
--->  Staging help2man into destroot
--->  Installing help2man @1.38.2_0
--->  Activating help2man @1.38.2_0
--->  Cleaning help2man
--->  Fetching autoconf
--->  Attempting to fetch autoconf-2.68.tar.bz2 from ftp://ftp.dti.ad.jp/pub/GNU/autoconf
--->  Attempting to fetch autoconf-2.68.tar.bz2 from http://distfiles.macports.org/autoconf
--->  Verifying checksum(s) for autoconf
--->  Extracting autoconf
--->  Configuring autoconf
--->  Building autoconf
--->  Staging autoconf into destroot
--->  Installing autoconf @2.68_0
--->  Activating autoconf @2.68_0
--->  Cleaning autoconf
--->  Fetching automake
--->  Attempting to fetch automake-1.11.1.tar.bz2 from ftp://ftp.dti.ad.jp/pub/GNU/automake
--->  Verifying checksum(s) for automake
--->  Extracting automake
--->  Configuring automake
--->  Building automake
--->  Staging automake into destroot
--->  Installing automake @1.11.1_0
--->  Activating automake @1.11.1_0
--->  Cleaning automake
--->  Fetching libtool
--->  Attempting to fetch libtool-2.4.tar.gz from ftp://ftp.dti.ad.jp/pub/GNU/libtool
--->  Attempting to fetch libtool-2.4.tar.gz from http://distfiles.macports.org/libtool
--->  Verifying checksum(s) for libtool
--->  Extracting libtool
--->  Configuring libtool
--->  Building libtool
--->  Staging libtool into destroot
--->  Installing libtool @2.4_0
--->  Activating libtool @2.4_0
--->  Cleaning libtool
--->  Fetching libxml2
--->  Attempting to fetch libxml2-2.7.7.tar.gz from http://distfiles.macports.org/libxml2
--->  Verifying checksum(s) for libxml2
--->  Extracting libxml2
--->  Configuring libxml2
--->  Building libxml2
--->  Staging libxml2 into destroot
--->  Installing libxml2 @2.7.7_0
--->  Activating libxml2 @2.7.7_0
--->  Cleaning libxml2
--->  Fetching mhash
--->  Attempting to fetch mhash-0.9.9.9.tar.bz2 from http://jaist.dl.sourceforge.net/mhash
--->  Verifying checksum(s) for mhash
--->  Extracting mhash
--->  Configuring mhash
--->  Building mhash
--->  Staging mhash into destroot
--->  Installing mhash @0.9.9.9_0
--->  Activating mhash @0.9.9.9_0
--->  Cleaning mhash
--->  Fetching pkgconfig
--->  Attempting to fetch pkg-config-0.25.tar.gz from http://distfiles.macports.org/pkgconfig
--->  Verifying checksum(s) for pkgconfig
--->  Extracting pkgconfig
--->  Applying patches to pkgconfig
--->  Configuring pkgconfig
--->  Building pkgconfig
--->  Staging pkgconfig into destroot
--->  Installing pkgconfig @0.25_1
--->  Activating pkgconfig @0.25_1
--->  Cleaning pkgconfig
--->  Fetching php5
--->  Attempting to fetch php-5.3.3.tar.bz2 from http://www.php.net/distributions/
--->  Verifying checksum(s) for php5
--->  Extracting php5
--->  Applying patches to php5
--->  Configuring php5
--->  Building php5
--->  Staging php5 into destroot
Note: php5 installs files outside the common directory structure.
--->  Installing php5 @5.3.3_2+apache2+pear
--->  Activating php5 @5.3.3_2+apache2+pear
To customize php, copy
/opt/local/etc/php5/php.ini-development (if this is a development server) or
/opt/local/etc/php5/php.ini-production (if this is a production server) to
/opt/local/etc/php5/php.ini and then make changes.

If this is your first install, you need to activate PHP in your web server.

To enable PHP in Apache, run
  cd /opt/local/apache2/modules
  /opt/local/apache2/bin/apxs -a -e -n "php5" libphp5.so
--->  Cleaning php5

あれっ? perl も入ったのかな??

投稿日:

ページのトップへ戻る