[LAMP] Linux+apache2+mysql5+php5+gd install +

来源:互联网 发布:sadp软件使用方法 编辑:程序博客网 时间:2024/04/26 16:32

安装zlib-1.2.3

./configure --enable-shared

make

make install

安装libxml-2.6.3 

./configure --prefix=/usr/local/libxml2 --with-zlib --with-http --enable-shared

make

make install

安装gettext-0.17

 ./configure --prefix=/usr/local/gettext --enable-shared
make
make install

安装png

./configure  --prefix=/usr/local/libpng --enable-shared
make
make install

安装jpeg
 ./configure --prefix=/usr/local/libjpeg --enable-shared
 make
  mkdir -p /usr/local/jpeg/include
  mkdir -p /usr/local/jpeg/lib
  mkdir -p /usr/local/jpeg/bin
  mkdir -p /usr/local/jpeg/man/man1
  make install

安装freetype

./configure --prefix=/usr/local/freetype --enable-shared
 make
make install

 

安装Fontconfig (获取软件http://www.fontconfig.org/release/)

tar -zxvf fontconfig-2.5.91.tar.gz
cd fontconfig-2.5.91

./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config

make
make install

-------------------------------

如果configure的过程中,提示找不到libxml2,尽管已安装 
可以先 
export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH 

./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config

------------------------------


安装gd

tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/libgd --with-png=/usr/local/png --with-freetype=/usr/local/freetype  --with-jpeg=/usr/local/jpeg --with-fontconfig=/usr/local/fontconfig

看到下面的信息,说明 都显示支持了
Support for PNG library:               yes
Support for JPEG library:             yes
Support for Freetype 2.x library:  yes
Support for Fontconfig library:    yes
Support for Xpm library:              no 
Support for pthreads:                  yes

make


编译gd-2.0.35.tar.gz时报错:

gd_png.c:16:53: error: png.h: No such file or directory
gd_png.c:47: error: expected specifier-qualifier-list before ‘jmp_buf’
gd_png.c:54: error: expected ‘)’ before ‘png_ptr’
gd_png.c:82: error: expected ‘)’ before ‘png_ptr’
gd_png.c:92: error: expected ‘)’ before ‘png_ptr’



解决办法:
修改Makefile:

     DEFAULT_INCLUDES = -I. -I$(srcdir) -I. -I /usr/local/libpng/include/

再make就OK了


make install

=========================================================================

apache2.2.9+mysql5+php5在centos-5.2上的安装:

如果已经安装上apache的RPM包的话可以用 如下命令卸载:

    rpm -e *mysql* --nodeps

apache+mysql+php
解压缩mysql安装包,进入mysql文件夹。

mysql5.2.6


./configure --prefix=/usr/local/mysql  --localstatedir=/var/lib/mysql   --with-comment=Source  --with-server-suffix=-Community   --with-mysqld-user=mysql  --without-debug   --with-big-tables   --with-charset=latin1  --with-collation=latin1_swedish_ci   --with-extra-charsets=all  --with-pthread   --enable-static   --enable-thread-safe-client  --with-client-ldflags=-all-static   --with-mysqld-ldflags=-all-static  --enable-assembler   --without-innodb   --without-ndb-debug

make
make install

--------------------

如果configure过程出现如下error:

checking for tgetent in -ltermcap… no
checking for termcap functions library… configure: error: No curses/termcap library found


说明 curses/termcap 库没有安装
去下载一个ncurses-5.2.tar.gz,

wget http://ftp.gnu.org/pub/gnu/ncurses/ncurses-5.2.tar.gz
tar zxvf   ncurses-5.2.tar.gz
cd ncurses-5.2
./configure --prefix=/usr/local --with-shared --without-debug
make
make install 

-------------------


# useradd mysql //添加 mysql 用户
# cd /usr/local/mysql
# bin/mysql_install_db --user=mysql
# chown -R root:mysql . //设置权限,注意后面有一个 "."
# chown -R mysql /var/lib/mysql //设置 mysql 目录权限
# chgrp -R mysql . //注意后面有一个 "."
# cp share/mysql/my-huge.cnf /etc/my.cnf
初始化表
# /usr/local/mysql/bin/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服务了

