Archive for the ‘MySQL’ Category

3月
29

今回はLAMP環境構築作業の続きでMySQLの設定を行っていきます。

MySQLの設定ファイルを変更します。

MySQLの設定ファイル変更
[root@centos ~]# vi /etc/my.cnf
viエディタが起動するので設定ファイルを変更します。
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
user=mysql
# Default to using old password format for compatibility with mysql 3.x
# clients (those using the mysqlclient10 compatibility package).
old_passwords=1
MySQLの文字コードをUTF-8に変更します
default-character-set = utf8

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

MySQLクライアントの文字コードをUTF-8に変更します
[mysql]
default-character-set = utf8

内容を保存しviエディタを終了します

MySQLのサービス起動と自動起動の設定をします。

MySQLを起動します
[root@centos ~]# /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中: 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:
/usr/bin/mysqladmin -u root password ‘new-password’
/usr/bin/mysqladmin -u root -h centos.sa-sa-ki.jp password ‘new-password’
See the manual for more instructions.
You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

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

Please report any problems with the /usr/bin/mysqlbug script!

The latest information about MySQL is available on the web at
http://www.mysql.com
Support MySQL by buying support/licenses at http://shop.mysql.com
[ OK ]
MySQL を起動中: [ OK ]

OS再起動時にMySQLを自動起動するようにします
[root@centos ~]# chkconfig mysqld on
[root@centos ~]# chkconfig –list | grep mysqld
mysqld 0:off 1:off 2:on 3:on 4:on 5:on 6:off

MySQLのrootユーザにパスワード設定
MySQL起動時にMySQLのrootユーザにパスワードを設定するよう指示が表示されていたのでパスワードを設定します。

MySQLサーバーへrootユーザでログインします
[root@centos ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: x.x.xx Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

MySQLのユーザ、パスワードを確認
mysql> select user,host,password from mysql.user;
+——+——————–+———-+
| user | host | password |
+——+——————–+———-+
| root | localhost | |
| root | centos.sa-sa-ki.jp | |
| root | 127.0.0.1 | |
+——+——————–+———-+
3 rows in set (0.00 sec)

MySQLに接続する時のホスト名がlocalhost、centos.sa-sa-ki.jp、127.0.0.1でユーザ名がrootのパスワードが未登録な事が確認できます。
これら全てにパスワードを設定していきます。

ホスト名がlocalhostのrootユーザにパスワード設定します
mysql> set password for root@localhost=password(’rootパスワード’);
Query OK, 0 rows affected (0.00 sec)

ホスト名がcentos.sa-sa-ki.jpのrootユーザにパスワード設定します
mysql> set password for root@”centos.sa-sa-ki.jp”=password(’rootパスワード’);
Query OK, 0 rows affected (0.00 sec)

ホスト名が127.0.0.1のrootユーザにパスワード設定します
mysql> set password for root@127.0.0.1=password(’rootパスワード’);
Query OK, 0 rows affected (0.00 sec)

MySQLのユーザ、パスワードを再確認します
mysql> select user,host,password from mysql.user;
+——+——————–+——————+
| user | host | password |
+——+——————–+——————+
| root | localhost | ++++++++++++++++ |
| root | centos.sa-sa-ki.jp | ++++++++++++++++ |
| root | 127.0.0.1 | ++++++++++++++++ |
+——+——————–+——————+
3 rows in set (0.00 sec)

MySQLに接続する時のホスト名がlocalhost、centos.sa-sa-ki.jp、127.0.0.1でユーザ名がrootのパスワードが設定された事が確認できました。

MySQLからログアウトします。
mysql> exit
Bye

ログイン確認
パスワードの設定が完了したので、ログインを確認していきます。

ホスト名がlocalhostのrootユーザでパスワードなしでログイン施行
[root@centos ~]# mysql -u root -h localhost
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)
ホスト名がlocalhostのrootユーザでパスワードなしでMySQLサーバーへログインできないことが確認できました。
同様にホスト名centos.sa-sa-ki.jpや127.0.0.1の場合も試してみます。

ホスト名がcentos.sa-sa-ki.jpのrootユーザでパスワードなしでログイン施行
[root@centos ~]# mysql -u root -h ‘centos.sa-sa-ki.jp’
ERROR 1130 (00000): Host ’sa-sa-ki.jp’ is not allowed to connect to this MySQL server

ホスト名が127.0.0.1のrootユーザでパスワードなしでログイン施行
[root@centos ~]# mysql -u root -h 127.0.0.1
ERROR 1045 (28000): Access denied for user ‘root’@'localhost’ (using password: NO)

