linux下LAMP环境搭建
++++++++++++++++++++++++++++++++++++++++++++++
操作系统 : [CentOS6.0]
服务器 : [httpd-2.2.9]
PHP : [php-5.2.6]
数据库 : [mysql-5.1.59]
++++++++++++++++++++++++++++++++++++++++++++++
准备安装软件(download)
1> [httpd-2.2.9]
http://sunsite.bilkent.edu.tr/pub/apache/httpd/httpd-2.2.9.tar.gz
2> [php-5.2.6]
http://museum.php.net/php5/php-5.2.6.tar.gz
3> [mysql-5.1.59]
http://downloads.mysql.com/archives/mysql-5.1/mysql-5.1.59.tar.gz
4> [libxml2-2.6.30]
http://download.chinaunix.net/down.php?id=28491&ResourceID=6095&site=1
5> [libmcrypt-2.5.8]
http://sourceforge.net/projects/mcrypt/files/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz/download
6> [zlib-1.2.3]
http://sourceforge.net/projects/libpng/files/zlib/1.2.3/zlib-1.2.3.tar.gz/download
7.>[libpng-1.2.31]
http://files.directadmin.com/services/custombuild/libpng-1.2.31.tar.gz
8.>[jpegsrc.v6b]
http://download.chinaunix.net/down.php?id=10021&ResourceID=5095&site=1
9.>[freetype-2.3.5]
http://nongnu.askapache.com/freetype/freetype-2.3.5.tar.gz
10.>[autoconf-2.61]
http://ftp.gnu.org/gnu/autoconf/autoconf-2.61.tar.gz
11.>[gd-2.0.35]
http://code.google.com/p/google-desktop-for-linux-mirror/downloads/detail?name=gd-2.0.35.tar.gz&can=2&q=
12.>[ncurses-5.6]
http://ftp.gnu.org/gnu/ncurses/ncurses-5.6.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++
1>【卸载系统自带的apache】
#查看apache是否己安装2>【安装gcc, gcc-c++】
rpm -qa httpd
#卸载
rpm -e httpd --nodeps
yum install gcc3>【开放80、3306、22端口】
yum install gcc-c++
#关闭防火墙4>【建立lamp/src目录, 将源码包上传】
service iptables stop
vi /etc/sysconfig/iptables
#添加
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
#重启防火墙
service iptables restart
5>【安装libxml2】
tar -zxvf libxml2-2.6.30.tar.gz6>【安装libmcrypt】
cd libxml2-2.6.30
./configure --prefix=/usr/local/libxml2/
make
make install
tar -zxvf libmcrypt-2.5.8.tar.gz7>【安装zlib】
cd libmcrypt-2.5.8
./configure --enable-ltdl-install
make
make install
tar -zxvf zlib-1.2.3.tar.gz8>【安装libpng】
cd zlib-1.2.3
./configure
make
make install
tar -zxvf libpng-1.2.31.tar.gz9>【安装jpegsrc.v6b】
cd libpng-1.2.31
./configure --prefix=/usr/local/libpng/
make
make install
mkdir /usr/local/jpeg610>【安装freetype】
mkdir /usr/local/jpeg6/bin
mkdir /usr/local/jpeg6/lib
mkdir /usr/local/jpeg6/include
mkdir -p /usr/local/jpeg6/man/man1
tar -zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install
tar -zxvf freetype-2.3.5.tar.gz11>【安装autoconf】
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make
make install
tar -zxvf autoconf-2.61.tar.gz12>【安装gd】
cd autoconf-2.61
./configure
make
make install
tar -zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
make
make install
13>【安装apache】
tar -zxvf httpd-2.2.9.tar.gz14>【安装ncurses】
cd httpd-2.2.9
./configure --prefix=/usr/local/apache2/ --sysconfdir=/etc/httpd/ --with-included-apr --disable-userdir --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-static-support
make
make install
#启动apache
/usr/local/apache2/bin/apachectl start
#如果出现下面的错误,
#httpd: Could not reliably determine the server's fully qualified domain name, using ::1 for ServerName
#修改配置文件
vi /etc/httpd/httpd.conf
#查找ServerName,将注释去掉
ServerName www.example.com:80
#添加到自启动
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
#将apache添加到系统服务中
cp /usr/local/apache2/bin/apachectl /etc/init.d/httpd
vi /etc/rc.d/init.d/httpd
#在#!/bin/sh后添加下面两行(包含"#")
# chkconfig:2345 85 15
# description:Apache
#添加执行权限
chmod 755 /etc/init.d/httpd
#添加到系统服务中
chkconfig --add httpd
#开启apache
service httpd start
tar -zxvf ncurses-5.6.tar.gz15>【安装mysql】
cd ncurses-5.6
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install
groupadd mysql
useradd -g mysql mysql
tar -zxvf mysql-5.1.59.tar.gz
cd mysql-5.1.59
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql
/usr/local/mysql/bin/mysqld_safe --user=mysql &
cp /lamp/src/mysql-5.1.59/support-files/mysql.server /etc/rc.d/init.d/mysqld
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig --levels 245 mysqld off
#配置mysql16>【安装php】
cd /usr/local/mysql
bin/mysqladmin version //简单的测试
bin/mysqladmin Variables //查看所有mysql参数
bin/mysql -uroot //没有密码可以直接登录本机服务器
DELETE FROM mysql.user WHERE Host='localhost' AND User='';
FLUSH PRIVILEGES;
#设置root密码为123456
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');
#配置可远程连接mysql
use mysql
SELECT user,password,host FROM user;
DELETE FROM user WHERE host='localhsot.localdomain'
DELETE FROM user WHERE host='127.0.0.1';
UPDATE user SET host='%' WHERE user='root';
#重启mysql
service mysqld restart
tar -zxvf php-5.2.6.tar.gz17>【apache配置】
cd php-5.2.6
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql/ --with-libxml-dir=/usr/local/libxml2/ --with-jpeg-dir=/usr/local/jpeg6/ --with-freetype-dir=/usr/local/freetype/ --with-gd=/usr/local/gd2/ --with-mcrypt=/usr/local/libmcrypt/ --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-soap --enable-mbstring=all --enable-sockets
make
make install
cp php.ini-dist /usr/local/php/etc/php.ini
#建立工作目录18>【添加PDO_MYSQL扩展】
mkdir -p /var/www/html
#修改httpd.conf
vi /etc/httpd/httpd.conf
#功能: 设置工作目录
#说明: 搜索DocumentRoot, 修改为
DocumentRoot "/var/www/html"
#功能: 设置目录选项
#说明: 搜索<Directory "/usr/local/apache2//htdocs">, 修改为
<Directory "/var/www/html">
#功能: 设置默认文档
#说明: 搜索<IfModule dir_module>, 修改为
DirectoryIndex index.html index.php
#功能: 增加php类型
#说明: 搜索 AddType application/x-gzip .gz .tgz在后面添加
AddType application/x-httpd-php .html .php
功能: 不允许访问目录
说明: 搜索Options Indexes FollowSymLinks项并注释
#Options Indexes FollowSymLinks
#注意: 修改配置文件后, 重启apache才能生效
#重启apache
service httpd restart
cd /lamp/src/php-5.2.6/ext/pdo_mysql
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --with-pdo-mysql=/usr/local/mysql
make
make install
#执行完make install后会生成#Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/#修改php.inivi /usr/local/php/etc/php.ini#查找extension_dir,修改为extension_dir = "/usr/local/php/lib/php/extensions/no-debug-non-zts-20060613/"#添加pdo_mysqlextension = pdo_mysql.so#重启apacheservice httpd restart19>【apache虚拟主机配置】
#建立dev目录
mkdir -p /var/www/html/dev
cd /var/www/html/dev
vi index.php
#添加
<?php
phpinfo();
?>
#保存,退出
#打开httpd.conf
vi /etc/httpd/httpd.conf
#查找Include /etc/httpd//extra/httpd-vhosts.conf并取消注释
Include /etc/httpd//extra/httpd-vhosts.conf
#打开httpd-vhosts.conf
vi /etc/httpd//extra/httpd-vhosts.conf
#将下面几行注释
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "/usr/local/apache2//docs/dummy-host.example.com"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
#</VirtualHost>
#<VirtualHost *:80>
# ServerAdmin webmaster@dummy-host2.example.com
# DocumentRoot "/usr/local/apache2//docs/dummy-host2.example.com"
# ServerName dummy-host2.example.com
# ErrorLog "logs/dummy-host2.example.com-error_log"
# CustomLog "logs/dummy-host2.example.com-access_log" common
#</VirtualHost>
#添加
<VirtualHost *:80>
ServerName dev.dev
DocumentRoot "/var/www/html/dev"
<Directory "/var/www/html/dev/">
AllowOverride All
</Directory>
</VirtualHost>
#保存, 退出
#重启apache
service httpd restart
#修改hosts文件
vi /etc/hosts
#添加
127.0.0.1 dev.dev localhost
#保存, 退出
#在浏览器输入http://dev.dev访问,查看能否输出php信息