在CentOS 6.0下搭建LAMP环境(源码安装)
程序员文章站
2022-07-15 22:54:20
...
转自 http://auction1.taobao.com/auction/item_detail-0db2-c96f1f929a63eed04664eccbcc912d28.jhtml
<p><span style="color:#ff0000">历史两日,终于在centos 6.0上搭建好了完整的LAMP开发环境,中间有很多麻烦,但还是一点点解决了。并且写好了这份安装文档,留给自己和以后再安装中遇到问题的人。予人玫瑰,手留余香。</span><br>
</p>
<p><span style="font-size:24px">一、搭建环境:</span></p>
<p>1、CentOS 6.0虚拟机(最小安装)<br>
</p>
<p>2、putty</p>
<p>3、ssh shell</p>
<p><span style="font-size:24px">二、准备工作:</span></p>
<p>1、源码包</p>
<p><img src="http://hi.csdn.net/attachment/201107/30/10062493_13120168992bK7.jpg" alt=""><br>
</p>
<p>2、安装gcc、gcc-c++编译器(yum安装)</p>
<p>若虚拟机能联网,直接输入命令<span style="color:#ff0000">yum install gcc</span>和<span style="color:#ff0000">yum install gcc-c++</span>;若不能联网,将centos光盘镜像挂载上,修改yum的本地源,使机器从本地源yum方式安装</p>
<p>3、检查机器上是否已经安装了mysql、php、apache,使用命令<span style="color:#ff0000">rpm -qa mysql</span>。若安装了,则使用命令rpm -e 包的全名 --nodeps卸载</p>
<p>4、关闭selinux,清空防火墙规则</p>
<p>5、开放80、3306、22端口</p>
<p>因为默认情况下,防火墙的80、3306、22端口是关闭的,这样的话对于客户机访问虚拟机上的web,会出现访问不到的现象。所以要开启。</p>
<p><span style="color:#ff0000">service iptables stop</span></p>
<p><span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT</span> //那是大写的英文字母I,不是数字1<br>
<span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT</span><br>
<span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT</span></p>
<p>然后保存:<br>
<span style="color:#ff0000">#/etc/rc.d/init.d/iptables save</span></p>
<p>重启防火墙</p>
<p><span style="color:#ff0000">service iptables restart</span><br>
</p>
<p>6、在linux下建立目录lamp,存放上传的源码</p>
<p>7、使用ssh shell将windows下下载好的14个源码包上传到/lamp</p>
<p>8、解包</p>
<p>因为包很多,这里编写shell脚本/lamp/tar.sh进行解包</p>
<p>tar.sh<br>
</p>
<p></p>
<textarea readonly name="code" class="plain">#!/bin/sh
cd /lamp
ls *.tar.gz > ls.list
for TAR in `cat ls.list`
do
tar -zxvf $YAR
done</textarea>执行脚本tar.sh进行解包<br>
<p></p>
<p>9、将源码包*.tar.gz全都删除<br>
<span style="font-size:24px">三、安装过程:</span></p>
<p>1、为方便操作,编写安装脚本/lamp/lamp.sh进行安装</p>
<p>lamp.sh</p>
<p></p>
<textarea readonly name="code" class="plain">cd /lamp/libxml2-2.6.30
./configure --prefix=/usr/local/libxml2/
make
make install
cd /lamp/libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/
make
make install
cd /lamp/libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install
make
make install
cd /lamp/zlib-1.2.3
./configure
make
make install
cd /lamp/libpng-1.2.31
./configure --prefix=/usr/local/libpng/
make
make install
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 /lamp/jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install
cd /lamp/freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make
make install
cd /lamp/autoconf-2.61
./configure
make
make install
cd /lamp/gd-2.0.35
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
make
make install
cd /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
/usr/local/apache2/bin/apachectl start
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
cd /lamp/ncurses-5.6
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install
groupadd mysql
useradd -g mysql mysql
cd /lamp/mysql-5.0.41
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
/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 &
cp /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
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig --levels 245 mysqld off
cd /lamp/php-5.2.6
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apx --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
echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
/usr/local/apache2/bin/apachectl restart
</textarea>执行脚本,进行安装(时间很长,可以去睡觉了<img alt="偷笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/titter.gif">)
<p></p>
<p>2、配置mysql</p>
<p><span style="color:#ff0000">cd /usr/local/mysql</span></p>
<p><span style="color:#ff0000">bin/mysqladmin version</span> //简单的测试</p>
<p><span style="color:#ff0000">bin/mysqladmin varibles</span> //查看所有mysql参数</p>
<p><span style="color:#ff0000">bin/mysql -u root</span> //没有密码可以直接登录本机服务器</p>
<div><span style="color:#ff0000">mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';</span></div>
<div><span style="color:#ff0000">mysql> FLUSH PRIVILEGES;</span></div>
<div><span style="color:#ff0000">mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');</span><br>
3、安装zend加速器<br>
<span style="color:#ff0000">mkdir /usr/local/php/etc</span><br>
<span style="color:#ff0000">cp php.ini-dist /usr/local/php/etc/php.ini</span> //更改之前设定的php.ini的配置文件位置,安装zend要用<br>
进入Zend包的目录<br>
<span style="color:#ff0000">./install-tty</span><br>
4、phpmyadmin的安装与配置<br>
<span style="color:#ff0000">cd /lamp</span><br>
<div><span style="color:#ff0000">cp -a phpMyAdmin-3.0.0-rc1-all-languages /var/www/html/phpmyadmin</span> //拷贝目录到指定位置(网站主目录/var/www/html下)并改名为phpmyadmin</div>
<div><span style="color:#ff0000">cd /usr/local/apache2/htdocs/phpmyadmin/</span></div>
<div><span style="color:#ff0000">cp config.sample.inc.php config.inc.php</span><br>
进入/var/www/html/phpmyadmin<br>
修改配置文件config.inc.php,将$cfg['blowfish_secret'] = '' 空格处填上登录phpmyadmin的密码,例如:$cfg['blowfish_secret'] = '123456'<br>
<br>
</div>
</div>
<p><span style="font-size:24px">四、常见错误及备注:</span></p>
<p>1、若shell脚本是从windows上传到linux上,而不是直接在linux上写的,可能会出现执行错误。解决办法见我的另一篇日志:<span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6636648" title="shell脚本在Linux下运行错误的解决方法">《shell脚本在Linux下运行错误的解决方法》</a></span></p>
2、对不能联网状态下yum本地安装的方法,见 <span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6636790" title="centos上不能联网状况下yum本地安装软件包">《centos虚拟机不能联网状况下yum方式从本地安装软件包》</a></span>
<p>3、linux启动apache libltdl.so.3:cannot open shared object file:No such file or directory异常</p>
<p>执行<span style="color:#ff0000">ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3</span> 即可</p>
<p>4、若出现Address already in use: make_sock: could not bind to address [::]:80异常</p>
<p>解决方法:reboot启动linux</p>
<p>5、若出现在linux终端执行clear或者top命令时出现:‘xterm’:unknown terminal type的错误,参考<span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6638858" title="在linux终端执行clear或top命令时出现:'xterm': unknown terminal type的错误">《在linux终端执行clear或top命令时出现:'xterm':
unknown terminal type的错误》</a></span></p>
<p>6、文中源码包和tar.sh、lamp.sh脚本的下载 <a href="http://u.115.com/file/dn9qqc4x#">点击下载</a> 提取码:<em><span rel="select">dn9qqc4x</span></em><br>
</p>
<p>7、若有其他错误,请百度寻找答案,或者给我发邮件guoyin0612@163.com</p>
<br>
<br>
<p></p>
<p><span style="color:#ff0000">历史两日,终于在centos 6.0上搭建好了完整的LAMP开发环境,中间有很多麻烦,但还是一点点解决了。并且写好了这份安装文档,留给自己和以后再安装中遇到问题的人。予人玫瑰,手留余香。</span><br>
</p>
<p><span style="font-size:24px">一、搭建环境:</span></p>
<p>1、CentOS 6.0虚拟机(最小安装)<br>
</p>
<p>2、putty</p>
<p>3、ssh shell</p>
<p><span style="font-size:24px">二、准备工作:</span></p>
<p>1、源码包</p>
<p><img src="http://hi.csdn.net/attachment/201107/30/10062493_13120168992bK7.jpg" alt=""><br>
</p>
<p>2、安装gcc、gcc-c++编译器(yum安装)</p>
<p>若虚拟机能联网,直接输入命令<span style="color:#ff0000">yum install gcc</span>和<span style="color:#ff0000">yum install gcc-c++</span>;若不能联网,将centos光盘镜像挂载上,修改yum的本地源,使机器从本地源yum方式安装</p>
<p>3、检查机器上是否已经安装了mysql、php、apache,使用命令<span style="color:#ff0000">rpm -qa mysql</span>。若安装了,则使用命令rpm -e 包的全名 --nodeps卸载</p>
<p>4、关闭selinux,清空防火墙规则</p>
<p>5、开放80、3306、22端口</p>
<p>因为默认情况下,防火墙的80、3306、22端口是关闭的,这样的话对于客户机访问虚拟机上的web,会出现访问不到的现象。所以要开启。</p>
<p><span style="color:#ff0000">service iptables stop</span></p>
<p><span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT</span> //那是大写的英文字母I,不是数字1<br>
<span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 22 -j ACCEPT</span><br>
<span style="color:#ff0000">#/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT</span></p>
<p>然后保存:<br>
<span style="color:#ff0000">#/etc/rc.d/init.d/iptables save</span></p>
<p>重启防火墙</p>
<p><span style="color:#ff0000">service iptables restart</span><br>
</p>
<p>6、在linux下建立目录lamp,存放上传的源码</p>
<p>7、使用ssh shell将windows下下载好的14个源码包上传到/lamp</p>
<p>8、解包</p>
<p>因为包很多,这里编写shell脚本/lamp/tar.sh进行解包</p>
<p>tar.sh<br>
</p>
<p></p>
<textarea readonly name="code" class="plain">#!/bin/sh
cd /lamp
ls *.tar.gz > ls.list
for TAR in `cat ls.list`
do
tar -zxvf $YAR
done</textarea>执行脚本tar.sh进行解包<br>
<p></p>
<p>9、将源码包*.tar.gz全都删除<br>
<span style="font-size:24px">三、安装过程:</span></p>
<p>1、为方便操作,编写安装脚本/lamp/lamp.sh进行安装</p>
<p>lamp.sh</p>
<p></p>
<textarea readonly name="code" class="plain">cd /lamp/libxml2-2.6.30
./configure --prefix=/usr/local/libxml2/
make
make install
cd /lamp/libmcrypt-2.5.8
./configure --prefix=/usr/local/libmcrypt/
make
make install
cd /lamp/libmcrypt-2.5.8/libltdl
./configure --enable-ltdl-install
make
make install
cd /lamp/zlib-1.2.3
./configure
make
make install
cd /lamp/libpng-1.2.31
./configure --prefix=/usr/local/libpng/
make
make install
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 /lamp/jpeg-6b
./configure --prefix=/usr/local/jpeg6/ --enable-shared --enable-static
make
make install
cd /lamp/freetype-2.3.5
./configure --prefix=/usr/local/freetype/
make
make install
cd /lamp/autoconf-2.61
./configure
make
make install
cd /lamp/gd-2.0.35
./configure --prefix=/usr/local/gd2/ --with-jpeg=/usr/local/jpeg6/ --with-freetype=/usr/local/freetype/
make
make install
cd /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
/usr/local/apache2/bin/apachectl start
echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
cd /lamp/ncurses-5.6
./configure --with-shared --without-debug --without-ada --enable-overwrite
make
make install
groupadd mysql
useradd -g mysql mysql
cd /lamp/mysql-5.0.41
./configure --prefix=/usr/local/mysql/ --with-extra-charsets=all
make
make install
cp support-files/my-medium.cnf /etc/my.cnf
/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 &
cp /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
chkconfig --add mysqld
chkconfig --list mysqld
chkconfig --levels 245 mysqld off
cd /lamp/php-5.2.6
./configure --prefix=/usr/local/php/ --with-config-file-path=/usr/local/php/etc/ --with-apxs2=/usr/local/apache2/bin/apx --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
echo "Addtype application/x-httpd-php .php .phtml" >> /etc/httpd/httpd.conf
/usr/local/apache2/bin/apachectl restart
</textarea>执行脚本,进行安装(时间很长,可以去睡觉了<img alt="偷笑" src="http://static.blog.csdn.net/xheditor/xheditor_emot/default/titter.gif">)
<p></p>
<p>2、配置mysql</p>
<p><span style="color:#ff0000">cd /usr/local/mysql</span></p>
<p><span style="color:#ff0000">bin/mysqladmin version</span> //简单的测试</p>
<p><span style="color:#ff0000">bin/mysqladmin varibles</span> //查看所有mysql参数</p>
<p><span style="color:#ff0000">bin/mysql -u root</span> //没有密码可以直接登录本机服务器</p>
<div><span style="color:#ff0000">mysql> DELETE FROM mysql.user WHERE Host='localhost' AND User='';</span></div>
<div><span style="color:#ff0000">mysql> FLUSH PRIVILEGES;</span></div>
<div><span style="color:#ff0000">mysql> SET PASSWORD FOR 'root'@'localhost' = PASSWORD('123456');</span><br>
3、安装zend加速器<br>
<span style="color:#ff0000">mkdir /usr/local/php/etc</span><br>
<span style="color:#ff0000">cp php.ini-dist /usr/local/php/etc/php.ini</span> //更改之前设定的php.ini的配置文件位置,安装zend要用<br>
进入Zend包的目录<br>
<span style="color:#ff0000">./install-tty</span><br>
4、phpmyadmin的安装与配置<br>
<span style="color:#ff0000">cd /lamp</span><br>
<div><span style="color:#ff0000">cp -a phpMyAdmin-3.0.0-rc1-all-languages /var/www/html/phpmyadmin</span> //拷贝目录到指定位置(网站主目录/var/www/html下)并改名为phpmyadmin</div>
<div><span style="color:#ff0000">cd /usr/local/apache2/htdocs/phpmyadmin/</span></div>
<div><span style="color:#ff0000">cp config.sample.inc.php config.inc.php</span><br>
进入/var/www/html/phpmyadmin<br>
修改配置文件config.inc.php,将$cfg['blowfish_secret'] = '' 空格处填上登录phpmyadmin的密码,例如:$cfg['blowfish_secret'] = '123456'<br>
<br>
</div>
</div>
<p><span style="font-size:24px">四、常见错误及备注:</span></p>
<p>1、若shell脚本是从windows上传到linux上,而不是直接在linux上写的,可能会出现执行错误。解决办法见我的另一篇日志:<span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6636648" title="shell脚本在Linux下运行错误的解决方法">《shell脚本在Linux下运行错误的解决方法》</a></span></p>
2、对不能联网状态下yum本地安装的方法,见 <span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6636790" title="centos上不能联网状况下yum本地安装软件包">《centos虚拟机不能联网状况下yum方式从本地安装软件包》</a></span>
<p>3、linux启动apache libltdl.so.3:cannot open shared object file:No such file or directory异常</p>
<p>执行<span style="color:#ff0000">ln -s /usr/local/lib/libltdl.so.3 /usr/lib/libltdl.so.3</span> 即可</p>
<p>4、若出现Address already in use: make_sock: could not bind to address [::]:80异常</p>
<p>解决方法:reboot启动linux</p>
<p>5、若出现在linux终端执行clear或者top命令时出现:‘xterm’:unknown terminal type的错误,参考<span class="link_title"><a target="_blank" href="http://blog.csdn.net/guoyin0612/article/details/6638858" title="在linux终端执行clear或top命令时出现:'xterm': unknown terminal type的错误">《在linux终端执行clear或top命令时出现:'xterm':
unknown terminal type的错误》</a></span></p>
<p>6、文中源码包和tar.sh、lamp.sh脚本的下载 <a href="http://u.115.com/file/dn9qqc4x#">点击下载</a> 提取码:<em><span rel="select">dn9qqc4x</span></em><br>
</p>
<p>7、若有其他错误,请百度寻找答案,或者给我发邮件guoyin0612@163.com</p>
<br>
<br>
<p></p>
推荐阅读
-
Linux+php+apache+oracle环境搭建之CentOS下源码编译安装PHP
-
CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)运行环境步骤
-
在CentOS 6.0下搭建LAMP环境(源码安装)
-
在CentOS 6.0下搭建LAMP环境(源码安装)
-
在CentOS上搭建LAMP+vsftpd环境的简单指南
-
详解Lamp环境搭建Linux CentOS6.5编译安装mysql5.6
-
在CentOS上搭建LAMP+vsftpd环境的简单指南
-
在CentOS6.4中安装配置LAMP环境的详细步骤
-
Linux+php+apache+oracle环境搭建之CentOS下源码编译安装PHP
-
CentOS 6.3下源码安装LAMP(Linux+Apache+Mysql+Php)运行环境步骤