LAMP · 3 min read · Jan 08, 2026

CentOS 6.5 に Apache2、PHP5、および MySQL サポートをインストールする (LAMP)

LAMP は L inux、A pache、M ySQL、P HP の略です。このチュートリアルでは、PHP5 サポート (mod_php) および MySQL サポートを備えた CentOS 6.4 サーバーに Apache2 ウェブサーバーをインストールする方法を示します。

私はこれがあなたにとって機能することを保証するものではありません!

1 前提条件

このチュートリアルでは、ホスト名 server1.example.com と IP アドレス 192.168.0.100 を使用します。これらの設定はあなたの環境によって異なる場合があるため、適宜置き換える必要があります。

2 MySQL 5 のインストール

MySQL をインストールするには、次のようにします:

yum -y install mysql mysql-server

次に、MySQL のシステム起動リンクを作成し (システム起動時に MySQL が自動的に起動するように)、MySQL サーバーを起動します:

chkconfig --levels 235 mysqld on  
/etc/init.d/mysqld start

MySQL の root アカウントのパスワードを設定します:

mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL  
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current  
password for the root user. If you've just installed MySQL, and  
you haven't set the root password yet, the password will be blank,  
so you should just press enter here.
Enter current password for root (enter for none):  
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL  
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER  
New password: <-- yourrootsqlpassword  
Re-enter new password: <-- yourrootsqlpassword  
Password updated successfully!  
Reloading privilege tables..  
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone  
to log into MySQL without having to have a user account created for  
them. This is intended only for testing, and to make the installation  
go a bit smoother. You should remove them before moving into a  
production environment.
Remove anonymous users? [Y/n] <-- ENTER  
... Success!
Normally, root should only be allowed to connect from 'localhost'. This  
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- ENTER  
... Success!
By default, MySQL comes with a database named 'test' that anyone can  
access. This is also intended only for testing, and should be removed  
before moving into a production environment.
Remove test database and access to it? [Y/n] <-- ENTER  
- Dropping test database...  
... Success!  
- Removing privileges on test database...  
... Success!
Reloading the privilege tables will ensure that all changes made so far  
will take effect immediately.
Reload privilege tables now? [Y/n] <-- ENTER  
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL  
installation should now be secure.
Thanks for using MySQL!

3 Apache2 のインストール

Apache2 は CentOS パッケージとして利用可能であるため、次のようにインストールできます:

yum -y install httpd

次に、システムを設定して Apache を起動時に開始するようにします…

chkconfig --levels 235 httpd on

… そして Apache を起動します:

/etc/init.d/httpd start

次に、ブラウザを http://192.168.0.100 に向けると、Apache2 のプレースホルダーページが表示されるはずです:

Apache のデフォルトのドキュメントルートは CentOS では /var/www/html であり、設定ファイルは /etc/httpd/conf/httpd.conf です。追加の設定は /etc/httpd/conf.d/ ディレクトリに保存されます。

4 PHP5 のインストール

次のように PHP5 と Apache PHP5 モジュールをインストールできます:

yum -y install php

その後、Apache を再起動する必要があります:

/etc/init.d/httpd restart

5 PHP5 のテスト / PHP5 インストールの詳細を取得する

デフォルトのウェブサイトのドキュメントルートは /var/www/html です。今から、そのディレクトリに小さな PHP ファイル (info.php) を作成し、ブラウザで呼び出します。このファイルは、インストールされた PHP バージョンなど、PHP インストールに関する多くの有用な詳細を表示します。

vi /var/www/html/info.php

| |

今、ブラウザでそのファイルを呼び出します (例: http://192.168.0.100/info.php):

ご覧のとおり、PHP5 は動作しており、Server API 行に示されているように Apache 2.0 ハンドラーを介して動作しています。さらに下にスクロールすると、PHP5 ですでに有効になっているすべてのモジュールが表示されます。MySQL はそこにリストされていないため、PHP5 にはまだ MySQL サポートがありません。

6 PHP5 での MySQL サポートの取得

PHP で MySQL サポートを取得するには、php-mysql パッケージをインストールできます。アプリケーションに必要な他の PHP5 モジュールもインストールすることをお勧めします。次のようにして利用可能な PHP5 モジュールを検索できます:

yum search php

必要なものを選択し、次のようにインストールします:

yum -y install php-mysql

次のステップでは、Wordpress、Joomla、Drupal などの CMS システムに必要な一般的な PHP モジュールをいくつかインストールします:

yum -y install php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-mcrypt php-mssql php-snmp php-soap php-tidy curl curl-devel

APC は PHP 中間コードをキャッシュおよび最適化するための無料でオープンな PHP オペコードキャッシャーです。他の PHP オペコードキャッシャー (eAccelerator や Xcache など) と似ています。PHP ページの速度を上げるために、これらのいずれかをインストールすることを強くお勧めします。

APC は次のようにインストールできます:

yum -y install php-pecl-apc

次に Apache2 を再起動します:

/etc/init.d/httpd restart

次に、ブラウザで http://192.168.0.100/info.php を再読み込みし、モジュールセクションに再度スクロールします。そこには、APC モジュールを含む多くの新しいモジュールが見つかるはずです:

7 phpMyAdmin

phpMyAdmin は、MySQL データベースを管理するためのウェブインターフェースです。

まず、CentOS システムで RPMforge リポジトリを有効にします。phpMyAdmin は公式の CentOS 6.5 リポジトリには含まれていません:

RPMforge GPG キーをインポートします:

rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

x86_64 システムの場合:

yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm

i386 システムの場合:

yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm

phpMyAdmin は次のようにインストールできます:

yum -y install phpmyadmin

次に、phpMyAdmin を設定します。phpMyAdmin が localhost からだけでなく接続を許可するように Apache 設定を変更します ( スタンスをコメントアウトします):

vi /etc/httpd/conf.d/phpmyadmin.conf

| # # Web application to manage MySQL # # # Order Deny,Allow # Deny from all # Allow from 127.0.0.1 # Alias /phpmyadmin /usr/share/phpmyadmin Alias /phpMyAdmin /usr/share/phpmyadmin Alias /mysqladmin /usr/share/phpmyadmin |

次に、phpMyAdmin の認証をクッキーから http に変更します:

vi /usr/share/phpmyadmin/config.inc.php

| [...] /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'http'; [...] |

Apache を再起動します:

/etc/init.d/httpd restart

その後、http://192.168.0.100/phpmyadmin/ で phpMyAdmin にアクセスできます:

8 リンク

Share: X/Twitter LinkedIn

新しい投稿を受信箱で受け取る

スパムはありません。いつでも購読を解除できます。