zoukankan      html  css  js  c++  java
  • lamp环境的搭建和安装

      

      最近,部门有些系统需要迁移到新的机器上,因此需要在新的机器上安装lamp和lnmp的环境,因此在这里总结一下:

    一. 安装lamp环境的步骤:

       (1).因为是新的机器,因此需要安装gcc的各种环境:

     yum -y install gcc gcc-c++ libxml2 libxml2-devel autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel zlib zlib-devel glibc glibc-devel glib2 glib2-d evel

       (2).安装MySQL:

       1).编译安装MySQL: 

    +-------------------------------------------------------------------------------+
    |     操作                         |     作用               |    
    +-------------------------------------------------------------------------------+
    |shell> cd /usr/local/src               | 进入软件包所在目录(不要照抄)     |
    |-------------------------------------------------------------------------------|
    |shell> groupadd mysql                    | 增加mysql组(如果有就不用加了)     |
    |-------------------------------------------------------------------------------|
    |shell> useradd mysql -g mysql               | 增加mysql用户,并属于mysql组     |
    |-------------------------------------------------------------------------------|
    |shell> tar -xzvf mysql-5.1.30.tar.gz             | 解压mysql源码包          |
    |-------------------------------------------------------------------------------|
    |shell> cd mysql-5.1.30                    | 进入源码包               |
    |-------------------------------------------------------------------------------|
    |shell> ./configure --prefix=/usr/local/mysql      | 配置mysql编译选项,          |
    |     --with-charset=utf8                 | 指定安装路径及支持的字符集     |
    |     --with-extra-charsets=gbk,gb2312,binary  
    |                      |
    |-------------------------------------------------------------------------------|
    |shell> make                         |  编译                    |
    |-------------------------------------------------------------------------------|
    |shell> make install                     |  安装                    |
    +-------------------------------------------------------------------------------+

      2).配置并初始化MySQL

    +---------------------------------------------------------------------------------------+
    |     操作                              |     作用               |    
    +---------------------------------------------------------------------------------------+
    |shell> cp support-files/my-medium.cnf /etc/my.cnf     | 把MySQL配置文件复制到/etc下     |
    |---------------------------------------------------------------------------------------|
    |shell> vi /etc/my.cnf 在'skip_federated'前加'#'号     | 注释掉这个错误的启动项,这是一个比较新式的存储引擎|
    |---------------------------------------------------------------------------------------|
    |shell> cd /usr/local/mysql                    | 进入mysql的安装目录          |
    |---------------------------------------------------------------------------------------|
    |shell> chown -R mysql.mysql .                    | 修改属主属组为mysql,才能完成     |
    |                                     | 下一步的初始化数据库工作     |
    |---------------------------------------------------------------------------------------|
    |shell> bin/mysql_install_db --user=mysql           | 初始化数据数据库          |
    | --datadir=/usr/local/mysql/var               |                    |
    |---------------------------------------------------------------------------------------|
    |shell> chown -R root .                         | 把var目录修改为mysql用户所有     |
    |shell> chown -R mysql var                    | 其他文件修改为root所有,保证安全|
    |---------------------------------------------------------------------------------------|
    |shell> bin/mysqld_safe --user=mysql &               | 启动mysql               |
    +---------------------------------------------------------------------------------------+

      3).测试数据库

    +-------------------------------------------------+-------------------------------------+
    |               操作                 |               作用          |    
    +-------------------------------------------------+-------------------------------------+
    |shell> bin/mysql -uroot                 | 以root用户连mysql,无密码          |
    |---------------------------------------------------------------------------------------|
    |mysql> show databases;                      | 显示数据库                    |
    |---------------------------------------------------------------------------------------|
    | +--------------------+                 |                         |    
    | | Database           |                 |                         |
    | +--------------------+                 |     看到左面的信息,数据库就安装     |
    | | information_schema |                 |     并启动成功了!               |
    | | mysql              |                 |                         |
    | | test               |                 |                         |
    | +--------------------+                 |                         |
    +---------------------------------------------------------------------------------------+

      4).接上步,修改mysql密码(可不做此步,默认无密码)

    +-------------------------------------------------------------------------------+
    |          操作                    |          作用          |    
    +-------------------------------------------------------------------------------+
    |mysql>UPDATE user SET                     |                    |
    | password=PASSWORD('new_password')          |     修改root用户的密码     |
    | WHERE user='root';                    |                    |
    |-------------------------------------------------------------------------------+
    |mysql>flush privileges;               |     清空权限缓存          |
    +-------------------------------------------------------------------------------+

    二.安装 apache2

      1) 安装zlib压缩库

    shell> cd /usr/local/src
    shell> tar -zxvf zlib-1.2.3.tar.gz
    shell> cd zlib-1.2.3
    shell>./configure      //这个配置编译命令不要加目录参数
    shell> make && make install

         2)安装apache:

    shell> cd /usr/local/src
    shell> tar -zxvf httpd-2.2.4.tar.gz
    shell> cd httpd-2.2.4
    shell>./configure --prefix=/usr/local/http2  
         --enable-modules=most 
         --enable-rewrite     
         --enable-ssl       #支持https的访问
         --enable-so
    
    shell> make && make install
    
    #启动Apache
    /usr/local/http2/bin/apachectl start
    
    #测试apache
    浏览器打开: http://虚拟机IP
    如果没有成功的话,可能是防火墙的问题 这时需要我们去设置防火墙 打开80端口
    
    看到 "it works!",即为成功

    三.安装图形库,为编译php做准备:

      

    1)libxml2
    shell> cd /usr/local/src
    shell> tar -zxvf libxml2-2.6.19.tar.gz
    shell> cd libxml2-2.6.19
    shell>./configure --prefix=/usr/local/libxml2
    shell> make && make install
    
    
    2)jpeg6
    #安装出现错误   提示无关键目录无法继续 
    #手动建立如下目录 ,注意 man1是数字1,不是字母L
    shell> mkdir -p /usr/local/jpeg6
    shell> mkdir -p /usr/local/jpeg6/bin
    shell> mkdir -p /usr/local/jpeg6/lib
    shell> mkdir -p /usr/local/jpeg6/include
    shell> mkdir -p /usr/local/jpeg6/man
    shell> mkdir -p /usr/local/jpeg6/man1
    shell> mkdir -p /usr/local/jpeg6/man/man1
    
    shell> cd /usr/local/src
    shell> tar -zxvf jpegsrc.v6b.tar.gz
    shell> cd jpeg-6b
    shell>./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
    shell> make && make install
    
    3)libpng
    shell> cd /usr/local/src
    shell> tar -zvxf libpng-1.2.12.tar.gz
    shell> cd libpng-1.2.12
    shell>./configure  #和zlib一样不要带参数,让它默认安装到相应目录
    shell> make && make install
    
    
    4)freetype
    shell> cd /usr/local/src
    shell> tar -zvxf freetype-2.3.4.tar.gz
    shell> cd freetype-2.3.4
    shell> mkdir -p /usr/local/freetype
    shell>./configure --prefix=/usr/local/freetype
    shell> make && make install
    
    
    5)GD库
    shell> cd /usr/local/src
    shell> tar -zvxf gd-2.0.35.tar.gz
    shell> mkdir -p /usr/local/gd
    shell> cd gd-2.0.35
    shell>./configure --prefix=/usr/local/gd  
         --with-jpeg=/usr/local/jpeg6/      
         --with-png --with-zlib 
         --with-freetype=/usr/local/freetype
    shell> make && make instal

       4).安装php:

    shell> cd /usr/local/src
    shell> tar -zxvf php-5.3.16.tar.gz
    shell> cd php-5.3.16 (必须使用php 5.3 不然的话 就会出现 配置选项不正确)
    shell>./configure --prefix=/usr/local/php 
         --with-apxs2=/usr/local/http2/bin/apxs 
         --with-mysql=mysqlnd 
         --with-pdo-mysql=mysqlnd 
         --with-mysqli=mysqlnd 
         --with-freetype-dir=/usr/local/freetype 
         --with-gd=/usr/local/gd 
         --with-zlib --with-libxml-dir=/usr/local/libxml2 
         --with-jpeg-dir=/usr/local/jpeg6 
         --with-png-dir 
         --enable-mbstring=all 
         --enable-mbregex 
         --enable-shared
    shell> make && make install
    shell> cp php.ini-dist /usr/local/php/lib/php.ini

    五. 配置apache,使其支持PHP

    vi /usr/local/http2/conf/httpd.conf
    1):在httpd.conf(Apache主配置文件)中增加:
    AddType application/x-httpd-php .php
    
    2):找到下面这段话:
    <IfModule dir_module>
        DirectoryIndex index.html
    </IfModule>
    
    在index.html 前面添加index.php
    
    
    3):建立php测试网页
    vi /usr/local/http2/htdocs/index.php    
    输入如下内容:
    <?php
    phpinfo();
    ?>
    
    4): 重启apache
    shell> /usr/local/http2/bin/apachectl restart
    
    5):再次浏览器查看http://虚拟机IP
    如果看到php信息,工作就完成了!

    六 配置虚拟主机:

      

    1)配置host文件
    打开C:/windows/system32/drivers/etc/hosts 文件
    增加域名记录
    如:
    192.168.1.246     www.ec1.com
    192.168.1.246     www.ec2.com
    
    2) 增加虚拟主机
    vi /usr/local/http2/conf/httpd.conf
    取消#Include conf/extra/httpd-vhosts.conf
    这一行前面的#号
    保存退出
    
    vi /usr/local/http2/conf/extra/httpd-vhosts.conf
    增加虚拟主机记录
    
    <VirtualHost *:80>
        ServerAdmin webmaster@dummy-host.example.com
        DocumentRoot "/usr/local/http2/htdocs/ec1"
        ServerName www.ec1.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/http2/htdocs/ec2"
        ServerName www.ec2.com
        ErrorLog "logs/dummy-host2.example.com-error_log"
        CustomLog "logs/dummy-host2.example.com-access_log" common
    </VirtualHost>
    
    
    3)     
      shell> cd /usr/local/http2/htdocs
      shell> mkdir ec1 ec2
      shell> echo this is ec1.com > ec1/index.html
      shell> echo this is ec2.com > ec2/index.html
    
    4)重启apache
    /usr/local/http2/bin/apachectl restart
    
    
    5)浏览器打开www.ec1.com,和www.ec2.com
    看到不同的网站内容,虚拟主机创建完毕!

    以上就是整个配置流程,当然这个是源码编译的,你也可以使用yum进行安装!

  • 相关阅读:
    bzoj2467 [中山市选2010]生成树
    hdu4489 The King’s Ups and Downs
    hdu4489 The King’s Ups and Downs
    Tyvj1014(区间dp)
    Tyvj1014(区间dp)
    Tyvj1013
    Tyvj1013
    Tyvj1009
    22.引用指针
    21.引用指针
  • 原文地址:https://www.cnblogs.com/shangzekai/p/4374489.html
Copyright © 2011-2022 走看看