天天看点

Linux 下源码搭建LAMP环境

Step0:准备工作

①将需要的所有软件包分类传到/root/目录下.

<a href="http://blog.51cto.com/attachment/201308/110202493.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110202670.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110202446.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110203993.png" target="_blank"></a>

②将所有的源码包进行解压缩到指定的路径(/usr/local/src)除了phpmyadmin

tar zxvf apr-1.4.5.tar.gz -C /usr/local/src/

tar zxvf apr-util-1.3.12.tar.gz  -C /usr/local/src/

tar jxvf httpd-2.4.4.tar.bz2  -C /usr/local/src/

tar zxvf cmake-2.8.10.2-Linux-i386.tar.gz  -C /usr/local/src/

tar zxvf mysql-5.6.10.tar.gz  -C /usr/local/src/

tar jxvf php-5.4.14.tar.bz2  -C /usr/local/src/

unzip phpMyAdmin-3.5.8-all-languages.zip 

mv  phpMyAdmin-3.5.8-all-languages  phpmyadmin

cd  /usr/local/src/ 

见下图

<a href="http://blog.51cto.com/attachment/201308/110203202.png" target="_blank"></a>

Step1:源码编译Apache

Apache编译需要apr和apr-util的支持,所以需要预先编译这两个源码.

说明:APR(Apache portable Run-time libraries)Apache可移植运行库,主要为上层的应用程序提供可以跨越多操作系统平台使用的底层支持接口库。APR开发项目实际上包含了三个开发包:apr、apr-util、apr-iconv,给一个开发包分别独立开发,并分别由自己的版本。

①cd /apr-1.4.5

  ./configure  --prefix=/usr/local/apr

  (指定apr安装目录,更多参数参见./configure --help)

   make &amp;&amp; make install 

②cd /apr-util-1.3.12

./configure --prefix=/usr/local/apr-util 

--with-apr=/usr/apr/bin/apr-1-config

(指定apr-util的安装目录以及apr的配置文件的路径)

  更多参数详见  ./configure --help 

  make &amp;&amp; make install 

③cd /httpd-2.4.4

./configure  

   --prefix=/usr/local/apache (指定Apache的安装目录)

   --sysconfdir=/etc/httpd  (指定Apache服务的配置脚本目录)  

   --enable-so  (启用Apache的DSO动态共享对象功能)

   --enable-ssl (启用Apache的SSL/TLS功能)

   --enable-rewrite (启用地址重写功能)

   --with-apr=/usr/local/apr/bin/apr-1-config (apr配置脚本目录)     

   --with-apr-util=/usr/local/apr/bin/apu-1-config (apu配置目录)

   --with-pcre (扩展的PCRE库) 

   注:需要安装pcre包 (yum install pcre*)

   --with-z (启用压缩库)

   --enable-mpms-shared=all(自动选择MPM类型)

   make  &amp;&amp; make install  

④编辑/etc/man.config文件,将Apache源码的man路径加入到配置中。 

<a href="http://blog.51cto.com/attachment/201308/110203458.png" target="_blank"></a>

⑤软连接将Apache源码的include/目录下的头文件加入到系统路径中。

 ln -s /usr/local/apache/include/   /usr/include/apache 

⑥自编写bash脚本,来完成Apache服务的start、stop、restart等操作,并且能接受chkconfig的管理。

  vim  httpd  

<a href="http://blog.51cto.com/attachment/201308/110204744.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110205681.png" target="_blank"></a>

mv  httpd  /etc/init.d/ 

  chmod  a+x  /etc/init.d/httpd 

⑦启动Apache服务,并观察端口状态。

  service httpd  start 

  chkconfig httpd on 

  chkconfig --list | grep httpd 

<a href="http://blog.51cto.com/attachment/201308/110205289.png" target="_blank"></a>

netstat -tupln | grep 80 

<a href="http://blog.51cto.com/attachment/201308/110205899.png" target="_blank"></a>

Step2:源码编译MySQL

①源码安装编译MySQL需要的cmake工具。

  mv /usr/local/src/cmake-2.8.10.2-Linux-i386  /usr/local/cmake

  编辑/etc/profile文件,把cmake的bin路径加入到系统路径中。

<a href="http://blog.51cto.com/attachment/201308/110205635.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110205841.png" target="_blank"></a>