あれ?
ホスト名centos.sa-sa-ki.jpの場合だけエラーメッセージが違いますね。
どうやらDNSサーバーで名前解決すると外部からの接続と認識して外部接続を許可する権限を付与しないとダメなようです。
/etc/hostsにcentos.sa-sa-ki.jpを追加すると他と同じメッセージになったのでひとまずよしとします。

次にパスワードを入力してMySQLにログインできるか確認します。

ホスト名がlocalhostのrootユーザでパスワードありでログイン施行
[root@centos ~]# mysql -u root -h localhost -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 21
Server version: x.x.xx Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

接続できたのでログアウトします。
mysql> exit
Bye

同様にホスト名centos.sa-sa-ki.jpや127.0.0.1の場合も試してみます。
ホスト名がcentos.sa-sa-ki.jpのrootユーザでパスワードありでログイン施行
[root@centos ~]# mysql -u root -h ‘centos.sa-sa-ki.jp’ -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22
Server version: x.x.xx Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

接続できたのでログアウトします。
mysql> exit
Bye

ホスト名が127.0.0.1のrootユーザでパスワードありでログイン施行
[root@centos ~]# mysql -u root -h 127.0.0.1 -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: x.x.xx Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

接続できたのでログアウトします。
mysql> exit
Bye

どのパターンもパスワード認証できました。

testデータベース削除
MySQLにはデフォルトでtestという名前のデータベースが作成されていますが、不要なので削除します。

MySQLへrootでログインします
[root@centos ~]# mysql -u root -h localhost -p
Enter password: 設定したrootユーザのパスワードを入力
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 24
Server version: x.x.xx Source distribution

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

登録データベースを確認します
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
| test |
+——————–+
3 rows in set (0.00 sec)

testデータベースを削除します
mysql> drop database test;
Query OK, 0 rows affected (0.00 sec)

再度登録データベースを確認します
mysql> show databases;
+——————–+
| Database |
+——————–+
| information_schema |
| mysql |
+——————–+
2 rows in set (0.00 sec)

testデータベースが削除されている事が確認できました

mysql> exit
Bye

MySQLの初期設定は終了です。
これでデータベースと連携したホームページ作りが可能になります。

なおMySQLを使ったシステムを作る場合はライセンスに関して注意が必要です。
MySQLにはGNU General Public License (一般的には「GPL」と呼ばれます) と商用ライセンスがあります。
GPLは無償でMySQLを使ったシステムを構築できる代わりにソースコードを公開する必要があり、他のユーザはそれを自由に改変、統合、頒布することができます。
商用ライセンスは有償ですがMySQLを使ったシステムのソースコードを公開する必要はありません。

ということで、MySQLを使ったシステムを作る場合はライセンスに留意する必要がありますね。

■ 参考サイト ■
データベースサーバー構築(MySQL) – CentOSで自宅サーバー構築
MySQL :: ライセンスに関する FAQ

