LAMP/LAPP環境の構築 on Ubuntu 10.10
LAMP(Linux + Apache + MySQL + PHP), LAPP(Linux + Apache + MySQL + PHP)環境が動くようにしてみます。
CentOSと比べるとapt-getで自動起動設定までしてくれるので楽です。
PostgreSQL
インストール
$ sudo apt-get install postgresql
configファイルは /etc/postgresql/8.4/main/ に配置されています。pg_hba.conf, postgresql.confなどを変更する場合はここを編集します。
/etc/postgresql/8.4/main/pg_hba.conf
/etc/postgresql/8.4/main/postgresql.conf
OS上のposrgresユーザーのパスワード設定
postgresはPostgreSQLの管理用ユーザーです。DBの作成、削除、ダンプ、リストアなどの操作を行うときはpostgresユーザーで実行します。
$ sudo passwd postgres 新しいUNIXパスワードを入力してください: 【パスワード】 新しいUNIX パスワードを再入力してください: 【パスワード】 passwd: パスワードは正しく更新されました
DB上のpostgresユーザーのパスワード設定
OS上のユーザーpostgresとは別に、DB上の管理者ユーザーとしてpostgresが設定されています。postgresユーザーの権限は強力で、操作ミスが他のDBに影響を及ぼすので、サービス毎にDBとそれを管理するユーザーを作ってそのDBだけに権限を与えるようにするのがベターです。
$ sudo su - postgres $ psql psql (8.4.7) "help" でヘルプを表示します. postgres=# alter user postgres with password 'パスワード'; ALTER ROLE postgres=# \q $ exit
動作確認
PostgreSQLに接続してDBの一覧を表示します。
$ sudo su - postgres $ psql -l データベース一覧 名前 | 所有者 | エンコーディング | 照合順序 | Ctype(変換演算子) | アクセス権 -----------+----------+------------------+------------+-------------------+----------------------- postgres | postgres | UTF8 | ja_JP.utf8 | ja_JP.utf8 | template0 | postgres | UTF8 | ja_JP.utf8 | ja_JP.utf8 | =c/postgres : postgres=CTc/postgres template1 | postgres | UTF8 | ja_JP.utf8 | ja_JP.utf8 | =c/postgres : postgres=CTc/postgres
MySQL
動作確認
MySQLに接続してDBの一覧を表示します。
$ mysql -u root -p Enter password: ******** mysql> show databases; +--------------------+ | Databases | +--------------------+ | information_schema | | mysql | +--------------------+ mysql> \q
Apache
インストール
$ sudo apt-get install apache2
動作確認
$ apache2 -v Server version: Apache/2.2.16 (Ubuntu) Server built: Nov 18 2010 21:17:29
PHP
インストール
phpと一緒にmysql, postgresql用のモジュールをインストールします。php-gd, php-pearなどをここで一緒に入れてもいいですし、必要な時に後から追加することもできます。
$ sudo apt-get install php5 php5-mysql php5-pgsql
動作確認
$ php -v PHP 5.3.3-1ubuntu9.3 with Suhosin-Patch (cli) (built: Jan 12 2011 16:08:14) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
Apache+PHP
設定
ディレクトリ指定のURLでindex.phpを優先的に表示するようにします。
$ sudo vi /etc/apache2/sites-available/default <Directory /var/www/> Options Indexes FollowSymLinks MultiViews DirectoryIndex index.php index.html (追加) AllowOverride None Order allow,deny allow from all </Directory>
設定の反映
configファイルをリロードします。
$ sudo service apache2 reload