33、lamp安装

来源:互联网 发布:php文件管理插件 简洁 编辑:程序博客网 时间:2024/04/27 02:30

前言

因为服务器上跑的程序需要更好的稳定性,所以应该使用源码包的安装方式去安装apache、php和mysql,软件包下载地址 百度网盘下载

安装前的准备

需要准备的二进制包列表如下

包名 作用 freetype-2.4.1.tar.gz gd-2.0.35.tar.gz httpd-2.2.19.tar.bz2 apache程序 jpegsrc.v8b.tar.gz libpng-1.4.3.tar.gz libxml2-2.7.2.tar.gz mcrypt-2.6.8.tar.gz mysql-5.1.58.tar.gz mysql安装包 php-5.3.6.tar.bz2 php安装包 zlib-1.2.5.tar.gz gzip压缩函数库

开始安装

安装zlib类库

用普通安装源码包的方式安装即可,作用是用来压缩数据

安装apache

安装apache需要注意的地方有一点,那就是安装前的配置检查

./configure --prefix=/usr/local/http2 \--enable-modules=all \ --enable-mods-shared=all \ --with-apxs2=/path/to/apxs \--enable-so

--enable-modules=all的意思是
--anable-mods-shared=all是把所有模块都编译器apache里
--enable-so的意思是让apache更好的支持so模块

然后执行make && make install进行安装。
安装完成后 /usr/local/http2/bin/apachectl start,启动apache服务。

设置80端口开启

iptables -I INPUT -p tcp --dport 80 -j ACCEPT 开放80端口/etc/rc.d/init.d/iptables save  保存防火墙设置/etc/rc.d/init.d/iptables restart 重启防火墙

rpm包安装apache异常处理

如果出现下面的异常现象:

正在启动 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using 120.192.83.162 for ServerName

解决方案是,修改/etc/hosts下的文件,在 127.0.0.1::1项后面都把电脑的主机名加进去,如下所示

[root@du ~]# vi /etc/hosts127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4 du::1         localhost localhost.localdomain localhost6 localhost6.localdomain6 du

设置一个虚拟主机

/usr/local/http2/conf/httpd.conf apache主配置文件地址;开启虚拟主机辅助配置
/usr/local/http2/conf/extra/httpd-vhosts.conf 虚拟主机配置文件。然后在虚拟主机配置文件里进行配置,配置方式和windows下的一样!apache的详细使用在工具篇详细介绍

设置虚拟主机后,可能打开是默认403 禁止访问,有三个地方需要考虑:
1. http.conf中的Directory Order deny,allow这个地方;
2. 第就是web的根目录以及上上级目录都需要Apache用户可以执行,也就是给需要访问的站点目录以及上级到根目录的目录都加x权限,chmod +x 目录
3. selinux的问题
1. 关掉SELinux,并重启系统让其生效。
修改/etc/selinux/config配置文件,设置SELINUX=disabled
如果不想重启系统,使用命令:setenforce 0
(也可在grub.conf修改kernel启动参数,添加selinux=0。当然需要重启系统)
2. 或者,修改SELinux的设置,让apache进程可以访问了我的目录。
命令为:chcon -R -t httpd_sys_content_t /root/websitechcon -t var_t /root/website
当我们把SELinux的权限问题解决后,重启了Apache,就一切正常了!。
我们在局域网中使用,网络环境相对安全,所以实际测试过程中一般都disable SELinux的。当然,为了安全也是可以开启的。

安装php

安装依赖libxml2

解压后进入libxml文件夹后,直接执行命令 ./configure --prefix=/usr/local/libxml2 && make && make install一步到位。

安装依赖jpeg8

解压后进入jpen-8b文件夹后,直接执行命令 ./configure --prefix=/usr/local/jpeg --enable-shared --enable-static && make && make install一步到位。

安装依赖libpng

解压后进入libpng文件夹后,直接执行命令 ./configure && make && make install一步到位。* (不需要指定安装目录)*

安装freetype

./configure --prefix=/usr/local/freetype && make && make install.

安装GD库

./configure --prefix=/usr/local/freetype && make && make install.

安装php主程序
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/http2/bin/apxs --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-freetype-dir=/usr/local/freetype --with-gd=/usr/local/gd --with-zlib --with-libxml-dir=/usr/local/libxml2 --with-jpeg-dir=/usr/local/jpeg --with-png-dir --enable-mbstring=all --enable-shared

如果出现以下异常:

Sorry, I cannot run apxs.  Possible reasons follow:1. Perl is not installed2. apxs was not found. Try to pass the path using –with-apxs2=/path/to/apxs3. Apache was not built using –enable-so (the apxs usage page is displayed)The output of /usr/local/apache/bin/apxs follows:./configure: /usr/local/apache/bin/apxs: not foundconfigure: error: Aborting

那么表明,在apache的bin目录下的apxs文件的设置项有误,需要把第一行的#!/replace/with/path/to/perl/interpreter -w,中/replace/with/path/to/perl/interpreter替换成本机perl的安装位置,如果不清楚,可以用which perl找到,一般在/usr/bin/perl ,将第一行改为:#!/usr/bin/perl -w. 再运行php的configure, 一切正常!

如果出现以下异常:

checking whether libxml build works... noconfigure: error: build test failed.  Please check the config.log for details.