————————————————————————————————–
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その13 CentOS 5.2 にLAMP環境構築(Apache、PHP編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その2 CentOS 5.2 をインストールする
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その1 導入を検討する

3月
28

今回はApache、PHP、MySQLをインストールしてLAMP環境を構築します。
LAMP環境の説明はflashcast:フリーで働くITエンジニア集団のブログ: ubuntu 8.10にApache、PHP、MySQLをインストールしてLAMP環境を構築するを参照ください。

Apache、PHP、MySQLをインストールします

ログイン後、rootユーザにスイッチします
[centos@centos ~]$ su -
パスワード: rootユーザーのパスワード

Apache、PHP、MySQLをインストールします
[root@centos ~]# yum -y install httpd php php-mbstring mod_ssl mysql-server php-mysql
Loading “priorities” plugin
Loading “fastestmirror” plugin
Loading mirror speeds from cached hostfile
* base: ftp.iij.ad.jp
* updates: ftp.iij.ad.jp
* addons: ftp.iij.ad.jp
* extras: ftp.iij.ad.jp
0 packages excluded due to repository priority protections
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
–> Running transaction check
—> Package php-mbstring.i386 0:x.x.x-xx.xxx_x.x set to be updated
–> Processing Dependency: php-common = x.x.x-xx.xxx_x.x for package: php-mbstring
—> Package mysql-server.i386 0:x.x.xx-x.xxx set to be updated
–> Processing Dependency: libmysqlclient.so.15(libmysqlclient_15) for package: mysql-server
–> Processing Dependency: perl-DBI for package: mysql-server
–> Processing Dependency: perl
-DBD-MySQL for package: mysql-server
–> Processing Dependency: perl(DBI) for package: mysql-server
–> Processing Dependency: libmysqlclient_r.so.15(libmysqlclient_15) for package: mysql-server
–> Processing Dependency: libmysqlclient_r.so.15 for package: mysql-server
–> Processing Dependency: mysql = x.x.xx-x.xxx for package: mysql-server
–> Processing Dependency: libmysqlclient.so.15 for package: mysql-server
—> Package httpd.i386 0:x.x.x-xx.xxx_x.centos.4 set to be updated
filelists.xml.gz 100% |=========================| 2.8 MB 00:00
filelists.xml.gz 100% |=========================| 2.7 MB 00:00
filelists.xml.gz 100% |=========================| 133 kB 00:00
filelists.xml.gz 100% |=========================| 150 B 00:00
—> Package php-mysql.i386 0:x.x.x-xx.xxx_x.x set to be updated
–> Processing Dependency: php-pdo for package: php-mysql
—> Package php.i386 0:x.x.x-xx.xxx_x.x set to be updated
–> Processing Dependency: php-cli = x.x.x-xx.xxx_x.x for package: php
—> Package mod_ssl.i386 1:x.x.x-xx.xxx_x.centos.4 set to be updated
–> Processing Dependency: libdistcache.so.1 for package: mod_ssl
–> Processing Dependency: libnal.so.1 for package: mod_ssl
–> Running transaction check
—> Package distcache.i386 0:x.x.x-xx.x set to be updated
—> Package php-cli.i386 0:x.x.x-xx.xxx_x.x set to be updated
—> Package perl-DBI.i386 0:x.xx-x.xxx set to be updated
—> Package php-pdo.i386 0:x.x.x-xx.xxx_x.x set to be updated
—> Package php-common.i386 0:x.x.x-xx.xxx_x.x set to be updated
—> Package perl-DBD-MySQL.i386 0:x.xxxx-x.xxx set to be updated
—> Package mysql.i386 0:x.x.xx-x.xxx set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

=============================================================================
Package Arch Version Repository Size
=============================================================================
Installing:
mod_ssl i386 1:x.x.x-xx.xxx_x.centos.4 updates 85 k
mysql-server i386 x.x.xx-x.xxx base 9.7 M
php i386 x.x.x-xx.xxx_x.x updates 1.1 M
php-mbstring i386 x.x.x-xx.xxx_x.x updates 969 k
php-mysql i386 x.x.x-xx.xxx_x.x updates 84 k
Installing for dependencies:
distcache i386 x.x.x-xx.x base 119 k
httpd i386 x.x.x-xx.xxx_x.centos.4 updates 1.1 M
mysql i386 x.x.xx-x.xxx base 4.1 M
perl-DBD-MySQL i386 x.xxxx-x.xxx base 147 k
perl-DBI i386 x.xx-x.xxx base 605 k
php-cli i386 x.x.x-xx.xxx_x.x updates 2.1 M
php-common i386 x.x.x-xx.xxx_x.x updates 154 k
php-pdo i386 x.x.x-xx.xxx_x.x updates 62 k

Transaction Summary
=============================================================================
Install 13 Package(s)
Update 0 Package(s)
Remove 0 Package(s)

Total download size: 20 M
Downloading Packages:
(1/13): mod_ssl-x.x.x-xx. 100% |=========================| 85 kB 00:00
(2/13): php-x.x.x-xx.xxx_ 100% |=========================| 1.1 MB 00:00
(3/13): mysql-x.x.xx-x.xx 100% |=========================| 4.1 MB 00:00
(4/13): php-mysql-x.x.x-x 100% |=========================| 84 kB 00:00
(5/13): perl-DBD-MySQL-x. 100% |=========================| 147 kB 00:00
(6/13): httpd-x.x.x-xx.xx 100% |=========================| 1.1 MB 00:00
(7/13): mysql-server-x.x. 100% |=========================| 9.7 MB 00:02
(8/13): php-common-x.x.x- 100% |=========================| 154 kB 00:00
(9/13): php-mbstring-x.x. 100% |=========================| 969 kB 00:00
(10/13): php-pdo-x.x.x-xx 100% |=========================| 62 kB 00:00
(11/13): perl-DBI-x.xx-x. 100% |=========================| 605 kB 00:00
(12/13): php-cli-x.x.x-xx 100% |=========================| 2.1 MB 00:00
(13/13): distcache-x.x.x- 100% |=========================| 119 kB 00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing: php-common ####################### [ 1/13]
Installing: perl-DBI ####################### [ 2/13]
Installing: mysql ####################### [ 3/13]
Installing: httpd ####################### [ 4/13]
Installing: perl-DBD-MySQL ####################### [ 5/13]
Installing: php-cli ####################### [ 6/13]
Installing: php-pdo ####################### [ 7/13]
Installing: distcache ####################### [ 8/13]
Installing: php-mbstring ####################### [ 9/13]
Installing: mysql-server ####################### [10/13]
Installing: php-mysql ####################### [11/13]
Installing: php ####################### [12/13]
Installing: mod_ssl ####################### [13/13]

Installed: mod_ssl.i386 1:x.x.x-xx.xxx_x.centos.4 mysql-server.i386 0:x.x.xx-x.xxx php.i386 0:x.x.x-xx.xxx_x.x php-mbstring.i386 0:x.x.x-xx.xxx_x.x php-mysql.i386 0:x.x.x-xx.xxx_x.x
Dependency Installed: distcache.i386 0:x.x.x-xx.x httpd.i386 0:x.x.x-xx.xxx_x.centos.4 mysql.i386 0:x.x.xx-x.xxx perl-DBD-MySQL.i386 0:x.xxxx-x.xxx perl-DBI.i386 0:x.xx-x.xxx php-cli.i386 0:x.x.x-xx.xxx_x.x php-common.i386 0:x.x.x-xx.xxx_x.x php-pdo.i386 0:x.x.x-xx.xxx_x.x
Complete!

Apacheの設定ファイルを変更します。

Apacheの設定ファイル変更
[root@centos ~]# vi /etc/httpd/conf/httpd.conf
viエディタが起動するので設定ファイルを変更します。
設定ファイルが大きいので設定箇所のみピックアップしています。

#
# Don’t give away too much information about all the subcomponents
# we are running. Comment out this line if you don’t mind remote sites
# finding out what major optional modules you are running
HTTPヘッダーやエラーページにApacheのバージョンやOSの情報が表示されないようにOS から Prod に変更
ServerTokens Prod

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed. This address appears on some server-generated pages, such
# as error documents. e.g. admin@your-domain.com
#
管理者メールアドレスを変更します
ServerAdmin centos@sa-sa-ki.jp

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work. See also the UseCanonicalName directive.
#
# If your host doesn’t have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make
# redirections work in a sensible way.
#
先頭の#を取ってコメントを解除し、サーバー名を変更します
ServerName www.sa-sa-ki.jp:80

#
# Each directory to which Apache has access can be configured with respect
# to which services and features are allowed and/or disabled in that
# directory (and its subdirectories).
#
# First, we configure the “default” to be a very restrictive set of
# features.
#
<Directory />
  FollowSymLinksからNoneに変更してオプションを無効にします
  Options None
  AllowOverride None
  全てのアクセスを拒否します
  Order deny,allow
  Deny from all

</Directory>

<Directory “/var/www/html”>

#
# Possible values for the Options directive are “None”, “All”,
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that “MultiViews” must be named *explicitly* — “Options All”
# doesn’t give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
  IndexesからExecCGIに変更してCGIスクリプトの実行を許可しドキュメントルートのファイル一覧を表示しないようにします
  Options ExecCGI FollowSymLinks

#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be “All”, “None”, or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
  NoneからAllに変更してファイルアクセス(.htaccess)の使用可能な指示子を全て許可にします
  AllowOverride All

#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all

</Directory>

#
# AddHandler allows you to map certain file extensions to “handlers”:
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add “ExecCGI” to the “Options” directive.)
#
CGIスクリプトに拡張子.plを追加します
AddHandler cgi-script .cgi .pl

