1. 首页 > 电脑教程 > 在ubuntu上搭建Lamp环镜

在ubuntu上搭建Lamp环镜

Linux+Apache+Mysql+Perl/PHP/Python一组常用来搭建动态网站或者服务器的开源软件,本身都是各自独立的程序,但是因为常被放在一起使用,拥有了越来越高的兼容度,共同组成了一个强大的Web应用程序平台。随着开源潮流的蓬勃发展,开放源代码的LAMP已经与J2EE和.Net商业软件形成三足鼎立之势,并且该软件开发的项目在软件方面的投资成本较低,因此受到整个IT界的关注。

最流行的PHP框架结构

下载教大家如何在 Ubuntu 上搭建Lamp环镜

一:准备软件包,存放/home/xiutuo/software/目录下。

主要软件包,(这里没有选择mysql-standard-5.0.20-linux-i686.tar.gz,呆会再说明原因。)httpd-2.2.0.tar.gzmysql-max-5.0.21-linux-i686-glibc23.tar.gzphp-5.1.2.tar.gz

安装php所需的软件包(其中libxml2是安装php5必须的,为什么还需要perl呆会说明原因。)libxml2-2.6.19.tar.gzlibxslt-1.1.15.tar.gzActivePerl-5.8.8.817-i686-linux-2.2.17-gcc-257965.rpmcurl-7.15.0.tar.gz

GD库所需要软件包(有人说PHP源码包里自带了GD2.0.28和zlib,只要安装GD的三个支持包:jpg,png和freetype,但是我们还是下载)gd-2.0.33.tar.gzfreetype-2.1.10.tar.gzjpegsrc.v6b.tar.gzlibpng-1.2.8.tar.gzzlib-1.2.3.tar.gz

