源码搭建lamp环境

一、编译LAMP前的准备工作

1、下载用到的源码包
zlib http://www.zlib.org
php http://www.php.net/downloads.php
ncurses http://ftp.gnu.org/pub/gnu/ncurses/
mysql http://download.mysql.cn/
libxml2 http://xmlsoft.org/downloads.html
libpng http://www.libpng.org/pub/png/libpng.html
libmcrypt http://freecode.com/projects/libmcrypt
jpeg6 http://lfs.linuxsir.org/htdocs/blfscvs/general/libjpeg.html
httpd http://httpd.apache.org/
gd http://www.boutell.com/gd/
freetype http://www.freetype.org/download.html
autoconf http://www.gnu.org/software/autoconf/
2、准备编译所需的工具 gcc、gcc-c++、make
[root@YYzs LAMP]# rpm -q make
make-3.81-19.el6.i686
[root@YYzs LAMP]# rpm -q gcc
gcc-4.4.4-13.el6.i686
[root@YYzs LAMP]# rpm -q gcc-c++
gcc-c++-4.4.4-13.el6.i686
//可以看到编译软件已经安装,如果未安装可用yum或挂载镜像安装盘利用rpm包安装
//如果觉得依赖问题麻烦且不能上网可把镜像盘作为yum源来安装
***以镜像盘做yum源的配置方法如下:***
//yum的配置文件中CentOS-Base.repo 是互联网用的基础配置文件 CentOS-Media.repo是光盘yum源 //的配置文件
[root@YYzs LAMP]# vi /etc/yum.repos.d/CentOS-Media.repo
//这时将enable=0改为1表示启用此功能
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
//这是表示设置光盘所在位置,如位置不同科在缺省位置上修改
//然后将/etc/yum.repos.d/CentOS-Base.repo配置文件移动到其他文件夹
[root@YYzs LAMP]# mkdir /backup
[root@YYzs LAMP]# mv /etc/yum.repos.d/CentOS-Base.repo /backup
[root@YYzs LAMP]#yum install gcc
3、卸载系统中已有的apache、mysql、php
//关闭或卸载,因为这可能会照成影响
[root@YYzs LAMP]# rpm -qa |grep httpd
httpd-tools-2.2.15-5.el6.centos.i686
httpd-2.2.15-5.el6.centos.i686
[root@YYzs LAMP]# rpm -qa |grep mysql
mysql-libs-5.1.47-4.el6.i686
mysql-5.1.47-4.el6.i686
mysql-devel-5.1.47-4.el6.i686
[root@YYzs LAMP]# rpm -qa |grep php
[root@YYzs LAMP]# yum remove httpd
[root@YYzs LAMP]# yum remove mysql
4、关闭SElinux、禁用iptables
vi /etc/sysconfig/selinux
//将SELINUX=enforcing修改为disabled然后重启生效
[root@YYzs LAMP]# chkconfig iptables off
//关闭防火墙
5.解压安装文件
//由于源码包太多因此可以写一个小的shell脚以方便解压,如果下载的源码包版本不一样记得修改一 下,或一个一个的安装也可以。
[root@YYzs LAMP]# vi tar.sh
#!/bin/bash
cd /tmp/LAMP
ls *.tar.gz > ls.list
for TAR in `cat ls.list`
do
tar -zxf $TAR
done
[root@YYzs LAMP]# sh -x tar.sh

二、正式安装

//安装原则是按照apache、mysql、php的顺序安装,所需的库文件可以最先安装,由于安装软件太多因此
//在这里还是以脚本的方式安装
[root@YYzs LAMP] vi lamp.sh

#!/bin/bash
###安装php库文件###

cd /tmp/LAMP/libxml2-2.6.30
./configure --prefix=/usr/local/libxml2/
make
make install

cd /tmp/LAMP/libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/
make
make install

cd /tmp/LAMP/libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install
make
make install

cd /tmp/LAMP/zlib-1.2.3
./configure
make
make install

cd /tmp/LAMP/libpng-1.2.31
./configure --prefix=/usr/local/libpng/
make
make install

#指定jpeg6安装目录
mkdir /usr/local/jpeg6
#指定命令文件存放目录
mkdir /usr/local/jpeg6/bin
#指定库文件存放目录
mkdir /usr/local/jpeg6/lib
#指定头文件存放目录
mkdir /usr/local/jpeg6/include
#指定帮助文档存放目录
mkdir -p /usr/local/jpeg6/man/man1
cd /tmp/LAMP/jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install