这个好像是因为libxml2的库版本太低,或者是其他的原因,反正上面源码包安装的库反正是不能用了,于是我从/usr/local/libxml2删除,卸载掉了自己安装的,然后使用yum install -y libxml2命令重装了该库,使用yum方式默认安装的位置在/usr/lib64路径下,这个路径可能因机器有所不同,然后把./configure 参数中的--with-libxml-dir=/usr/local/libxml2 改成了 --with-libxml-dir=/usr/lib64

为了防止意外,我把网上提供的解决方案也一并操作了一下,安装了 yum install -y libxml2-devl.

则表明libxml2-devel没有安装,在此不演示二进制包和源码包的安装方式,直接使用yum install -y libxml2-develyum list | grep 关键字是搜索可安装的相关的关键字的哦!

再次./configure,检查顺利通过!万事大吉,继续走make && make install

安装完成后,拷贝php配置文件,cp php.ini-development /usr/local/php/lib/php.ini
完成后,apache的主配置文件会添加一句话105 LoadModule php5_module modules/libphp5.so。重启apache服务器,如果出现类似...cannot load /usr/local/http2/modules/libphp5.so...这样的提示,需要执行echo "/usr/local/lib" >> /etc/ld.so.confldconfig这两条命令使函数库生效。

这时候再次重启(如果没有上述错误,可以省略),php文件可以访问,但是这时如果php文件不能正常访问,比如把php代码原样打印,那么需要执行将AddType application/x-httpd-php .php这句代码加入apache主配置文件实现让php模块来解释php后缀的文件。

到了这一步大致就好了,但是还差一点,date会报如下异常:

dateWarning: phpinfo() [function.phpinfo]: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Asia/Chongqing' for 'CST/8.0/no DST' instead in /home/dab1993/web/index.php on line 2

这个异常是代表时区设置异常,好吧 配置一下时区!
vi /usr/local/php/lib/php.ini修改date.timezone = PRC,重启apache,即可正常执行php程序!

安装mysql

mysql依赖libtermcap,所以需要先安装,从yum中选择一个

[root@zuopu749 lib]# yum list | grep termcapcompat-libtermcap.i686                   2.0.8-49.el6                   basecompat-libtermcap.x86_64                 2.0.8-49.el6                   base[root@zuopu749 lib]# yum install -y compat-libtermcap

检查配置

./configure --prefix=/usr/local/mysql \            --with-charset=utf8 \            --with-extra-charsets=gbk,gb2312,binary

唔,虽然一开始就安装了 compat-libtermcap,但还是报了那个异常,看来安装的包不对貌似,度娘一下,再安装一个包yum list|grep ncurses,
yum -y install ncurses-devel,这下再次./configure,检测通过,开始安装!

检测虽然过了,但是编译的时候还是出现了异常

../depcomp: line 571: exec: g++: not foundmake[1]: *** [my_new.o] 错误 127make[1]: Leaving directory `/root/mysql-5.1.58/mysys'

原来是c++的编译器没有安装,yum install -y gcc-c++,安装完后继续尝试。重新make前,记得先make clean一下,把之前编译的文件先删掉。

又报错了../include/my_global.h:1088: 错误:对 C++ 内建类型 ‘bool’ 的重声明,网上说还得重新./configure一下,看来只是make clean还不行啊,这样一来顺序就应该是,yum install -y gcc-c++->./configure ...->make clean -> make -> make install。如果最后还是不行,可以重新删掉文件夹,解压重来!

继续执行编译 make命令,但是可能是vps配置过低,编译一直卡在make[4]: Entering directory /...mysql-test/。网上虽说这一段卡是因为这是正常的,只要正常等待就好了,但是我等待了两个小时了都没好,决定放弃! 不过虽然卡了,但是度娘说,实际上mysql已经可以使用了。不过看不到成功的提示,心里终究是不舒服的,于是改用yum命令安装mysql :
mysql服务:yum install -y mysql-server mysql-devel
mysql客户端:yum install -y mysql

记得更改my.ini中的默认编码格式为utf8。

安装完成后,执行mysql命令,初始化mysql数据库。然后将mysql服务放入开机自启chkconfig --add mysqld。然后chkconfig --level 3 mysqld on指定在第三种运行模式下开启mysql。开放mysql3306端口,就可以正常远程访问mysql了,其余的问题就是mysql内部的配置问题了。至此 lamp 架设完毕!

后续设置

除了mysql需要开机自启之外,apache也需要开机自启,apache有两种开机启动的方式。
1. 在/etc/rc.d/rc.local文件中增加一条命令 /usr/local/http2/bin/apachectl start
2. 推荐的方式:把apache添加为服务,在/etc/rc.d路径下新建一个httpd文件:文件内容如下:

#!/bin/sh#chkconfig: 2345 80 05#description: httpdcase $1 instart)        /usr/local/http2/bin/apachectl start #将该行替换成你自己的服务启动命令        ;;stop)        /usr/local/http2/bin/apachectl stop        ;;restart)        /usr/local/http2/bin/apachectl restart         ;;*)        ;;esac

上述chkconfig的选项是说明,在2345启动级别中启动它,80是启动优先级,05是关闭的优先级!服务名则是httpd,然后chkconfig --add mysqld就可以实现开机启动了。对了,不要忘了给httpd文件加x权限chmod +x httpd。(当然,把源码包的启动路径直接软连接到/etc/init.d/也是可以的!)

0 0
原创粉丝点击