2010年11月

お次はperlをインストールします。

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

$ perl -v

This is perl, v5.8.9 built for darwin-2level

続いてmacportsの確認

$ port search perl
・・・
perl5 @5.8.9 (lang)
    Wrapper port for perl 5.x

perl5.10 @5.10.1 (lang)
    Perl 5.10.x - Practical Extraction and Report Language

perl5.12 @5.12.2 (lang)
    Perl 5.12.x - Practical Extraction and Report Language

perl5.8 @5.8.9 (lang)
    Perl 5.8.x - Practical Extraction and Report Language
・・・

とりあえず最新バージョンをインストールすることに。

関連モジュールの検索

$ port variants perl5.12
perl5.12 has the variants:
   dtrace: Build with DTrace probes
   mangle_names: mangle the installed names by appending -5.12 to avoid
                 conflicting with perl5.8 and perl5.10
   shared: Build shared perl library
   threads: Build with thread support
   universal: Build for multiple architectures

特にこれが必要!てのは無さそうなので、単体でインストールすることに。

$ sudo port install perl5.12
・・・
Error: Target org.macports.activate returned: Image error: /opt/local/bin/a2p is being used by the active perl5.8 port.  Please deactivate this port first, or use 'port -f activate perl5.12' to force the activation.
Log for perl5.12 is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_lang_perl5.12/main.log
Error: Status 1 encountered during processing.
To report a bug, see <http://guide.macports.org/#project.tickets>

なんかエラーでた。

perl5.8 が port を使用中なので、そいつを停止させるか perl5.12 が使うように指示を出してください(?)

!!! そういえば、phpをインストールしたときにperlも一緒にインストールされていたような・・・。

mac の開発環境構築 〜PHP〜

やっぱり。。

念のため、今までにインストールされたパッケージを確認。

$ port installed
The following ports are currently installed:
  apache-ant @1.8.1_0 (active)
  apache2 @2.2.16_0+preforkmpm
  apache2 @2.2.17_0+preforkmpm (active)
  apr @1.4.2_1 (active)
  apr-util @1.3.9_2 (active)
  autoconf @2.68_0 (active)
  autoconf213 @2.13_1 (active)
  automake @1.11.1_0 (active)
  bzip2 @1.0.6_0 (active)
  curl @7.21.2_1+ssl (active)
  curl-ca-bundle @7.21.2_0 (active)
  cyrus-sasl2 @2.1.23_3+kerberos (active)
  db46 @4.6.21_6 (active)
  expat @2.0.1_1 (active)
  freetype @2.4.3_0 (active)
  gawk @3.1.8_0 (active)
  gettext @0.18.1.1_2 (active)
  gperf @3.0.4_0 (active)
  gsed @4.2.1_0 (active)
  help2man @1.38.2_0 (active)
  jpeg @8b_0 (active)
  libiconv @1.13.1_0 (active)
  libidn @1.19_0 (active)
  libmcrypt @2.5.8_1 (active)
  libpng @1.2.44_0 (active)
  libtool @2.4_0 (active)
  libxml2 @2.7.7_0 (active)
  m4 @1.4.15_0 (active)
  mhash @0.9.9.9_0 (active)
  mysql5 @5.1.51_0 (active)
  mysql5-server @5.1.51_0 (active)
  ncurses @5.7_1 (active)
  ncursesw @5.7_1 (active)
  neon @0.29.5_0 (active)
  openssl @1.0.0a_0
  openssl @1.0.0a_1 (active)
  p5-locale-gettext @1.05_3 (active)
  pcre @8.10_0 (active)
  perl5 @5.8.9_0 (active)
  perl5.12 @5.12.2_0
  perl5.8 @5.8.9_3 (active)
  php5 @5.3.3_2+apache2+pear (active)
  php5-curl @5.3.3_0 (active)
  php5-gd @5.3.3_0 (active)
  php5-mbstring @5.3.3_0 (active)
  php5-mcrypt @5.3.3_0 (active)
  php5-mysql @5.3.3_0+mysqlnd (active)
  php5-sqlite @5.3.3_0 (active)
  php5-tidy @5.3.3_0 (active)
  php5-zip @5.3.3_0 (active)
  phpmyadmin @3.3.5.1_0 (active)
  pkgconfig @0.25_1 (active)
  readline @6.1.002_0 (active)
  serf @0.7.0_0 (active)
  sqlite3 @3.7.3_0 (active)
  subversion @1.6.13_0 (active)
  tidy @20090325_0 (active)
  zlib @1.2.5_0 (active)

perl5.12もちゃんとインストールされたけどactiveじゃないよ。ってことだね。

とりあえずOKにしておきましょう。5.12が必要になったらそのときにactiveにすればヨシ。

参考サイト:PerlをMacPortsからインストールする

いちいち長ったらしいパスから起動するのは面倒なので、エイリアスの設定をしておきましょう。

$  vi ~/.bash_profile

alias apache_start="sudo /opt/local/apache2/bin/apachectl start"
alias apache_stop="sudo /opt/local/apache2/bin/apachectl stop"
alias apache_restart="sudo /opt/local/apache2/bin/apachectl restart"

参考サイト:Snow LeopardなMacBookにMacPortsで開発環境入れ直し(Apache2/PHP5/MySQL5/PostgreSQL8.3)

続いてphpmyadminをインストール

