最近,部门有些系统需要迁移到新的机器上,因此需要在新的机器上安装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..tar.gz | 解压mysql源码包 |
|-------------------------------------------------------------------------------|
|shell> cd mysql-5.1. | 进入源码包 |
|-------------------------------------------------------------------------------|
|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..tar.gz
shell> cd zlib-1.2.
shell>./configure //这个配置编译命令不要加目录参数
shell> make && make install

2)安装apache:

shell> cd /usr/local/src
shell> tar -zxvf httpd-2.2..tar.gz
shell> cd httpd-2.2.
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做准备:

  

)libxml2
shell> cd /usr/local/src
shell> tar -zxvf libxml2-2.6..tar.gz
shell> cd libxml2-2.6.
shell>./configure --prefix=/usr/local/libxml2
shell> make && make install )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 )libpng
shell> cd /usr/local/src
shell> tar -zvxf libpng-1.2..tar.gz
shell> cd libpng-1.2.
shell>./configure #和zlib一样不要带参数,让它默认安装到相应目录
shell> make && make install )freetype
shell> cd /usr/local/src
shell> tar -zvxf freetype-2.3..tar.gz
shell> cd freetype-2.3.
shell> mkdir -p /usr/local/freetype
shell>./configure --prefix=/usr/local/freetype
shell> make && make install )GD库
shell> cd /usr/local/src
shell> tar -zvxf gd-2.0..tar.gz
shell> mkdir -p /usr/local/gd
shell> cd gd-2.0.
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..tar.gz
shell> cd php-5.3. (必须使用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
):在httpd.conf(Apache主配置文件)中增加:
AddType application/x-httpd-php .php ):找到下面这段话:
<IfModule dir_module>
DirectoryIndex index.html
</IfModule> 在index.html 前面添加index.php ):建立php测试网页
vi /usr/local/http2/htdocs/index.php
输入如下内容:
<?php
phpinfo();
?> ): 重启apache
shell> /usr/local/http2/bin/apachectl restart ):再次浏览器查看http://虚拟机IP
如果看到php信息,工作就完成了!

六 配置虚拟主机:

  

)配置host文件
打开C:/windows/system32/drivers/etc/hosts 文件
增加域名记录
如:
192.168.1.246 www.ec1.com
192.168.1.246 www.ec2.com ) 增加虚拟主机
vi /usr/local/http2/conf/httpd.conf
取消#Include conf/extra/httpd-vhosts.conf
这一行前面的#号
保存退出 vi /usr/local/http2/conf/extra/httpd-vhosts.conf
增加虚拟主机记录 <VirtualHost *:>
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 *:>
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> )
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 )重启apache
/usr/local/http2/bin/apachectl restart )浏览器打开www.ec1.com,和www.ec2.com
看到不同的网站内容,虚拟主机创建完毕!

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