二、安装apache2

解压缩apache安装包,进入apache文件夹。

安装:

apache2.2.9
  ./configure --prefix=/usr/local/apache2  --enable-http  --enable-modules=all  --enable-rewrite  --enable-so  --enable-cgi  --enable-cgid  --enable-deflate=shared  --enable-cache  --enable-file-cache

make
make install

注解:
./configure //配置源代码树
--prefix=/usr/local/apache2 //体系无关文件的顶级安装目录PREFIX ,也就Apache的安装目录。
--enable-module=so //打开 so 模块,so 模块是用来提 DSO 支持的 apache 核心模块
--enable-deflate=shared //支持网页压缩
--enable-expires=shared //支持 HTTP 控制
--enable-rewrite=shared //支持 URL 重写
--enable-cache   //支持缓存
--enable-file-cache   //支持文件缓存
--enable-mem-cache   //支持记忆缓存
--enable-disk-cache   //支持磁盘缓存
--enable-static-support //支持静态连接(默认为动态连接)
--enable-static-htpasswd //使用静态连接编译 htpasswd - 管理用于基本认证的用户文件
--enable-static-htdigest //使用静态连接编译 htdigest - 管理用于摘要认证的用户文件
--enable-static-rotatelogs //使用静态连接编译 rotatelogs - 滚动 Apache 日志的管道日志程序
--enable-static-logresolve //使用静态连接编译 logresolve - 解析 Apache 日志中的IP地址为主机名
--enable-static-htdbm //使用静态连接编译 htdbm - 操作 DBM 密码数据库
--enable-static-ab //使用静态连接编译 ab - Apache HTTP 服务器性能测试工具
--enable-static-checkgid //使用静态连接编译 checkgid
--disable-cgid //禁止用一个外部 CGI 守护进程执行CGI脚本
--disable-cgi //禁止编译 CGI 版本的 PHP
--disable-userdir //禁止用户从自己的主目录中提供页面
--with-mpm=worker // 让apache以worker方式运行
--enable-authn-dbm=shared // 对动态数据库进行操作。Rewrite时需要。

三、安装php5

解压缩php安装包,进入php文件夹。

安装:

./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-zlib-dir --with-libxml-dir=/usr/local/libxml2/  --with-gd=/usr/local/libgd --with-freetype-dir=/usr/local/freetype/  --with-jpeg-dir=/usr/local/jpeg/  --with-png-dir=/usr/local/libpng/  --enable-mbstring  --with-mysql=/usr/local/mysql/  --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-gd-native-ttf   --with-gettext=/usr/local/gettext/   --enable-magic-quotes--enable-sockets

make

make install

make clean

cp php.ini-dist /usr/local/php/lib/php.ini

四、收尾工作

vi /usr/local/apache2/conf/httpd.conf

使apache支持php,增加

LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php

修改DirectoryIndex index.html index.php

 

找到这一段:
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride none

更改为AllowOverride all
允许apache rewrite

重启apache:/usr/local/apache2/bin/httpd -k restart


===============================================================

【修改DocumentRoot 之后, 访问首页出现 Forbidden】

【解决方法】

1 关闭 防火强 和  SElinux 进程 ,需要重启服务器
 
用vim打开 /etc/selinux/config

在 SELINUX=enforcing 前面加个#号注释掉它
#SELINUX=enforcing

然后新加一行
SELINUX=disabled


保存,退出,重启系统。


2、问题的原因不在于SElinux,而是因为httpd.conf中有


<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all    --> 修改为Allow from all 后解决
</Directory>

将Deny from all  修改为Allow from all ,就可以访问到我虚拟主机设置文件中的其他目录了!如可访问/var/www,附虚拟主机文件 httpd-vhosts.conf

<VirtualHost *:80>
  DocumentRoot /var/www
  ServerName
  DirectoryIndex index.html index.php index.htm
</VirtualHost>