#
# Optionally add a line containing the server version and virtual host
# name to server-generated pages (internal error documents, FTP directory
# listings, mod_status and mod_info output etc., but not CGI generated
# documents or custom error documents).
# Set to “EMail” to also include a mailto: link to the ServerAdmin.
# Set to one of: On | Off | EMail
#
エラーページにApacheのバージョンを表示しないようにOn から Off に変更
ServerSignature Off

#
# Aliases: Add here as many aliases as you need (with no limit). The format is
# Alias fakename realname
#
# Note that if you include a trailing / on fakename then the server will
# require it to be present in the URL. So “/icons” isn’t aliased in this
# example, only “/icons/”. If the fakename is slash-terminated, then the
# realname must also be slash terminated, and if the fakename omits the
# trailing slash, the realname must also omit it.
#
# We include the /icons/ alias for FancyIndexed directory listings. If you
# do not use FancyIndexing, you may comment this out.
#
Alias /icons/ “/var/www/icons/”

<Directory “/var/www/icons”>

Options Indexesを削除してiconsディレクトリのファイル一覧を表示しないようにします
Options MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>

内容を保存しviエディタを終了します

ドキュメントルートの権限を変更します。

ドキュメントルートの権限変更
[root@centos ~]# chown -R apache.apache /var/www
[root@centos ~]# ls -l /var/www
合計 32
drwxr-xr-x 2 apache apache 4096 11月 13 00:44 cgi-bin
drwxr-xr-x 3 apache apache 4096 2月 3 23:11 error
drwxr-xr-x 6 apache apache 4096 3月 19 09:58 html
drwxr-xr-x 3 apache apache 4096 2月 3 23:11 icons