cd /tmp/LAMP/freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make
make install

cd /tmp/LAMP/autoconf-2.61
./configure
make
make install

cd /tmp/LAMP/gd-2.0.35
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
#指定前面所安装的库文件的目录
make
make install

###安装apache###

cd /tmp/LAMP/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-support
#安装目录、配置文件安装目录
make
make install

#启动apache
/usr/local/apache2/bin/apachectl start
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit

###安装mysq###

#编译mysql前要先安装否则可能会报错
cd /tmp/LAMP/ncurses-5.6
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install

groupadd mysql
useradd -g mysql mysql
cd /tmp/LAMP/mysql-5.0.41
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
#支持所有的字符集
make
make install

#生成mysql的配置文件
cp support-files/my-medium.cnf /etc/my.cnf
#创建mysql数据库授权表
/usr/local/mysql/bin/mysql_install_db --user=mysql
chown -R root /usr/local/mysql
chown -R mysql /usr/local/mysql/var
chgrp -R mysql /usr/local/mysql

/usr/local/mysql/bin/mysqld_safe --user=mysql &
[root@YYzs mysql-5.0.41]# ps -ef | grep myssqld
[root@YYzs mysql-5.0.41]# netstat -an |grep 3306
查看进程以及mysql监听的3306端口是否工作来看是否启动成功
[root@YYzs mysql-5.0.41]# /usr/local/mysql/bin/mysql -u root 设置mysql的root密码
mysql> SET PASSWORD FOR 'root'@'localhost'=PASSWORD('yyzs');
mysql> exit

cp /tmp/LAMP/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
chown root.root /etc/rc.d/init.d/mysqld
chmod 755 /etc/rc.d/init.d/mysqld
ls -l /etc/rc.d/init.d/mysqld
chkconfig --add mysqld
chkconfig --list mysqld
#将系统启动级别为245时设为不启动mysql
chkconfig --levels 245 mysqld off

###安装php###

cd /tmp/LAMP/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-sockets
make
make install

#拷贝配置文件
cp php.ini-dist /usr/local/php/etc/php.ini
#使apache能解析php
echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
/usr/local/apache2/bin/apachectl restart

//执行安装脚本
[root@YYzs LAMP]# sh -x lamp.sh

//在重启apache时出现错误httpd: Could not reliably determine the server's fully qualified //domain name
//解决方法是将/etc/httpd/httpd.conf 文件中的#ServerName 前的#去掉就好了

三、安装优化与管理工具

//安装Zend加速引擎
[root@YYzs lamp]# cd ZendOptimizer-3.2.6-linux-glibc21-i386
[root@YYzs ZendOptimizer-3.2.6-linux-glibc21-i386]# ./install.sh

//安装phpMyAdmain
[root@YYzs lamp]# cp -a /lamp/phpMyAdmin-3.0.0-rc1-all-languages /usr/local/apache2/htdocs/phpmyadmin
[root@YYzs phpmyadmin]# cp config.sample.inc.php config.inc.php
[root@YYzs phpmyadmin]# vi config.inc.php
//更改认证方式将['auth_type'] = 'cookie' 改为'http'

四、测试apache是否正常工作以及是否能正常解析php

1.在windows xp 下的ie浏览器中输入:192.168.1.107 回车,显示为:it works, 表示apache正常工作
2. vi /usr/local/apache2/htdocs/info,php
<?
phpinfo();
?>
此时在windows xp的ie浏览器输入:http://192.168.1.107/info.php 显示的是php的信息界面,说明 apache正常解析了php

注:在装php时出现了问题,先用make test来试探就出问题了。
报错:
usr/local/src/php-5.2.6/sapi/cli/php: error while loading shared libraries:libltdl.so.3
分析了日志,网查查了下发现php5.2.6版本打开了cli功能,所以最后,用yum install libtool-libs或yum install libtool-ltdl-devel
补充了安装。

原文链接: https://www.cnblogs.com/YYzs/archive/2012/06/14/2549113.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    源码搭建lamp环境

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/52705

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 上午4:08
下一篇 2023年2月9日 上午4:09

相关推荐