问题2:在主文件httpd.conf中修改为Allow from all 后,apache的默认根目录及/var/www目录的安全性又如何?


3、或者不改变主文件httpd.conf,在虚拟主机文件 httpd-vhosts.conf中,按如下设置也可以访问到该虚拟主机目录


<Directory /var/www>               
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

<VirtualHost *:80>
  DocumentRoot /var/www
  ServerName
  DirectoryIndex index.html index.php index.htm
</VirtualHost>

4.是seLinux对访问目录的权限设置捣的鬼!

修改Selinux对 DocumentRoot 的访问控制
用以下命令修改文件夹安全属性
chcon -R -t httpd_user_content_t public_html/  


mysql在进入mysql工具时,总是有错误提示:
# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

或者
# mysql -u root -p password 'newpassword'
Enter password:
mysqladmin: connect to server at 'localhost' failed
error: 'Access denied for user 'root'@'localhost' (using password: YES)' 

方法操作很简单,如下:
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root' and host='root' or host='localhost';//把空的用户密码都修改成非空的密码就行了。
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysqld restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword> 


能ping通但是apache无法访问

具体情况如下
1.本机能ping通虚拟机
2.虚拟机也能ping通本机
3.虚拟机能访问自己的web
4.本机无法访问虚拟己的web



是防火墙将80端口屏蔽了的缘故。

检查是不是服务器的80端口被防火墙堵了,可以通过命令:telnet server_ip 80 来测试。

/etc/init.d/iptables status

会得到一系列信息,说明防火墙开着。

/etc/init.d/iptables stop

解决方法如下:

# iptables  -A INPUT -p tcp -m tcp --sport 80 -j ACCEPT
# iptables  -A OUTPUT -p tcp -m tcp --dport 80 -j ACCEPT 


然后保存:/etc/rc.d/init.d/iptables save


重启防火墙:/etc/init.d/iptables restart


CentOS防火墙的关闭,关闭其服务即可:

查看CentOS防火墙信息:/etc/init.d/iptables status
关闭CentOS防火墙服务:/etc/init.d/iptables stop


永久关闭防火墙:chkconfig –level 35 iptables off

====================  PHP  扩  展  属  性  添  加  ===================

PHP扩展(extension 简写EXT)的编译分为两种:单独编译和内核编译.单独编译php的扩展给php配置的灵活性带来了非常大的提高,比如你可以将大多数常年不需要更新的扩展编译到php内核(像gd、openssl之类),而将其他一些更新频率相对高一点的扩展(像mysql),在需要进行更新的时候,只需要重新编译扩展,而不用重新编译整个php。理论上,扩展编译到php内核会带来稍微的性能提升,具体情况还是得各人自己取舍了。


php的安装目录:/usr/local/php/

然后进入需要安装的模块的目录

使用php的phpize工具, /usr/local/php/bin/phpize

然后使用
# ./configure --with-php-config=/var/php/bin/php-config

注: for xcache, with parameter -enable-xcache  and  Foreacceleratorwith parameter -enable-eaccelerator


# make
# make install

Installing shared extensions:     /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/

xcache安装到了/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/

修改php.ini以加载扩展  分两种情况:

1.对于xcache、eaccelerator之类的opcache扩展,一般都以zend_extension方式加载,

2.其他的都以普通extension方式加载,常见的有memcache curl soap zip ftp等, 

二者不同之处在于,前者在加载的时候需要指定扩展的so文件的绝对路径,后者先要配置php.ini里面的extension_dir(一般也就是刚才make install后输出的那个目录),然后只输入so文件的文件名即可。

然后需要你到php.ini中把extension扩展打开

extension = XXX.so

同时要注意extension_dir这个目录要有你安装好的XXX.so

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

下面来罗列下我们常用的模块的安装

1.memcache

cd memcache-2.5.5

/usr/local/php5/bin/phpize

./configure --with-php-config=/usr/local/php5/bin/php-config --enable-memcache

make

make install

编译出来的memcache.so保存在 /usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/ 目录下