lamp环境的搭建和安装的更多相关文章

  1. linux之lamp环境的搭建

    linux之lamp环境的搭建 1.安装lamp环境的安装工具 我们的lamp环境都是采用源码包进行编译安装: 编译安装需要工具gcc gcc-c++. 建议在线联网安装:yum  -install ...

  2. LAMP环境的搭建

    [一些前言废话]一名web开发尤其是后端不懂LAMP环境的搭建,那就摊上事了,有些人说他一直用win下的wampServer这种傻瓜式环境搭建,用的挺好的,也有人说他用云服务器,搭配“一键搭建LAMP ...

  3. Linux:LAMP环境的搭建

    LAMP环境的搭建 安装DNS服务器 安装DNS服务 yum install bind -y DNS的配置 创建正向解析 以创建一个名为"lsy.com"的正向查找区域为例: 第一 ...

  4. LAMP环境源码编译安装过程

    LAMP环境源码编译安装过程 一.Apache的安装 1.1.apache软件包及依赖包准备 httpd-2.4.29.tar.bz2       apr-1.6.3.tar.gz      apr- ...

  5. LAMP环境 源码包安装

    linux的学习很早就开始了,大学的时候的时候有有学过unix,后来每年都有去看看linux,因为在小城市的缘故,很少会实际工作中用到,基本都是智慧云之类的,同事也说,你学起来也用不上,IT生态不好, ...

  6. LAMP环境的搭建(四)----Apache下部署项目

    根据前文完成了LAMP基本环境的安装,那么接下来就是部署线上的环境了. yum 安装的apache 目录存在于  /etc/httpd apache最重要的文件就是 httpd.conf.  目录再 ...

  7. PHP学习记录第一篇:Ubuntu14.04下LAMP环境的搭建

    最近一段时间会学习一下PHP全栈开发,将会写一系列的文章来总结学习的过程,以自勉. 第一篇记录一下LAMP环境的安装 0. 安装Apache Web服务器 安装之前先更新一下系统 sudo apt-g ...

  8. LAMP环境的搭建(三)----PHP7的安装

    centos自带的PHP源是5.4版本的.如果需要安装PHP 5.4 直接输入 yum install php -y 即可 因为PHP7性能巨大的提升,因此本文选择安装PHP7 如果已经安装过了php ...

  9. LAMP环境的搭建(二)----Mysql安装与配置

    Mysql是一款免费开源的关系型数据库. 尽管Mysql被oracle公司收购.但是oracle并没有限制了mysql的发展. 目前mysql是使用范围最广的关系型数据库,许多大型公司也在使用.截至本 ...

随机推荐

  1. MongoDB助力快速搭建物流订单系统

    简介 快递物流系统里最常见的一种业务类型就是订单的查询和记录.订单的特点是随着递送过程,订单数据需要随时更新路径.数据结构上需要可以灵活应对,这点非常符合Document模型,并且MongoDB支持G ...

  2. 因此mybatis最好与spring集成起来使用

    单独使用mybatis是有很多限制的(比如无法实现跨越多个session的事务),而且很多业务系统本来就是使用spring来管理的事务,因此mybatis最好与spring集成起来使用. spring ...

  3. 在Swing的组件中,基本上都是在AWT组件的名称前面加“J”

    在Swing的组件中,基本上都是在AWT组件的名称前面加“J”. 一般情况下,除了Choise等组件: import javax.swing.*;好要加上:import java.awt.*以及imp ...

  4. 【mysql-python】安装+基本使用

    安装:从SourceForge.net上下载最新的MySQLdb,http://sourceforge.net/projects/mysql-python/ 运行exe文件 使用 From:http: ...

  5. VS2008 对话框编辑器“即时预览”

    之前在VS2008中利用资源编辑器修改完对话框资源后,总是重新编译一下,然后Ctrl+F5运行来预览修改的效果,不断修改,不断编译,导致很费时,效率低下. 今天,发现了一个很好用的功能“Test Di ...

  6. 系统之间通讯方式—SOAP(web service)

    [web service 简介] 是一种新的web应用程序分支,是自包含.自描述.模块化的应用,可以发布.定位.通过web调用.web service是一个应用组件,它逻辑性的为其他应用程序提供数据与 ...

  7. 关于recycler遇到的问题

    1.//设置recyclerView不能点击myLayoutManager.setScrollEnabled(false);class MyLayoutManager extends LinearLa ...

  8. iOS 设置字体 自定义字体

    博文转载至 http://blog.csdn.net/trandy/article/details/8364517 1.网上搜索字体文件(后缀名为.ttf,或.odf) 2.把字体库导入到工程的res ...

  9. 工作表(Worksheet)基本操作应用示例

    在编写代码时,经常要引用工作表的名字.知道工作表在工作簿中的位置.增加工作表.删除工作表.复制工作表.移动工作表.重命名工作表,等等.下面介绍与此有关及相关的一些属性和方法示例. [示例04-01]增 ...

  10. sessionStorage与localStorage

    客户端存储数据的两个对象为: localStorage和sessionStorage一样都是用来存储客户端临时信息的对象. 他们均只能存储字符串类型的对象(虽然规范中可以存储其他原生类型的对象,但是目 ...