linux下LAMP环境搭建

来源:互联网 发布:seajs require其他js 编辑:程序博客网 时间:2024/04/30 04:42
++++++++++++++++++++++++++++++++++++++++++++++
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是否己安装rpm -qa httpd#卸载rpm -e httpd --nodeps
2>【安装gcc, gcc-c++】
yum install gccyum install gcc-c++
3>【开放80、3306、22端口】
#关闭防火墙service iptables stopvi /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
4>【建立lamp/src目录, 将源码包上传】
5>【安装libxml2】
tar -zxvf libxml2-2.6.30.tar.gzcd libxml2-2.6.30./configure --prefix=/usr/local/libxml2/make make install
6>【安装libmcrypt】
tar -zxvf libmcrypt-2.5.8.tar.gzcd libmcrypt-2.5.8./configure --enable-ltdl-installmakemake install
7>【安装zlib】
tar -zxvf zlib-1.2.3.tar.gzcd zlib-1.2.3./configuremakemake install
8>【安装libpng】
tar -zxvf libpng-1.2.31.tar.gzcd libpng-1.2.31./configure --prefix=/usr/local/libpng/makemake install
9>【安装jpegsrc.v6b】
mkdir /usr/local/jpeg6mkdir /usr/local/jpeg6/binmkdir /usr/local/jpeg6/libmkdir /usr/local/jpeg6/includemkdir -p /usr/local/jpeg6/man/man1tar -zxvf jpegsrc.v6b.tar.gzcd jpeg-6b./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-staticmakemake install
10>【安装freetype】
tar -zxvf freetype-2.3.5.tar.gzcd freetype-2.3.5./configure --prefix=/usr/local/freetype/makemake install
11>【安装autoconf】
tar -zxvf autoconf-2.61.tar.gzcd autoconf-2.61./configuremakemake install
12>【安装gd】
tar -zxvf gd-2.0.35.tar.gzcd gd-2.0.35./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/makemake install

13>【安装apache】

tar -zxvf httpd-2.2.9.tar.gzcd 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-supportmakemake 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/httpdvi /etc/rc.d/init.d/httpd#在#!/bin/sh后添加下面两行(包含"#")# chkconfig:2345 85 15# description:Apache#添加执行权限chmod 755 /etc/init.d/httpd#添加到系统服务中chkconfig --add httpd#开启apacheservice httpd start

14>【安装ncurses】
tar -zxvf ncurses-5.6.tar.gzcd ncurses-5.6./configure --with-shared --without-debug --without-ada --enable-overwritemakemake install
15>【安装mysql】
groupadd mysqluseradd -g mysql mysqltar -zxvf mysql-5.1.59.tar.gzcd mysql-5.1.59./configure --prefix=/usr/local/mysql/ --with-extra-charsets=allmakemake install

cp support-files/my-medium.cnf /etc/my.cnf/usr/local/mysql/bin/mysql_install_db --user=mysqlchown -R root /usr/local/mysqlchown -R mysql /usr/local/mysql/varchgrp -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/mysqldchown root.root /etc/rc.d/init.d/mysqldchmod 755 /etc/rc.d/init.d/mysqldchkconfig --add mysqldchkconfig --list mysqldchkconfig --levels 245 mysqld off

#配置mysqlcd /usr/local/mysqlbin/mysqladmin version //简单的测试bin/mysqladmin Variables //查看所有mysql参数bin/mysql -uroot //没有密码可以直接登录本机服务器DELETE FROM mysql.user WHERE Host='localhost' AND User='';FLUSH PRIVILEGES;#设置root密码为123456SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');#配置可远程连接mysqluse mysqlSELECT 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';#重启mysqlservice mysqld restart
16>【安装php】
tar -zxvf php-5.2.6.tar.gzcd 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-socketsmakemake installcp php.ini-dist /usr/local/php/etc/php.ini
17>【apache配置】
#建立工作目录mkdir -p /var/www/html#修改httpd.confvi /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才能生效#重启apacheservice httpd restart
18>【添加PDO_MYSQL扩展】
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/mysqlmakemake 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 restart
19>【apache虚拟主机配置】
#建立dev目录mkdir -p /var/www/html/devcd /var/www/html/devvi index.php#添加<?phpphpinfo();?>#保存,退出#打开httpd.confvi /etc/httpd/httpd.conf#查找Include /etc/httpd//extra/httpd-vhosts.conf并取消注释Include /etc/httpd//extra/httpd-vhosts.conf#打开httpd-vhosts.confvi /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>#保存, 退出#重启apacheservice httpd restart#修改hosts文件vi /etc/hosts#添加127.0.0.1       dev.dev localhost#保存, 退出#在浏览器输入http://dev.dev访问,查看能否输出php信息