注:本实验是在关闭iptables和selinux的情况下进行的。

安装环境

[root@server~]#yum-yinstallperlgdgd-devellibpnglibpng-devellibjpeglibjpeg-develzlibzlib-develpcre-develgccgcc-c++makecmakeautoconfopensslopenssl-develncurses-develpatchlibxml2libxml2-develcurl-developenldapopenldap-devellibeventlibevent-develbisoniculibicu-devellibtoolreadline-develnet-snmp-develbzip2-develfreetype-develvim

一、搭建LAMP环境
(1)安装apache
安装http
[root@serverlamp]#tarzxvfhttpd-2.2.22.tar.gz
[root@serverlamp]#cdhttpd-2.2.22
[root@serverhttpd-2.2.22]#./configure--prefix=/usr/local/apache--enable-so--enable-sl--enable-cgi--enable-rewrite--with-zlib\
--with-pcre

[root@serverhttpd-2.2.22]#make&&makeinstall
启动测试apache
[root@server~]#/usr/local/apache/bin/apachectlstart

(2)安装mysql
[root@server~]#useradd-s/sbin/nologin-Mmysql

[root@serverlamp]#tarzxvfmysql-5.5.29.tar.gz
[root@serverlamp]#cdmysql-5.5.29

[root@servermysql-5.5.29]#cmake.\
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql\
-DINSTALL_DATADIR=/data/mysql\
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock\
-DDEFAULT_CHARSET=utf8\
-DDEFAULT_COLLATION=utf8_general_ci\
-DWITH_EXTRA_CHARSETS=complex\
-DMYSQL_USER=mysql

[root@vhost1mysql-5.5.29]#make[root@vhost1mysql-5.5.29]#makeinstallMysql安装之后的配置:[root@vhost1mysql-5.5.29]#cd/usr/local/mysql[root@vhost1mysql]#scripts/mysql_install_db--user=mysql--basedir=/usr/local/mysql--datadir=/data/mysql


[root@servermysql]#chown-Rroot.
[root@servermysql]#cpsupport-files/my-medium.cnf/etc/my.cnf
[root@serverphp]#vim/etc/my.cnf
添加以下内容:
[mysqld]
port=3306
socket=/tmp/mysql.sock
basedir=/usr/local/mysql
datadir=/data/mysql
user=mysql
character_set_server=utf8

配置mysql启动
[root@servermysql]#cpsupport-files/mysql.server/etc/init.d/mysql
[root@servermysql]#vim/etc/init.d/mysql
添加以下两行
basedir=/usr/local/mysql
datadir=/data/mysql

[root@servermysql]#servicemysqlstart
StartingMySQL...SUCCESS!

查看mysql是否已经启动
[root@servermysql]#netstat-nultp|grepmysql
0.0.0.0:33060.0.0.0:*LISTEN64819/mysqld

(3)安装php
[root@serverphp-5.4.11]#useradd-s/sbin/nologin-Mfpmuser

[root@serverlamp]#tarzxvfphp-5.4.11.tar.gz
[root@serverphp-5.4.11]#
./configure--prefix=/usr/local/php\
--with-apxs2=/usr/local/apache/bin/apxs\
--with-config-file-path=/etc\
--with-freetype-dir--with-jpeg-dir\
--with-png-dir--enable-zip\
--with-zlib--enable-xml\
--with-gd--with-mhash\
--with-libxml-dir=/usr--enable-mbstring\
--enable-fpm--with-fpm-user=fpmuser\
--with-fpm-group=fpmuser--disable-ipv6\
--enable-sockets--with-openssl\
--with-bz2--with-curl--enable-dba=shared\
--with-pcre-dir--with-gd--with-jpeg-dir--with-png-dir\
--with-zlib-dir--enable-mbstring\
--with-mysql=/usr/local/mysql/\
--with-mysql-sock=/tmp/mysql.sock\
--with-mysqli=/usr/local/mysql/bin/mysql_config

[root@serverphp-5.4.11]#make
[root@serverphp-5.4.11]#makeinstall

[root@serverphp-5.4.11]#cpphp.ini-production/usr/local/php/lib/php.ini
[root@serverphp-5.4.11]#cd/usr/local/php/etc/
[root@serveretc]#cp-aphp-fpm.conf.defaultphp-fpm.conf
[root@serveretc]#cd..

启动php
[root@serverphp]#sbin/php-fpm


(4)配置apache
[root@serverhtml]#vim/usr/local/apache/conf/httpd.conf
找到DirectoryIndexindex.htmlindex.html.var
修改为DirectoryIndexindex.htmlindex.php

接着增加如下内容:

AddTypeapplication/x-httpd-php.php

修改完如下:

<IfModuledir_module>
DirectoryIndexindex.htmlindex.php
</IfModule>
AddTypeapplication/x-httpd-php.php

添加虚拟目录测试lamp
[root@server~]#vim/usr/local/apache/conf/httpd.conf

添加以下内容
Alias/test"/usr/local/apache/test"
<Directory"/usr/local/apache/test">
AuthTypeBasic
OptionsNone
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>

创建Php测试页面
[root@server~]#mkdir/usr/local/apache/test
[root@server~]#vim/usr/local/apache/test/index.php
添加以下内容:
<?php
phpinfo();
?>

配置完成后重启apache
[root@serverhtml]#/usr/local/apache/bin/apachectlrestart

测试PHP页面


打开浏览器访问:

http://ip/test/index.php


至此LAMP环境配置完成

相关软件包下载:http://down.51cto.com/data/699395