分离php和mysql搭建LAMP平台

  正常情况下,在同一台服务器上搭建LAMP平台时各组件安装顺序是:Linux-mysql-apache-php。其中mysql和apache安装没有前后顺序。而对于mysql和apache+mysql不在一台服务器的时候,如何让PHP能够连接到MySQL呢?

  一、安装Mysql服务器 (mysql服务器IP地址:192.168.10.2)

     1、创建mysql运行用户

    [转载]分离php和mysql搭建LAMP平台

     2、解码mysql源码包(mysql-5.1.55)

   [转载]分离php和mysql搭建LAMP平台

    3、配置,并指定安装路径

[转载]分离php和mysql搭建LAMP平台

  4、修改include子文件夹下的config.h文件,实现完美支持gbk,gb2312字符集编码

   [转载]分离php和mysql搭建LAMP平台

    5、编译及安装

   [转载]分离php和mysql搭建LAMP平台

    6、建立my.conf配置文件 

    [转载]分离php和mysql搭建LAMP平台

    7、初始化数据库文件,并授予mysql用户运行权限

[转载]分离php和mysql搭建LAMP平台

    8、优化路径

[转载]分离php和mysql搭建LAMP平台

    9、添加系统服务

    [转载]分离php和mysql搭建LAMP平台

    10、启动服务,并修改mysql管理员密码[转载]分离php和mysql搭建LAMP平台

    11、授权mysql管理员远程登录mysql数据库

     [转载]分离php和mysql搭建LAMP平台

 二、apache+php安装(服务器IP地址:192.168.10.1)

   <一>apache安装

     1、卸载rpm包安装的httpd服务

     [转载]分离php和mysql搭建LAMP平台

     2、解包

     [转载]分离php和mysql搭建LAMP平台

     3、配置

[转载]分离php和mysql搭建LAMP平台

     4、编译安装

 [转载]分离php和mysql搭建LAMP平台

   5、优化路径

   [转载]分离php和mysql搭建LAMP平台
  6、添加系统服务

[转载]分离php和mysql搭建LAMP平台
  7、启动服务

  [转载]分离php和mysql搭建LAMP平台

   8、客户端测试首页

  [转载]分离php和mysql搭建LAMP平台

 

<二>PHP安装

   1、安装数据加密等扩展工具(如libmcrypt、mhash、mcrypt)

      注意:这三个包mcrypt要最后安装

[转载]分离php和mysql搭建LAMP平台

  2、编译安装php [转载]分离php和mysql搭建LAMP平台
  3、建立php.ini配置文件并调整内容  [转载]分离php和mysql搭建LAMP平台

 4、调整httpd.conf内容

   [转载]分离php和mysql搭建LAMP平台

 5、测试php和apache是否成功

   [转载]分离php和mysql搭建LAMP平台
[转载]分离php和mysql搭建LAMP平台

三、实现php连接mysql

  php连接mysql可以通过mysq_connect函数来连接。

  首先php要添加对mysql模块的支持,由于mysql和php不在同一台服务器,所哟我们添加php的扩展模块。

  1、在apache+php服务器上安装mysql-devel [转载]分离php和mysql搭建LAMP平台
 2、切换到php源代码包的扩展目录下的mysql目录下运行phpize命令来生成配置文件

  [转载]分离php和mysql搭建LAMP平台

3、配置,编译及安装(安装完成之后会在扩展模块路径下生成一个mysql.so模块文件

 [转载]分离php和mysql搭建LAMP平台

4、将扩展模块添加到php.ini配置文件

[转载]分离php和mysql搭建LAMP平台

5、重启httpd服务,编写一个mysql连接测试页面

 [转载]分离php和mysql搭建LAMP平台

6、客户端访问测试

[转载]分离php和mysql搭建LAMP平台



linux技术交流群:295294329

  





   

 


原网页地址:http://blog.sina.com.cn/s/blog_b6e37c3f0101oo81.ht...
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章