接着要做的工作就是让php加载这个扩展,编辑你的php.ini,在适当位置(通常是最后,也可以是独立的一个ini文件)加入如下行:

extension=memcache.so

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

2.eaccelerator

1、 PHP加速器 eaccelerator 简介;

eaccelerator是一个自由开放源码php加速器,优化和动态内容缓存,提高了性能php脚本的缓存性能,使得PHP脚本在编译的状态下,对服务器的开销几乎完全消除。它还有对脚本起优化作用,以加快其执行效率。使您的PHP程序代码执效率能提高1-10倍;

官方主页: http://eaccelerator.net

2、 安装和配置;

首先您要安装好PHP,然后再来编译安装 eaccelerator,过程如下

2.1 编译安装;

# tar xvf eaccelerator-0.9.5.2.tar.bz2
# cd cd eaccelerator-0.9.5.2
# /usr/local/php/bin/phpize
# ./configure --with-php-config=/usr/local/php/bin/php-config --enable-eaccelerator=shared
# make
# make install

# ldconfig
注:更新动态链接库地址;

zend_extension="/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/eaccelerator.so" 注:模块的具体位置;
eaccelerator.shm_size="16" 注:共享内存大小;
eaccelerator.cache_dir="/dev/shm" 注:缓存目录;
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

ZIP扩展
进入安装原php的源码目录,
cd ext
cd zip
phpize
./configure
make
就会在PHPDIR/ext/zip/modules/下生成zip.so的文件。

复制zip.so文件到extensions的配置目录,修改php.ini就好了

SOAP扩展
进入安装原php的源码目录,
cd ext
cd soap
phpize
./configure
make
就会在PHPDIR/ext/soap/modules/下生成soap.so的文件。

复制soap.so文件到extensions的配置目录,修改php.ini就好了

===============================================================================================================

xml/libxml/zlib/gd/png/freetype/jpeg/

