LAMP环境的配置方法一、环境
Centos 5
Apache 2.2
Mysql 5.1
PHP 5.2
二、Apache2.2的安装
1.解压Apache安装包
[root@cent5]#tar zxvf httpd-2.2.21.tar.gz
2.配置Apache
[root@cent5]#cd httpd-2.2.21
[root@cent5 httpd-2.2.21]#useradd apache
[root@cent5 httpd-2.2.21]#groupadd apache
[root@cent5 httpd-2.2.21]#usermod -G apache apache
[root@cent5 httpd-2.2.21]# ./configure --prefix=/opt/httpd/ --enable-deflate --enable-expires --enable-headers --enable-modules=most --enable-so --with-mpm=worker --enable-rewrite --enable-ssl --enable-mods-shared=all ---进行编译
[root@cent5 httpd-2.2.21]#make && make install ---安装
[root@cent5]#/opt/httpd/bin/apachectl start ---启动Apache服务
打开浏览器输入http://ip地址,如果出现“It works!"则安装成功。
三、Mysql5.1的安装
1.解压Mysql5.1的安装包
[root@cent5]#tar zxvf mysql-5.1.63.tar.gz
2.配置Mysql
[root@cent5]#groupadd mysql
[root@cent5]#useradd -s /sbin/nologin -g mysql -M mysql
[root@cent5 mysql-5.1.63]#./configure --prefix=/opt/mysql --with-unix-socket-path=/opt/mysql/tmp/mysql.sock --localstatedir=/opt/mysql/data --enable-assembler --enable-thread-safe-client --with-mysqld-user=mysql --with-big-tables --without-debug --with-pthread --enable-assembler --with-extra-charsets=complex --with-readline --with-ssl --with-embedded-server --enable-local-infile --with-plugins=partition,innobase --with-plugin-PLUGIN --with-mysqld-ldflags=-all-static --with-client-ldflags=-all-static
正确的结果:
Thank you for choosing MySQL!
Remember to check the platform specific part of the reference manual
for hints about installing MySQL on your platform.
Also have a look at the files in the Docs directory.
[root@cent5 mysql-5.1.63]#make && make install
[root@cent5 mysql-5.1.63]#/bin/cp support-files/my-small.cnf /etc/my.cnf
[root@cent5 mysql-5.1.63]#mkdir -p /opt/mysql/data
[root@cent5 mysql-5.1.63]#/opt/mysql/bin/mysql_install_db --user=mysql
正确结果:
Installing MySQL system tables...
120514 21:55:04 [Warning] '--skip-locking' is deprecated and will be removed in a future release. Please use '--skip-external-locking' instead.
OK
Filling help tables...
[root@cent5 mysql-5.1.63]# chgrp -R mysql /opt/mysql/
[root@cent5 mysql-5.1.63]# cp support-files/mysql.server /etc/init.d/mysqld
[root@cent5 mysql-5.1.63]# chmod 700 /etc/init.d/mysqld
[root@cent5 mysql-5.1.63]# /etc/init.d/mysqld restart
[root@cent5 mysql-5.1.63]# echo 'export PATH=$PATH:/opt/mysql/bin' >>/etc/profile
[root@cent5 mysql-5.1.63]# source /etc/profile
[root@cent5 mysql-5.1.63]#mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.63 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit
Bye
三、PHP的安装
PHP的安装一定要在Apache的安装目录内。
1.解压libiconv-1.10.tar.tar
[root@cent5]#tar zxf libiconv-1.10.tar.tar
2.安装libiconv
[root@cent5 libiconv-1.10]#./configure --prefix=/usr/local/libiconv
[root@cent5 libiconv-1.10]#make && make install
3.解压php-5.2.6.tar.gz
[root@cent5]#tar zxf php-5.2.6.tar.gz
4.检查PHP所需要的安装包
[root@cent5]#rpm
-qa zlib libxml libjpeg freetype libpng gd
curl libiconv zlib-devel
libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
5.如果没有安装用如下命令进行安装
[root@cent5]#yum install zlib libxml libjpeg freetype libpng gd curl libiconv zlib-devel libxml2-devel libjpeg-devel freetype-devel libpng-devel gd-devel curl-devel
6.安装PHP
[root@cent5 php-5.2.6]# ./configure --prefix=/opt/httpd/php5.2.6 --with-apxs2=/opt/httpd/bin/apxs --with-mysql=/opt/mysql --with-ttf --with-xmlrpc --with-openssl --with-zlib --with-freetype-dir --with-gd --with-jpeg-dir --with-png-dir --with-iconv=/usr/local/libiconv --enable-short-tags --enable-sockets --enable-zend-multibyte --enable-soap --enable-mbstring --enable-static --enable-gd-native-ttf --with-curl
Thank you for using PHP.
[root@cent5 php-5.2.6]#make && make install
[root@cent5 php-5.2.6]#cp php.ini-dist /opt/httpd/php5.2.6/etc/php.ini
四、修改Apache配置文件
1.将#ServerName
127.0.0.1:80的“#”去掉。
2.增加如下内容:
AddType
application/x-httpd-php .php .php3
AddType
application/x-httpd-php-source .phps
3.修改damon用户为apache
User
apache
Group
apache
4.测试文件内容,保存为.php的格式
<?
phpinfo ()
?>
5.找到:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
将该行改为
DirectoryIndex index.html index.htm index.php