相关下载(根据自己的linux版本下载相应的包,查看操作系统版本:# uname -r )

http://ftp.gnome.org/pub/GNOME/s … bxml2-2.6.19.tar.gzhttp://ftp.gnome.org/pub/GNOME/s … bxslt-1.1.15.tar.gzhttp://downloads.activestate.com … .638-i686-linux.rpm

http://curl.haxx.se/download/curl-7.15.0.tar.gz

http://www.boutell.com/gd/http/gd-2.0.33.tar.gz

http://keihanna.dl.sourceforge.n … etype-2.1.10.tar.gz

http://www.ijg.org/files/jpegsrc.v6b.tar.gz

http://nchc.dl.sourceforge.net/s … libpng-1.2.8.tar.gz

http://www.zlib.net/zlib-1.2.3.tar.gz

把以上所有软件包下载到:/home/xiutuo/software/目录下。

二:安装apache2。# cd /home/xiutuo/software/进入目录/home/xiutuo/software/# tar -zvxf httpd-2.2.0.tar.gz解压httpd-2.2.0.tar.gz# cd httpd-2.2.0进入httpd-2.2.0目录# mkdir -p /usr/local/apache2生成/usr/local/apache2目录# ./configure –prefix=/usr/local/apache或者# ./configure –prefix=/usr/local/apache –enable-modules=so –enable-rewrite# make; make install安装apache# vi /usr/local/apache/conf/httpd.conf#ServerName www.example.com:80 在其下增加ServerName www.xiutuo.com:80保存退出,现在就这么简单配置apache。

# /usr/local/apache/bin/apachectl -k start启动apahce,用浏览器查看http://www.xiutuo.com,得到it works,说明apache已经配置成功了。# /usr/local/apache/bin/apachectl -k stop停止apache。

三:安装mysql# cd /home/xiutuo/software/# tar -zvxf mysql-max-5.0.21-linux-i686-glibc23.tar.gz# mkdir -p /usr/local/mysql (省略也可)# cp -r mysql-max-5.0.21-linux-i686-glibc23.tar.gz /usr/local/mysql# cp /usr/local/mysql/support-files/my-medium.cnf /etc/my.cnf

添加mysql用户及用户组# groupadd mysql# useradd -g mysql mysql修改mysql目录权限# chown -R root /usr/local/mysql# chgrp -R mysql /usr/local/mysql# chown -R mysql /usr/local/mysql/data生成mysql系统数据库# /usr/local/mysql/scrīpts/mysql_install_db –user=mysql&启动mysql服务# /usr/local/mysql/bin/mysqld_safe –user=mysql&如出现 Starting mysqld daemon with databases from /usr/local/mysql/data代表正常启动mysql服务了, 按Ctrl + C 跳出修改 mysql 的 root 密码# /usr/local/mysql/bin/mysqladmin -u root -p password “123456″

四:安装GD库(让PHP支持GIF,PNG,JPEG)a.安装 jpeg6建立目录:# mkdir -p /usr/local/jpeg6# mkdir -p /usr/local/jpeg6/bin# mkdir -p /usr/local/jpeg6/lib# mkdir -p /usr/local/jpeg6/include# mkdir -p /usr/local/jpeg6/man# mkdir -p /usr/local/jpeg6/man1# mkdir -p /usr/local/jpeg6/man/man1

# cd /home/xiutuo/software/# tar -zvxf jpegsrc.v6b.tar.gz# cd jpeg-6b# ./configure –prefix=/usr/local/jpeg6/ –enable-shared –enable-static# make; make install

b.安装libpng# cd /home/xiutuo/software/# tar -zvxf libpng-1.2.8.tar.gz# cd libpng-1.2.8# cp scrīpts/makefile.std makefile# make; make install

c.安装 freetype# cd /home/xiutuo/software/# tar -zvxf freetype-2.1.10.tar.gz# cd freetype-2.1.10# mkdir -p /usr/local/freetype# ./configure –prefix=/usr/local/freetype# make;make install

d.:安装zlib# cd /home/xiutuo/software/#tar -zxvf zlib-1.2.3.tar.gz#cd zlib.1.2.3# ./configure# make;make install

e.安装GD库# cd /home/xiutuo/software/# tar -zvxf gd-2.0.33.tar.gz# mkdir -p /usr/local/gd2# cd gd-2.0.33# ./configure –prefix=/usr/local/gd2 –with-jpeg=/usr/local/jpeg6/–with-png=/usr/local/lib/–with-zlib=/usr/local/lib/–with-freetype=/usr/local/freetype/# make; make install

e.安装Curl库# cd /home/xiutuo/software/# tar -zxf curl-7.15.0.tar.gz# mkdir -p /usr/local/curl# ./configure –prefix=/usr/local/curl# make; make install

五:安装php5,php5必须有libxml2支持!a.安装libxml2# cd /home/xiutuo/software/# tar -zxf libxml2-2.6.19.tar.gz# cd libxml2-2.6.19# mkdir -p /usr/local/libxml2# ./configure –prefix=/usr/local/libxml2# make; make install

b.安装 libxslt(可选安装,你可以不安装)# cd /home/xiutuo/software/# tar -zxf libxslt-1.1.15.tar.gz# mkdir -p /usr/local/libxslt# cd libxslt-1.1.15# ./configure –prefix=/usr/local/libxslt –with-libxml-prefix=/usr/local/libxml2# make; make install

c.安装php5# cd /home/xiutuo/software/# tar -zvxf php-5.1.2.tar.gz# mkdir -p /usr/local/php# cd php-5.05# ./configure –prefix=/usr/local/php –with-apxs2=/usr/local/apache/bin/apxs –with-mysql=/usr/local/mysql/ –with-curl=/usr/local/curl –enable-ftp –with-libxml-dir=/usr/local/libxml2 –with-expat-dir=/usr/lib –enable-soap –with-xsl=/usr/local/libxslt –enable-xslt -with-gd=/usr/local/gd2/ –with-jpeg-dir=/usr/local/jpeg6/ –with-zlib-dir=/usr/local/lib/ –with-png=/usr/local/lib/ –with-freetype-dir=/usr/local/freetype/+——————————————————————–+| License: || This software is subject to the PHP License, available in this || distribution in the file LICENSE. By continuing this installation || process, you are bound by the terms of this license agreement. || If you do not agree with the terms of this license, you must abort || the installation process at this point. |+——————————————————————–+Thank you for using PHP.

# make# make install# cp php.ini-dist /usr/local/php/lib/php.ini (别忘记了呵呵)

其中./configure 后的–prefix=/usr/local/php–with-apxs2=/usr/local/apache/bin/apxs–with-mysql=/usr/local/mysql/–with-libxml-dir=/usr/local/libxml2是必要的选项

–with-gd=/usr/local/gd2/–with-jpeg-dir=/usr/local/jpeg6/–with-png=/usr/local/lib–with-zlib-dir=/usr/lib–with-freetype-dir=/usr/local/freetype这是让PHP支持GD库的配置选项

–with-curl=/usr/local/curl 支持CURL库–enable-ftp 打开FTP库函数支持

–enable-soap –with-xsl=/usr/local/libxslt –enable-xslt让PHP支持SOAP, 上面这些一般用得少, 可以去掉

六:重新配置apache2让他支持php。

配置 httpd.conf 让apache支持PHP# vi /usr/local/apache/conf/httpd.conf找到 AddType application/x-gzip .gz .tgz 在其下添加如下内容AddType application/x-httpd-php .phpAddType application/x-httpd-php-source .phps

重启apache# /usr/local/apache2/bin/apachectl restart在htdocs目录里建一内容为 <? phpinfo(); ?> PHP文件, 输入URL地址查看PHP配置是否正确

ok,web环境apache2+mysql5+php5就介绍到这里。更详细的apache2的配置和mysql配置和php.ini的配置参考相应文档。——————————————————–安装时候遇到的问题:

由于本人的系统是redhat9,自定义安装了php,mysql,apache。所以在安装最新的php,mysql,apache版本时候,本人对相关的rpm进行了卸载,忽略依赖关系强制卸载apache;由于php,mysql与perl的bt依赖关系,一气之下删除了所有的相关文件。

问题

1.当你看到mysql有很多版本,如:mysql-max-5.0.21-linux-i686-glibc23.tar.gz和mysql-max-5.0.21-linux-i686.tar.gz这俩个到底选哪个呢,请你使用如下命令来决定# rpm -qa | grep glibcglibc-kernheaders-2.4-8.10glibc-common-2.3.2-11.9glibc-2.3.2-11.9glibc-devel-2.3.2-11.9如果出现以上信息,请选择mysql-max-5.0.21-linux-i686-glibc23.tar.gz版本

2:编译php时出现

./configure: /usr/local/apache2/bin/apxs: /replace/with/path/to/perl/interpreter:bad interpreter: No such file or directory这是找不到perl解释器的缘故。修改/usr/local/apache2/bin/apxs文件中:/replace/with/path/to/perl/interpreter把他替换成perl所在的路径如/opt/ActivePerl-5.8/bin/perl,(如果你下载的是active perl5.8的rpm,他默认安装路径是/opt/ActivePerl-5.8/bin/perl)

3.安装了perl后,发现所有的文本编辑器都不能用了。运行vi或者gedit时候,提示找不到libperl.so到perl的安装目录下找一个libperl.so放到/usr/lib目录下就解决问题了我的libperl.so在/opt/ActivePerl-5.8/lib/5.8.8/i686-linux-thread-multi-CORE/目录下。如果不知道libperl.so在什么地方,可以用# locate libperl.so查找,或者用find命令

4.当我使用mysql-standard-5.0.20,编译php时出现mysql错误:

checking for mSQL support… nochecking for MSSQL support via FreeTDS… nochecking for MySQL support… yeschecking for specified location of the MySQL UNIX socket… nochecking for MySQL UNIX socket location… /tmp/mysql.sockchecking for mysql_close in -lmysqlclient… nochecking for mysql_error in -lmysqlclient… noconfigure: error: mysql configure failed. Please check config.log for more information.

网查找说:安装PHP的时候没有指定一下mysql的安装目录。但是我已经指定了,所以这个说法是错误的,其实主要原因是 mysql-level没有装,也就是mysql的版本不对,应该换mysql-max-5.0.21版本(包含所有mysql相关内容的软件包)

5.编译php时出现configure: error: freetype2 not found!没有安装freetype-level

configure: error: libpng.(a|so) not found.没有安装libpng-devel

6忘了mysql的root口令怎么办# /usr/local/mysql/support-files/mysql.server stop# mysqld_safe –skip-grant-tables &# mysqladmin -u user password ‘newpassword’# mysqladmin flush-privileges

声明:希维路由器教程网提供的内容,仅供网友学习交流,如有侵权请与我们联系删除,谢谢。ihuangque@qq.com
本文地址:https://www.ctrlcv.com.cn/diannao/169347960110839.html