在编译gd的时候png报错:
gd_png.c:791: syntax error before "for"
gd_png.c:793: warning: parameter names (without types) in function declaration
gd_png.c:793: warning: data definition has no type or storage class
gd_png.c:794: syntax error before '}' token
gd_png.c:798: warning: parameter names (without types) in function declaration
gd_png.c:798: warning: data definition has no type or storage class
gd_png.c:799: syntax error before '}' token
gd_png.c:802: syntax error before '&' token
gd_png.c:802: warning: data definition has no type or storage class
gd_png.c:404: storage size of `open' isn't known
[color=Red]make[2]: *** [gd_png.lo] Error 1
make[2]: Leaving directory `/tmp/gd-2.0.26gif'
make[1]: *** [all-recursive] Error 1
make[1]: Leaving directory `/tmp/gd-2.0.26gif'
make: *** [all] Error 2
[root@RHEL3 gd-2.0.26gif]# [/color]

解決方法为:
vi gd_png.c
找到「png.h」改成「/usr/local/libpng2/include/png.h」)

 

*******************************************************************************************************************

在交叉编译的jpeg时候如果出现以下的错误信息:

./libtool --mode=compile arm_920t_le-gcc -O2  -I. -c ./jcapimin.c
make: ./libtool: Command not found

解决方法:

#wget:http://ftp.gnu.org/gnu/libtool/libtool-2.2.6a.tar.gz
#./configure
#make
#make install

#cd jpeg

#cp /usr/share/libtool/config.sub .
#cp /usr/share/libtool/config.guess .

参考地址:http://www.trylife.cn/error-jpeg/

在编译php的时候会有:

CC=/usr/local/920t_le/bin/arm_920t_le-gcc./configure --prefix=/usr/local/php/test --host=arm-linux--with-zlib-dir   --with-libxml-dir=/usr/local/libxml/ --with-gd=/usr/local/php/ --with-freetype-dir=/usr/local/php/--with-jpeg-dir=/usr/local/php/ --with-png-dir=/usr/local/php/--enable-mbstring --with-gettext=/usr/local/php/ --enable-sockets



Configuring extensions

checking whether to enable LIBXML support... yes

checking libxml2 install dir... /usr/local/libxml/

checking for xml2-config path... /usr/local/libxml//bin/xml2-config

checking whether libxml build works...

checking for OpenSSL support... no

checking for Kerberos support... no

checking for PCRE support... yes

checking for ZLIB support... no

checking if the location of ZLIB install directory is defined... yes

checking for gzgets in -lz... no

configure: error: ZLIB extension requires zlib >= 1.0.9

 

cat config.log

/usr/local/libxml/lib conftest.c -lz  -lm  -lxml2 -lz -lm 1>&5

/usr/local/920t_le/bin/../lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld:          skipping incompatible /usr/local/php/lib//libxml2.so whensearching for -lxml2

/usr/local/920t_le/bin/../lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld:          skipping incompatible /usr/local/php/lib//libxml2.a whensearching for -lxml2

/usr/local/920t_le/bin/../lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld:          skipping incompatible /usr/local/libxml/lib/libxml2.so whensearching for -lxml2

/usr/local/920t_le/bin/../lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld:          skipping incompatible /usr/local/libxml/lib/libxml2.a whensearching for -lxml2

/usr/local/920t_le/bin/../lib/gcc/arm-linux/3.4.4/../../../../arm-linux/bin/ld:           cannot find -lxml2

collect2: ld returned 1 exit status

configure: failed program was:

#line 23196 "configure"

#include "confdefs.h"

/* Override any gcc2 internal prototype to avoid an error.  */

/* We use char because int might match the return type of a gcc2

    builtin and then its argument prototype would still apply.  */

char gzgets();

 

int main() {

gzgets()

; return 0; }


解决办法:重新安装一遍libxml,安装的时候,在指定C编译器的同时,export PATH 交叉编译的编译器路径
类似 :exportPATH="/usr/local/920t_le/armlinux/bin/:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/local/920t_le/bin"
然后在configure


问题:httpd: Syntax error on line 53 of/usr/local/apache/conf/httpd.conf: Cannot load/usr/local/apache/modules/libphp5.so into server:/usr/local/apache/modules/libphp5.so: cannot restore segment prot afterreloc: Permission denied

解决办法:
原因是Linux有一个SELinux保护模式引起的。
1.关闭SELINUX的方法:
vi /etc linux/config 将SELINUX=enforcing 改成SELINUX=disabled 需要重启

2.不关闭SELINUX的方法:

# setenforce 0

# chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so

# service httpd restart

# setenforce 1

 

或者

 

手工编译安装php后,如果一切顺利解决了的话,重启apache时,libphp5.so: cannot restore segment prot after reloc: Permission denied 错误:如果你是开着seliunx 的话,运行下面的命令:chcon -t texrel_shlib_t /usr/local/apache/modules/libphp5.so<具体chcon 的命令的意思,可以自己man一下,它是selinux有关的命令,更改文件的标签。ls命令在命令后加个 -Z 或者加 –context 查看标签>如果 没有开selinux 的话,找到libphp5.so,然后chmod 777 libphp5.so源自:http://www.phpfreaks.com/forums/index.php?topic=133131.0;wap2

Cannot load /www/modules/libphp5.so into server error

(1/1)

bigb89: Hi, I am trying toinstall PHP and configure it to work with Apache. So far I have Apache2 and MySQL 5 working just fine, but after intalling PHP I tried torestart Apache and I get the following error: Cannot load/www/modules/libphp5.so into server: /www/modules/libphp5.so: cannotrestore segment prot after reloc: Permission denied. What's causingthis error is the following line on my httpd.conf file: LoadModulephp5_module        modules/libphp5.so. Could anyone explain to mewhat's causing this error and how can I fix it?Thanks in advance!

rlee923: Hi,I assume you are using one of those linux with Selinux enabled.The problem is caused by the security system - selinux, blocking it's access to libph5.so.chcon -t texrel_shlib_t /usr/local/apache/modules/libphp5.soThis is the magic line of the code, change the path so it points to the directory where you've installed apache2 if necessary.