所有ユーザとグループがapacheになっている事を確認します

PHPの設定ファイルを変更します。

PHPの設定ファイル変更
[root@centos ~]# vi /etc/php.ini
viエディタが起動するので設定ファイルを変更します。
設定ファイルが大きいので設定箇所のみピックアップしています。

;
; Misc
;
; Decides whether PHP may expose the fact that it is installed on the server
; (e.g. by adding its signature to the Web server header). It is no security
; threat in any way, but it makes it possible to determine whether you use PHP
; on your server or not.
HTTPヘッダーにPHPのバージョンを表示しないようにOn から Off に変更
expose_php = Off

内容を保存しviエディタを終了します

Webサーバーを外部公開する為に、CentOSのファイアウォールの設定を変更します。

[root@centos ~]# vi /etc/sysconfig/iptables
viエディタが起動するので設定ファイルを変更します。
# Firewall configuration written by system-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT – [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -p tcp -m tcp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 53 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m udp -p udp –dport 53 -j ACCEPT
下記1行を追加してTCPの80番ポート(http)を開放します
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-with icmp-host-prohibited

内容を保存しviエディタを終了します

設定内容を反映します
[root@centos ~]# /etc/rc.d/init.d/iptables restart
ファイアウォールルールを適用中: [ OK ]
チェインポリシーを ACCEPT に設定中filter [ OK ]
iptables モジュールを取り外し中 [ OK ]
iptables ファイアウォールルールを適用中: [ OK ]
iptables モジュールを読み込み中ip_conntrack_netbios_ns [ OK ]

ルータの設定を変更してTCPの80番ポートを開放します。
開放方法はルータの設定手順に従って実施してください。

Apacheのサービス起動と自動起動の設定をします。

Apacheを起動します
[root@centos ~]# /etc/rc.d/init.d/httpd start
httpd を起動中: [ OK ]

OS再起動時にApacheを自動起動するようにします
[root@centos ~]# chkconfig httpd on
[root@centos ~]# chkconfig –list | grep httpd
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

ApacheとPHPのバージョン情報をチェックします。
ApacheとPHPのバージョン情報を隠蔽する設定をしたのでその確認をします。

テスト用PHPページを作成します
[root@centos ~]# vi /var/www/html/test.php
viエディタが起動するので入力します。
<?php
  phpinfo();
?>

内容を保存しviエディタを終了します

telnetコマンドでhttpヘッダーの内容を確認します
[root@centos ~]# telnet www.sa-sa-ki.jp 80
Trying 192.168.0.20…
Connected to www.sa-sa-ki.jp (192.168.0.20).
Escape character is ‘^]’.
HEAD /index.html HTTP/1.0
もう一度[Enter]キーを押下してください

HTTP/1.1 200 OK
Date: Fri, 27 Mar 2009 02:20:01 GMT
Apacheのバージョンが表示されていない
Server: Apache
X-Powered-By: PHP/x.x.xも表示されていない
X-Pingback: http://www.sa-sa-ki.jp/blog/xmlrpc.php
Connection: close
Content-Type: text/html; charset=UTF-8

Connection closed by foreign host.

次に存在しないページにブラウザでアクセスして、ApacheやPHPのバージョン情報が表示されない事を確認します。

最後に作成したtest.phpページにブラウザでアクセスして、ApacheとPHPが正常に動いているか確認します。

※セキュリティの為、表示されている情報は隠しています

次回はMySQLの初期設定を行います。

