apache+mysql+php编译

来源:互联网 发布:开票软件无法打开 编辑:程序博客网 时间:2024/04/30 14:27

 

1.安装Apache 2.2.10

    虽然选择了无包安装CentOS,但是由于包依赖关系,CentOS还是会自动安装Apache,所以需要首先卸载掉Apache,依次点击Applications->Add/Remove Software->把万维网服务器前面的勾去掉即可。

    开始编译安装Apache

    下载httpd-2.2.10

    解压 tar zxvf httpd-2.2.10.tar.gz

    进入目录,开始编译

            ./configure --sysconfdir=/etc --enable-ssl --enable-modules --enable-rewrite

    一般apache还需要支持url改写,所以编译时加上后面的部分;

    正常情况下,如果选择了无包安装CentOS,会出现下面的错误:
        checking whether to enable mod_ssl… checking dependencies
        checking for SSL/TLS toolkit base… none
        checking for OpenSSL version… checking openssl/opensslv.h usability… no
        checking openssl/opensslv.h presence… no
        checking for openssl/opensslv.h… no
        checking openssl/ssl.h usability… noz
        checking openssl/ssl.h presence… no
        checking for openssl/ssl.h… no
        no OpenSSL headers found
        checking for SSL-C version… checking sslc.h usability… no
        checking sslc.h presence… no
        checking for sslc.h… no
        no SSL-C headers found
        configure: error: …No recognized SSL/TLS toolkit detected

    解决办法,安装 openssl

        yum -y install openssl-devel

   对于ubuntu用户安装libssl

       apt-get install libssl-dev

    下载安装和更新的列表信息

        Running Transaction
        Updating : e2fsprogs-libs               ####################### [ 1/15]
        Updating : krb5-libs                    ####################### [ 2/15]
        Installing: e2fsprogs-devel              ####################### [ 3/15]
        Installing: libsepol-devel               ####################### [ 4/15]
        Installing: libselinux-devel             ####################### [ 5/15]
         Installing: keyutils-libs-devel          ####################### [ 6/15]
        Installing: krb5-devel                   ####################### [ 7/15]
        Installing: zlib-devel                   ####################### [ 8/15]
        Installing: openssl-devel                ####################### [ 9/15]
        Updating : krb5-workstation             ####################### [10/15]
        Updating : e2fsprogs                    ####################### [11/15]
        Cleanup   : e2fsprogs-libs               ####################### [12/15]
        Cleanup   : krb5-workstation             ####################### [13/15]
        Cleanup   : e2fsprogs                    ####################### [14/15]
        Cleanup   : krb5-libs                    ####################### [15/15]

        Installed: openssl-devel.i386 0:0.9.8b-8.3.el5_0.2
       Dependency Installed: e2fsprogs-devel.i386 0:1.39-10.el5_1.1keyutils-libs-devel.i386 0:1.2-1.el5 krb5-devel.i386 0:1.6.1-17.el5_1.1   libselinux-devel.i386 0:1.33.4-4.el5 libsepol-devel.i3860:1.15.2-1.el5 zlib-devel.i386 0:1.2.3-3
        Dependency Updated:e2fsprogs.i386 0:1.39-10.el5_1.1 e2fsprogs-libs.i386 0:1.39-10.el5_1.1krb5-libs.i386 0:1.6.1-17.el5_1.1             krb5-workstation.i3860:1.6.1-17.el5_1.1
        Complete!

    OK, openssl安装完毕。

    然后再次输入./configure --sysconfdir=/etc --enable-ssl --enable-modules --enable-rewrite

    这样就生成了makefile

    然后make和make install即可完成Apache安装。

    终端输入:/usr/local/apache2/bin/apachectl start启动apache,

    终端输入:netstat -tnl看看端口,如果有80了,说明apache启动成功了。

    最后需要设置Apache随Redhat启动,终端输入:echo “/usr/local/apache2/bin/apachectl start &” >> /etc/rc.local

或者写一个shell脚本,或者下载一个启动脚本

    cp httpd /etc/init.d/httpd    

    chkconfig /etc/init.d/httpd on

 

如何让Apache能自动运行index

 

    编辑httpd.conf文件,找到DirectoryIndex在后面加一个index.htm等。

    例如,把DirectoryIndex这行改为:

        DirectoryIndex index.html index.htm index.php index.html.var

 

    apache2的配置文件是/etc/httpd.conf和/etc/extra/目录下的文件,需要几个文件一起来配置。在httpd.conf中指向/etc/extra/目录下的配置文件。

 

2.安装MySQL

下载MySQL

解压缩 tar xvf mysql-5.1.32.tgz

./configure --prefix=/usr/local/mysql --sysconfdir=/etc --localstatedir=/var/lib/mysql --enable-local-infile --enable-assembler --with-charset=utf8  --with-big-tables  --with-plugin-partition --with-plugin-federated

make

make install

#prefix=/usr/local/mysql mysql安装的目标目录

#sysconfdir=/etc my.ini配置文件的路径

