CentOS LAMP環境phpとmysqlの接続の構築とテスト



CentOS LAMPはサーバとして不要なコンポーネントをインストールしないので、コンポーネントを選択するときはwebサーバを選択しないでください.後で手動でインストールをコンパイルするからです.CentOS LAMPシステムはRPMパケットとソースパケットの保存場所を規定する:

  
  
  
  
  1. RPM  /usr/local/src  
  2. (prefix) /usr/local/XXX  
  3. MySQL   /usr/local/mysql/var  
  4.  /usr/local/apache/htdocs 

CentOS LAMP環境構築
構築の仕事はAPACHE、MYSQL、PHPを含む.この順序で環境を構築することができます.
1、パッケージの取得

  
  
  
  
  1. Httpd:  http://www.apache.org/dist/httpd/httpd-2.2.11.tar.gz  
  2. mysql: http://mirror.provenscaling.com/mysql/enterprise/source/5.0/mysql-5.0.70.tar.gz  
  3. php: http://museum.php.net/php5/php-5.2.2.tar.gz 

それらをすべて/usr/local/srcの下に置きます.>cd/usr/local/src(インストールパッケージディレクトリにナビゲート)
2、mysqlをインストールする

  
  
  
  
  1. >tar -zxvf mysql-5.0.70.tar.gz  
  2. >cd mysql-5.0.70  
  3. >./configure --prefix=/usr/local/mysql  
  4. >make  
  5. >make install   
  6. >useradd mysql //  mysql   
  7. >cd /usr/local/mysql  
  8. >bin/mysql_install_db --user=mysql 
  9. >chown -R mysql .  // ,  "."  
  10. >chgrp -R mysql .  
  11. >chown -R mysql var  
  12. >cp share/mysql/my-medium.cnf /etc/my.cnf  
  13. >cp share/mysql/mysql.server /etc/rc.d/init.d/mysqld //  
  14. >chmod 755 /etc/rc.d/init.d/mysqld  
  15. >chkconfig --add mysqld 

手順8を実行した後:
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/local/mysql/bin/mysqladmin -u root password 'new-password'/usr/local/mysql/bin/mysqladmin -u root -h centos5 password 'new-password' Alternatively you can run:/usr/local/mysql/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/usr/local/mysql ;/usr/local/mysql/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/local/mysql/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
以下のコマンドを実行してMySQLサーバーを起動します:>/etc/rc.d/init.d/mysqld start//MySQLを起動(mysqlインストール完了)
3、Apacheのインストール

  
  
  
  
  1. >tar -zxvf httpd-2.2.11.tar.gz  
  2. >cd httpd-2.2.11  
  3. >./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max 
  4. >make  
  5. >make install 

手順3を実行すると、次の問題が発生します.
[root@centos5 httpd-2.3.8]# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite --enable-shared=max checking for chosen layout... Apache checking for working mkdir -p... yes checking build system type... i686-pc-linux-gnu checking host system type... i686-pc-linux-gnu checking target system type... i686-pc-linux-gnu Configuring Apache Portable Runtime library ... checking for APR... no configure: error: APR not found.  Please read the documentation.
に着くhttp://apr.apache.org/download.cgiダウンロードapr-1.4.2.tar.gz.
解凍後、解凍ディレクトリに入り、次の操作を行います.
./configure --prefix=/desired/path/of/apr    make    make test    make install  
apacheサービスの開始>/usr/local/apache/bin/apachectl-k startブラウザで開くhttp://127.0.0.1/アクセス可能な場合はapacheのインストールに成功しました.
4、PHPを取り付ける
>tar -zxvf php-5.2.2.tar.gz >cd php-5.2.2 >./configure --prefix=/usr/local/php --with-mysql=/usr/local/mysql --with-apxs2=/usr/local/apache/bin/apxs >make >make install >cp php.ini-dist/usr/local/php/lib/php.ini >vi/usr/local/php/lib/php.ini
5、CentOS LAMP構成httpd
.conf >vi/usr/local/apache/conf/httpd.confは「AddTypeアプリケーション/x-gzip.tgz」を見つけ、その下にAddTypeアプリケーション/x-httpd-phpを追加する.phpAddType application/x-httpd-php-source .phps「DirectoryIndex.html index.html index.htmlの前にindex.phpを追加する
apacheサービスを開始>/usr/local/apache/bin/apachectl-k start apacheを電源オンに設定自己起動:/etc/rc.d/rc.localファイルに行を追加して保存:/usr/local/apache/bin/apachectl start(apache+php構成完了)
6、確認L.A.M.P環境情報:>vi/usr/local/apache/htdocs/phpinfo.phpは次の行を新しく追加して保存します. >chmod 755/usr/local/apache/htdocs/phpinfo.phpはブラウザで開きますhttp://127.0.0.1/phpinfo.phpphpinfoの各情報が正しいかどうかを確認します.アクセス可能であれば環境構築に成功
phpとmysqlの接続をテストする

  
  
  
  
  1. >vi /usr/local/apache/htdocs/testdb.php , 。  
  2. <?php 
  3. $link=mysql_connect('localhost','root','yourpassword');  
  4. if(!$link) echo "fail";  
  5. else echo "success";  
  6. mysql_close();  
  7. ?> 
  8. >chmod 755 /usr/local/apache/htdocs/testdb.php  
  9. >service mysqld start 

ブラウザで開くhttp://127.0.0.1/testdb.php出力successがphpとmysqlの接続が成功したことを示す場合CentOS LAMP環境構築完了