■ 参考サイト ■
Webサーバー構築(Apache) – CentOSで自宅サーバー構築
はじめての自宅サーバ構築 Fedora/CentOS – Webサーバの構築(apache)

————————————————————————————————–
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その12 CentOS 5.2 にDNSサーバーを導入して名前解決(確認編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その11 CentOS 5.2 にDNSサーバーを導入して名前解決(設定編)
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その10 CentOS 5.2 SSHサーバーを構築して外部からリモート接続&リモートファイル転送
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その9 CentOS 5.2 にバッファオーバーフロー攻撃対策を行う
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その8 CentOS 5.2 にrootkit検知ツールを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その7 CentOS 5.2 にファイル改竄検知システムを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その6 CentOS 5.2 にアンチウィルスソフトを導入する
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その5 CentOS 5.2 ファイル転送準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その4 CentOS 5.2 インストール後の初期設定
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その3 インストールしたCentOS 5.2 にリモート接続準備
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その2 CentOS 5.2 をインストールする
flashcast:フリーで働くITエンジニア集団のブログ: 自宅サーバー再構築 その1 導入を検討する

1月
28

以前flashcast:フリーで働くITエンジニア集団のブログ: ubuntu 8.10にApache、PHP、MySQLをインストールしてLAMP環境を構築するで、ubuntuにLAMP環境を作成する方法をご紹介しましたが、flashcast:フリーで働くITエンジニア集団のブログ: ThinkPad X31にインストールしたubuntu 8.10でトラックポイントを有効にするにはでもお伝えした通り、OS入れ替え作業を行いubuntuがまっさらな状態になってしまいましたので、再度LAMP環境を構築しようと思います。

前回と同じだと面白くないので、今回はXAMPP(ザンプ)をインストールして簡単にLAMP環境を構築したいと思います。
XAMPPのいいところはLAMP環境を構築するための必要なソフトウェアが全て梱包してあり、インストールが簡単でかつ複数のOSで利用可能なところでしょうか。

では、インストールしてみることにします。

まずxamppのパッケージをダウンロードします。
apache friends – xampp
Linux用xamppパッケージのダウンロードはこちらです。
http://www.apachefriends.org/download.php?xampp-linux-1.7.tar.gz

xampp-linux-1.7.tar.gzファイルのダウンロードが終わったら、メニューバーの[アプリケーション]-[アクセサリ]-[端末]を選択します。

端末の画面からコマンドを入力していきます。

rootユーザにスイッチします。スイッチできない場合は以前ご紹介したflashcast:フリーで働くITエンジニア集団のブログ: ubuntu 8.10 でrootユーザを使うにはを参照してやり方を確認してください。
ubuntu@ubuntu: ~$ su -
パスワード:rootユーザのパスワード

ダウンロードしたxampp-linux-1.7.tar.gzを解凍しつつ/optディレクトリへ展開します
root@ubuntu: ~# tar xzvf /home/ubuntu/Desktop/xampp-linux-1.7.tar.gz -C /opt

これで/opt/xamppディレクトリにXAMPPがインストールされました。最後にXAMPPのサービスを起動します
root@ubuntu: ~# /opt/lampp/lampp start
Starting XAMPP for Linux 1.7…
XAMPP: Starting Apache with SSL (and PHP5)…
XAMPP: Starting MySQL…
XAMPP: Starting ProFTPD…
XAMPP for Linux started.

たったこれだけでXAMPPの導入は終わりです。
あとは稼動確認をしてみます。

ブラウザを起動して、アドレスに「http://localhost/」と入力してみてください。
XAMPPのタイトルページが表示されますので、「日本語」というリンクをクリックします。

XAMPPのメニューページへ遷移します。
サービスの動作確認をする為に、左ペインにある「ステータス」リンクをクリックします。

各サービスが正常稼動していることが確認できます。

最後にubuntuを再起動する度にXAMPPのサービスを再起動する必要があるのですが、毎回サービス起動するのは面倒くさいのでubuntu起動時に自動でサービスを起動する処理を追加します。

root@ubuntu: ~# vi /etc/rc.local
viエディタが起動しますので、以下の1行 exit 0 より上の行に追加します。
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will “exit 0″ on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/opt/lampp/lampp start

exit 0

保存してviエディタを終了します。

ちなみにサービスの自動起動はRedHat系のLinuxを使ってる人は chkconfig を使ったりしますよね?
ubuntuはchkconfigがデフォルトでインストールされていなかったので、/etc/rc.localを使ってブート時に自動起動してみました。

これでubuntuを再起動してもすぐにXAMPPを使うことができて便利ですね。

1月
03

ubuntu 8.10でApache、PHP、MySQLをインストールしてLAMP(ランプ)環境を作ってみたいと思います。
LAMP環境とは

OSがLinux
WebサーバがApache
DBサーバがMySQL
スクリプト言語がPHP、Perl、Python

の頭文字を取ってLAMP(ランプ)と呼ぶそうです。

WikipediaでLAMPを調べてみると、LAMPの類似用語があるようで
OSがWindowsだと[WAMP(ワンプ)]
Macだと[MAMP(マンプ)]
Solarisだと[SAMP(サンプ)]
BSDだと[BAMP(バンプ)]

DBサーバがPostgresだと[LAPP(ラップ)]
Firebirdだと[FLAP(フラップ)]

スクリプト言語がRubyだと[LAMR(ラマー)]

apachefriends.orgから提供されているApache、MySQL、SQLite、PHP、Perl、phpMyAdminなどのいくつかの補助ソフトを含んだマルチプラットフォーム(Linux、Solaris、Windows、Mac)対応の[XAMPP(ザンプ)]

OSがWindows、WebサーバがIIS、DBサーバがSQL Serverで
言語がPHPだと[WISP(ウィスプ)]
ASP.NETだと[WISA(ウィサ)]
などがあるようです。

ubuntu 8.10にApache、MySQL、PHPをインストールしていきます。

※PerlとPythonはインストールした記憶がないのに、インストール済みだったので、恐らくubuntu 8.10をインストールした時にデフォルトで導入されていたようです。
PerlとPythonがインストールされていたかはメニューバーの[アプリケーション]-[アクセサリ]-[端末]を起動して以下のコマンドを入力、バージョンを確認しました。

 $ perl –version

 This is perl, v5.10.0 built for i486-linux-gnu-thread-multi

 Copyright 1987-2007, Larry Wall

 Perl may be copied only under the terms of either the Artistic License or the
 GNU General Public License, which may be found in the Perl 5 source kit.

 Complete documentation for Perl, including FAQ lists, should be found on
 this system using “man perl” or “perldoc perl”. If you have access to the
 Internet, point your browser at http://www.perl.org/, the Perl Home Page.

 $ python -V
 Python 2.5.2

Perlはバージョン5.10.0がPythonはバージョン2.5.2が導入済みでした。

それではまずメニューバーの[システム]-[システム管理]-[Synaptic パッケージマネージャ]を選択して「Synaptic パッケージ・マネージャ」を起動します。
※「Synaptic パッケージ・マネージャ」を起動するにあたり、ログインユーザのパスワードを求められる場合があります。その場合はログインユーザのパスワードを入力してください。

以下のパッケージを導入します。
パッケージを探すときは「クイック検索」に名前を入力するとパッケージ一覧から探しやすいです。

apache2
libapache2-mod-php
mysql-server
php5
php5-cli
php5-mysql

上記パッケージをインストール指定すると関連する別のパッケージも導入するか「追加された変更点もマークしますか?」ダイアログが表示されるので[マーク(M)]ボタンをクリックします。

関連パッケージを含む全てのパッケージを選択したら、[適用]ボタンをクリックしてパッケージのダウンロード・インストールを行います。

概要ダイアログが表示されるので、[適用]ボタンをクリックします。

パッケージのダウンロードとインストールが始まります。

MySQLのrootユーザのパスワードの入力を聞かれるので、設定したいパスワードを入力して[進む]ボタンをクリックします。

MySQLのrootユーザのパスワードを再入力して[進む]ボタンをクリックします。

適用が変更されましたダイアログが表示されるので、[閉じる]ボタンをクリックします。
これでインストール完了です。

次にApacheの動作確認をします。
メニューバーの[アプリケーション]-[インターネット]-[Firefox ウェブ・ブラウザ]を選択してFirefoxを起動します。
アドレスに[http://localhost/]と入力して[Enter]キーを押したらブラウザ上に「It works!」と表示されれば無事Apacheのインストールが完了しています。

設定ファイルの場所とか絶対忘れちゃいそうなのでメモです。

設定ファイル関連:/etc/apache2
ドキュメントルート:/var/www
サービス関連:/etc/init.d/apache2

次にPHPの動作確認です。
メニューバーの[アプリケーション]-[アクセサリ]-[端末]を起動して以下のコマンドを入力してPHP確認用のページを作成します。

 $ su -
 パスワード: rootユーザのパスワード
 # cd /var/www
 # vi testphp.php
 viエディタが開きますので、[i]キーを一度押してテキスト入力モードにして
 phpinfo関数を実行するよう記載してください。
 実際にはこんな感じ。
 

 これだけ入力したら[Esc]キーを押し、その後[:]キー[w]キー[q]キーを順番に押して[Enter]キーを押します。 
 念のためApacheのサービスを再起動します。
 # /etc/init.d/apache2 reload
  * Reloading web server config apache2
 apache2: Could not reliably determine the server’s fully qualified domain name,
 using 127.0.1.1 for ServerName
[ OK ]

※ここでrootユーザにスイッチしています。ubuntuはデフォルトではrootユーザにスイッチできません。rootユーザにスイッチできなかった方はflashcast:フリーで働くITエンジニア集団のブログ: ubuntu 8.10 でrootユーザを使うにはの記事を参考にrootユーザを有効にしてください。

これでtestphp.phpファイルが/var/wwwにできましたので、アドレスに[http://localhost/testphp.php]と入力して[Enter]キーを押したらブラウザ上に下記画像のような画面が表示されれば無事PHPのインストールが完了しています。

PHPの設定ファイルの場所メモです。

設定ファイル関連:/etc/php5/apache2/php.ini

次にMySQLの動作確認です。

 $ mysql -u root -p
 Enter password: MySQLインストール中に設定したrootユーザのパスワード(ubuntuのrootユーザではありません)
 Welcome to the MySQL monitor. Commands end with ; or \g.
 Your MySQL connection id is 7
 Server version: 5.0.67-0ubuntu6 (Ubuntu)

 Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

 mysql> \q
 Bye

MySQLの設定ファイルの場所メモです。

設定ファイル関連:/etc/mysql/my.cnf
サービス関連:/etc/init.d/mysql

インストールと簡単な動作確認、設定ファイルの場所などを書いているので手順が若干長く感じるかもしれませんが、これだけでubuntuでもWebアプリが動作するようになりました。

  • Search:
  • flashcastとは?

    東京を中心に、現在フリーランスとして活動しているITエンジニア、および、かつてフリーランスとして活動していた起業家達が立ち上げたコミュニティーです。

    みんなで集まって面白いことをやろう!形に残そう!ということで、ブログをはじめました。

    技術情報や、フリーエンジニアに役立つ情報などを、ご紹介できたらと思っています。

    お問い合わせ:
    info@flashcast.jp
  • カレンダー

    2010年7月
    日曜日 月曜日 火曜日 水曜日 木曜日 金曜日 土曜日
    « 6月    
     123
    45678910
    11121314151617
    18192021222324
    25262728293031
  • メンバー紹介

    もじゃもじゃ
    flashcastのリーダー

    3年ほどフリーのITエンジニアとして活動。現在は、社員2名の株式会社を経営しています。

    一攫千金を夢見る野心家です。

    ライブキャスト

    yasu
    ダイバー

    自宅サーバーでホームページを作り始めました。

    少しずつ記事を増やしていきますので足を運んでください。

    よろしくお願いします。

    sa-sa-ki.jp

    のら
    たびびと

    ねこ好きに悪人はいなーいっ!!

    バイクや車も好きです。

    めぐ
    デザイナーのたまご

    音楽とデザインとお酒をこよなく愛する永遠のダイエッター。

    現在ペンタブレットでイラストを勉強中。

    Hiro
    コンサル

    PMやSEの案件を業務委託で請けることが多いですが、小規模案件も受託でやっています。

    得意な分野はマイクロソフト製品や関連技術によるシステム構築です。

    KEI
    取締役の風格

    最年少なのに、メンバーで1番の貫禄の持ち主!?

    C#や.netなどサーバ側の開発が得意。

    ろっきー
    美食家★パパ

    自分にとっての息抜きは、ドライブして温泉に入って、美味しいご飯を食べる事。

    ココロとカラダのリフレッシュを大切にし、日々の仕事に励む一児の父親です。

    郵便番号検索

    my-hobby

    とのさま
    げーむのおうさま

    大人なのに好きなことしかやらない駄目人間。

    Web系が得意、アクセスは苦手><

    tonosamart.com

    セクレタリアト
    ギャンブラー

    フリーランス時代は仲間の現場を探すことが多く、それをきっかけに会社を設立。

    現在はSI業に特化せず、他の業種にも興味を持ち始めています。

    メドレー株式会社

  • 広告