②编译MySQL.

  cd  /usr/local/src/mysql-5.6.10/

  cmake . 

  make  &amp;&amp; make install (估计20分钟左右)

③创建mysql组和mysql账号(系统服务账号),修改mysql目录的权限。

  useradd  -r  -g  mysql  mysql 

  cd /usr/local/mysql 

  chown  -R  mysql  .

  chgrp  -R  mysql  .

<a href="http://blog.51cto.com/attachment/201308/110206552.png" target="_blank"></a>

 以mysql的身份初始化MySQL数据库。

  scripts/mysql_install_db --user=mysql

  把mysql目录的所有者权限改回root,除了data/目录。

  chown -R root .

  chgrp -R mysql data/

<a href="http://blog.51cto.com/attachment/201308/110206536.png" target="_blank"></a>

④拷贝样例配置文件,形成MySQL的主配置文件。

  cp /usr/local/mysql/support-files/my-default.cnf  /etc/my.cnf

  cp /usr/local/mysql/support-files/mysql.server  /etc/init.d/mysqld

⑤ 启动MySQL服务,并观察端口状态.

  service mysqld start

  netstat  -tupln | grep 3306

<a href="http://blog.51cto.com/attachment/201308/110206194.png" target="_blank"></a>

⑥编辑/etc/profile文件,将MySQL源码的bin路径加入到环境变量中。

<a href="http://blog.51cto.com/attachment/201308/110207127.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110207757.png" target="_blank"></a>

⑦编辑/etc/ld.so.conf.d/mysql.conf文件,将MySQL源码的lib路径加入系系统库中。

<a href="http://blog.51cto.com/attachment/201308/110207855.png" target="_blank"></a>

ldconfig刷新库lib动态链接库。

查看有没有加载成功。

<a href="http://blog.51cto.com/attachment/201308/110207994.png" target="_blank"></a>

⑧软连接将MySQL源码的include/目录下的头文件加入到系统路径中。

  ln -s /usr/local/mysql/include/   /usr/include/mysql

Step3:源码编译PHP

①cd /usr/local/src/php-5.4.14/

./configure  --prefix=/usr/local/php(指定安装目录)

   --with-apxs2=/usr/local/apache/bin/apxs

(将php编译成apache的模块,允许apache的apxx调用该模块)

  --with-mysql=/usr/local/mysql (指明mysql的安装位置) 

  --with-mysqli=/usr/local/mysql/bin/mysql_config(调用myql接口)

  -enable-mbstring=all(指定字符集)

  --with-xml

  --with-png  --with-jpeg  --with-gd  --with-zlib --with-freetype

  xml|png|zlib|jpeg|freetype是apache的一些绘图功能

  make &amp;&amp; make install  

②编辑/etc/profile文件,将PHP源码的bin路径加入到环境变量中。

<a href="http://blog.51cto.com/attachment/201308/110207245.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110208189.png" target="_blank"></a>

③编辑/etc/ld.so.conf.d/php.conf文件,将PHP源码的lib路径加入到系统库中。

<a href="http://blog.51cto.com/attachment/201308/110208258.png" target="_blank"></a>

④软连接将PHP源码的include/目录下的头文件加入到系统路径中。

  ln -s /usr/local/php/include/   /usr/include/php

⑤编辑Apache的配置文件,添加支持PHP的一些模块处理功能。

<a href="http://blog.51cto.com/attachment/201308/110208368.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110208544.png" target="_blank"></a>

⑥service httpd restart

①cp -r /root/PHP/phpmyadmin/   /usr/local/apache/htdocs/

②cd  /usr/local/apache/htdocs/phpmyadmin

③cp -p config.sample.inc.php  config.inc.php

④修改MySQL数据库的root管理员密码

  mysqladmin  -u  root  -p  password ‘123456’

  Enter password:(原密码为空----回车)

【环境测试】

浏览器输入基于物理目录的地址来Web管理MySQL数据库.

<a href="http://apacheserverip/phpmyadmin">http://ApacheServerIP/phpmyadmin</a>

 (账号:root;密码:123456)

<a href="http://blog.51cto.com/attachment/201308/110209500.png" target="_blank"></a>

<a href="http://blog.51cto.com/attachment/201308/110210622.png" target="_blank"></a>

END ! ! ! 

     本文转自Tar0 51CTO博客,原文链接:http://blog.51cto.com/tar0cissp/1282655,如需转载请自行联系原作者