#localstatedir=/var/lib/mysql 数据库存放的路径

安装完以后要初始化数据库,当然你是升级的话不用做这步;
cp /usr/local/mysql/share/mysql/my-huge.cnf /etc/my.cnf

/usr/local/mysql/bin/mysql_install_db


如果系统没有mysql这个用户的话,最好做以下这步:

useradd -M -o -r -d /var/lib/mysql -s /bin/bash -c "MySQL Server" -u 27 mysql 

然后我启动mysql

/usr/local/mysql/bin/safe_mysqld &

ok,先看看mysql能否正常工作

mysql -uroot mysql

一般情况下都是不能正常链接数据库,错误提示一般为:

ERROR 2002: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) 

其实网上大家问的最多的都是整个问题,说什么链接不到mysqld.sock,其实大家不妨看看mysql的错误日志就明白怎么回事,我这里的错误日志是在

/var/lib/mysql/*.err 你会发现mysql只所以不能启动,是因为/var/lib/mysql的权限不允许mysql服务访问,英文mysql默认是调用mysql用户来启动服务的,好了,既然知道是什么原因找到不能启动,那就简单了。我们只要

chown -R mysql:mysql /var/lib/mysql 就行,如果还是启动不了,再慢慢调试权限,反正一般启动不了都是权限的问题。

如果大家还是不能启动不了的话,那就用我的比较繁琐的权限的设置,反正我每次都是这么做的,一般不会有问题,见下:

chown -R root /usr/local/mysql 
chgrp -R mysql /usr/local/mysql 
chown -R root /usr/local/mysql/bin 
chgrp -R mysql /usr/local/mysql/bin 
chgrp -R mysql /var/lib/mysql 
chmod 777 /var/lib/mysql 
chown -R root /var/lib/mysql/mysql 
chgrp -R mysql /var/lib/mysql/mysql 
chmod 777 /var/lib/mysql/mysql 
chown -R root /var/lib/mysql/mysql/* 
chgrp -R mysql /var/lib/mysql/mysql/* 
chmod 777 /var/lib/mysql/mysql/* 
chmod 777 /usr/local/mysql/lib/mysql/libmysqlclient.a

 

做完上面的步骤,然后把你编译目录的一个脚本COPY过去

cp /usr/local/mysql/share/mysql/mysql.server /etc/rc.d/init.d/mysqld

chkconfig --add mysqld

用ntsysv设置使mysql每次启动都能自动运行。

好了,至此mysql安装完毕,你可以这样起动你的mysql服务

/etc/rc.d/init.d/mysqld start

下面这步比较关键,

ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
ln -s /usr/local/mysql/include/mysql /usr/include/mysql

大家可以不做这步,大可以在编译其他软件的时候自定义myslq的库文件路径,但我还是喜欢把库文件链接到默认的位置,这样你在编译类似PHP,Vpopmail等软件时可以不用指定mysql的库文件地址。
 
ps: 如果是非编译版本的mysql,在启动服务的时候,需要修改 /etc/rc.d/init.d/mysql 将basedir修改到数据库data存放位置即可。

 

3.编译安装GD库,让php支持更多图形方面的内容,例如gif jpg(jpeg) png wbmp xml 和 ttf字体(此部分要在PHP安装前进行,且按照以下顺序进行安装)

◆安装ncurses-5.6

解压缩 tar zxvf ncurses-5.6.tar.gz,进入目录

./configure --prefix=/usr --with-shared --without-debug

make

make install

◆安装zlib2

解压缩 tar  zxvf zlib-1.2.3.tar.gz,进入目录

./configure --prefix=/usr/local/zlib

make

make install

◆安装PNG

解压缩 tar zxvf libpng-1.2.26.tar.gz,进入目录

#cp scripts/makefile.linux ./makefile

./configure --prefix=/usr/local/libpng

make

make install

◆安装ttf ( ttf 是字体的支持 )

tar zxvf freetype-2.3.5.tar.gz
cd freetype-2.3.5
./configure --prefix=/usr/local/freetype

make
make install

◆.安装JPEG6

tar zxvf jpegsrc.v6b.tar.gz
cd jpeg-6b

mkdir -pv /usr/local/libjpeg/{,bin,lib,include,man/man1,man1}

./configure --prefix=/usr/local/libjpeg --enable-shared --enable-static

make
make install

◆安装 libxml2

tar zxvf libxml2-2.6.31.tar.gz
cd libxml2-2.6.31
./configure --prefix=/usr/local/libxml2

make

make install

cp xml2-config /usr/bin

◆安装 libmcrypt-2.5.7.tar.gz

tar zxvf libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7

./configure
make
make install

#如果安装过程提示./libtool找不到该命令 cp /usr/share/libtool/libtool .

◆安装Fontconfig

tar -zxvf fontconfig-2.4.2.tar.gz
cd fontconfig-2.4.2

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

一般这里会出现一个错误提示如下:

checking for LIBXML2… configure: error: Package requirements (libxml-2.0 >= 2.6) were not met:

No package ‘libxml-2.0′ found

Consider adjusting the PKG_CONFIG_PATH environment variable if you
installed software in a non-standard prefix.

Alternatively, you may set the environment variables LIBXML2_CFLAGS
and LIBXML2_LIBS to avoid the need to call pkg-config.
See the pkg-config man page for more details.

解决方法:确定 /usr/local/libxml2/lib/pkgconfig 目录下有 libxml-2.0.pc

export PKG_CONFIG_PATH=/usr/local/libxml2/lib/pkgconfig:$PKG_CONFIG_PATH

如果是64位系统则加上 --with-expat-lib=/usr/lib64

然后再次输入:./configure --prefix=/usr/local/fontconfig --with-freetype-config=/usr/local/freetype/bin/freetype-config  ( --with-expat-lib=/usr/lib64    64位系统加)

make

make install

◆安装GD库

tar zxvf gd-2.0.35.tar.gz
cd gd-2.0.35
./configure --prefix=/usr/local/libgd --with-png=/usr/local/libpng --with-freetype --with-expat-lib=/usr/lib64 (64位系统添加)

如果前面安装都顺利,会看到下面的支持信息:

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
make install

make时遇到可能遇到错误:

Makefile.am:18: The usual way to define `LIBTOOL' is to add `AC_PROG_LIBTOOL'
Makefile.am:18: to `configure.ac' and run `aclocal' and `autoconf' again.

解决方法:安装gettext-devel 后命令行运行 aclocal autoconf 两个命令重新编译
可能需要额外库文件支持一一下载安装,可从安装光盘找到。
 

还可能遇到/usr/lib/libexpat.so: could not read symbols: File in wrong format

解决方法:这是以为是64位系统configure时添加 --with-expat-lib=/usr/lib64)如果还有错误 则替换 64位/usr/lib64/libexpat.so  到 /usr/lib/libexpat.so
注意备份
 mv /usr/lib/libexpat.so /usr/lib/libexpat.so.bak
cp /usr/lib64/libexpat.so /usr/lib/libexpat.so

 

4.安装PHP5.2.10

tar zxvf php-5.2.10.tar.gz

cd php-5.2.10

./configure /
--prefix=/usr/local/php /
--with-apxs2=/usr/local/apache2/bin/apxs /
--with-mysql=/usr/local/mysql /
--with-gd-dir=/usr/local/libgd /
--enable-gd-native-ttf /
--with-ttf /
--enable-gd-jis-conv /
--with-freetype-dir=/usr/local/freetype /
--with-jpeg-dir=/usr/local/libjpeg /
--with-png-dir=/usr/local/libpng /
--with-libxml-dir=/usr/local/libxml2 /
--with-zlib-dir=/usr/local/zlib /
--enable-xml --enable-mbstring --enable-sockets

成功提示信息是:Thank you for using PHP.

 

有些程序包系统已经安装,则不需要再安装一遍,使用

    rpm -ql xxx

来检查是否已经安装了。

    redhat 5 企业版已经安装了gd、png等几个,则执行下面的configure命令:

./configure /
--prefix=/usr/local/php5 /
--with-apxs2=/usr/local/apache2/bin/apxs /
--with-mysql=/usr/local/mysql /
--with-gd --enable-gd-native-ttf /
--with-ttf --enable-gd-jis-conv /
--with-freetype-dir=/usr/local/freetype /
--with-jpeg-dir=/usr/local/libjpeg /
--with-png-dir=/usr/lib /
--with-libxml-dir=/usr/local/libxml2 /
--with-zlib-dir=/usr/local/zlib /
--enable-xml --enable-mbstring /
--enable-sockets --enable-calendar

 

 

    make

    make install

    拷贝一个配置文件当作我们以后的php.ini

        cp php.ini-development /usr/local/php5/lib/php/php.ini

    如果需要用到regist_globals的话,则修改php.ini文件
        register_globals = On

 

    修改 apache 配置文件 httpd.conf 加入对php的支持
        vi /etc/httpd.conf

   

    查找<IfModule mod_mime.c>; 

    在此范围添加 

        AddType application/x-httpd-php .php 
        AddType application/x-httpd-php-source .phps 

 

    然后重启 apache
        /usr/local/apache2/bin/apachectl restart

    站点目录是:/var/www/html

    最后我们还要添加上系统PATH,这样就可以在终端直接输入php即可运行程序,在终端输入:

        vi .bashrc,加入这一行:export PATH=”$PATH:/usr/local/php5/bin”,

    然后注销当前用户重新登录即可,注意,这种方式只对当前用户有效,不是全局设置。

    设置全局路径可以编辑/etc/profile文件,在最后加入

        PATH="$PAHT":/usr/local/php5/bin

    即可。

    链接php库,以便于开发。

        ln -s /usr/local/php5/include /usr/include/php5

 

    然后写个php测试页info.php:内容如下 

    <?php 
        phpinfo(); 
    ?>; 

    正常的话,应该能看到php的信息了.

 

原创粉丝点击