$ port search phpmyadmin
phpmyadmin @3.3.5.1 (www, php, databases)
    A tool written in PHP intended to handle the administration of MySQL over
    the Web.

macportsの扱いにもそろそろ慣れてきましたね。

$ sudo port install phpmyadmin
・・・
A new configuration file has been created at /opt/local/www/phpmyadmin/config.inc.php.
Please refer to the phpMyAdmin documentation when editing this file,
an online version of which can be found at http://www.phpmyadmin.netdocumentation/Documentation.html#config
・・・

設定ファイルが作成されたので編集してください。と

デフォルトの設定ファイルをバックアップ

$ sudo cp /opt/local/www/phpmyadmin/config.inc.php /opt/local/www/phpmyadmin/config.inc.php.bak

設定ファイルを編集

$ sudo vi /opt/local/www/phpmyadmin/config.inc.php

// conneatタイプをsocketに変更
$cfg['Servers'][$i]['connect_type'] = 'socket';
// socket接続先を追加
$cfg['Servers'][$i]['socket'] = '/opt/local/var/run/mysql5/mysqld.sock';

Apacheに接続先を追加

<Directory /opt/local/www/phpmyadmin>
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
    Allow from all
</Directory>
Alias /phpMyAdmin /opt/local/www/phpmyadmin

apacheを再起動

$ sudo /opt/local/apache2/bin/apachectl restart

http://localhost/phpMyAdmin/ に接続。MySQLのID、passでログイン。OK^^v

参考サイト:MacPortsでphpMyAdminをインストール

PHPから使えるようにphp5-mysqlをインストール

$ sudo port install php5-mysql
・・・
###########################################################
# A startup item has been generated that will aid in
# starting apache2 with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load apache2
###########################################################
Note: apache2 installs files outside the common directory structure.
・・・

apache2をloadしてくださいとのこと。

$ sudo port load apache2
Password:
Error: Target org.macports.load returned: org.macports.apache2: Already loaded
Log for apache2 is at: /opt/local/var/macports/logs/_opt_local_var_macports_sources_rsync.macports.org_release_ports_www_apache2/main.log
Error: Status 1 encountered during processing.
To report a bug, see 

またまたエラー。もう入ってます。ですって。

php.iniのdefault_socketを設定します。

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

pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock
mysql.default_socket =/opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket =/opt/local/var/run/mysql5/mysqld.sock

apacheを再起動してphpinfoで確認。OK!

参考サイト:macportsでMac Snow LeopardにApache2 + PHP5 + MySQL5 を入れる

続いてMySQLをインストール。

まずはデフォルトのMySQLの確認

$ mysql -v
-bash: mysql: command not found
$ ps ax | grep mysql

あれ?デフォルトでMySQLは入ってなかったかな??

ではMacPortsでインストールできるMySQLバージョンの確認

$ port search mysql
・・・
mysql4 @4.1.22 (databases)
    Multithreaded SQL database server

mysql5 @5.1.51 (databases)
    Multithreaded SQL database server

mysql5-devel @5.5.2-m2 (databases)
    Multithreaded SQL database server

mysql5-server @5.1.51 (databases)
    Multithreaded SQL database server

mysql5-server-devel @5.5.2-m2 (databases)
    Multithreaded SQL database server
・・・

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

$ port variants mysql5-server
mysql5-server has no variants

mysql5-serverをインストール

$ sudo port install mysql5-server
・・・
###########################################################
# A startup item has been generated that will aid in
# starting mysql5-server with launchd. It is disabled
# by default. Execute the following command to start it,
# and to cause it to launch at startup:
#
# sudo port load mysql5-server
###########################################################
--->  Installing mysql5-server @5.1.51_0
******************************************************
* In order to setup the database, you might want to run
* sudo -u _mysql mysql_install_db5
* if this is a new install
******************************************************
・・・

mysql5-serverをloadしてください。といわれるので、いわれるまま叩いてみる。

$ sudo port load mysql5-server

お次もいわれるがまま

$ sudo -u _mysql mysql_install_db5
Installing MySQL system tables...
OK
Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin -u root -h macmini.local password 'new-password'

Alternatively you can run:
/opt/local/lib/mysql5/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /opt/local ; /opt/local/lib/mysql5/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /opt/local/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /opt/local/lib/mysql5/bin/mysqlbug script!

パスワードを設定してください。とのことです。

$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'
/opt/local/lib/mysql5/bin/mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/opt/local/var/run/mysql5/mysqld.sock' (2)'
Check that mysqld is running and that the socket: '/opt/local/var/run/mysql5/mysqld.sock' exists!

おっと?connectがつながらないですって!

とりあえず起動してみることに

$ sudo /opt/local/share/mysql5/mysql/mysql.server start
Password:
Starting MySQL
. SUCCESS! 

もいちどトライ

$ sudo /opt/local/lib/mysql5/bin/mysqladmin -u root password 'new-password'

今度はうまく通ったみたい。

ログインしてみる

$ /opt/local/lib/mysql5/bin/mysql -u root -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.51 Source distribution

Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

「mysql5」コマンドで操作できるみたい。

数学ガール

| コメント(0)
結城 浩
ソフトバンククリエイティブ
発売日:2007-06-27

久しぶりに数式を見てワクワクドキドキした。

数式から生まれるあらたな数式。

偉人たちが発明した方程式を自分で証明してみる。
証明できたときの達成感!!
とてもなつかしい感覚。

もいちど学生に戻りたい。って思った。