1.编译安装顺序问题:先安装apache,然后再安装php,因为php的编译会用到apache的apxs模块,如果先安装php,再安装apache,则需要重新编译php
2.安装apache
1.确认linux系统中的编译环境,执行如下命令:
[root@localhost /]#rpm -qa |grep gcc #输出gcc环境下的相关包
vi /usr/local/apache/conf/httpd.conf
找到ServerName那一行,去掉前面的注释
7.启动apache
/usr/local/apache/bin/apachectl
查看是否启动
ps aux|grep 'httpd'
8.将apache注册为系统服务并开机启动
有两种方法可以让Apache在系统启动时自动启动。
1. 在/etc/rc.d/rc.local中增加启动apache的命令,例如:/usr/local/httpd/bin/apachectl start
2. 将apache注册为系统服务
首先将apachectl命令拷贝至/etc/rc.d/init.d目录下,改名为httpd
使用编辑器打开httpd文件,并在第一行#!/bin/sh下增加两行文字如下(这是必需的,否则会报httpd不支持chkconfig)
# chkconfig: 35 70 30
# description: Apache
接着注册该服务
chkconfig --add httpd
一切OK了,启动服务
service httpd start
其中所增加的第二行中三个数字第一个表示在运行级别3和5下启动apache,第二、三是关于启动和停止的优先级配置,无关紧要。
附:
编译的httpd不支持chkconfig的解决方法
用chkconfig将自编译设置为系统服务的时候,httpd 服务不支持 chkconfig。
解决过程如下:
1.编辑/etc/init.d/httpd
#!/bin/bash
#chkconfig:345 61 61
#description:Apache httpd
(哈哈,复制粘贴好像有问题,手动输入)
2.配置
[root@localhost ~]# chkconfig --add httpd
[root@localhost ~]# chkconfig --list|grep httpd
httpd 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭
[root@localhost ~]# chkconfig --level 345 httpd on
[root@localhost ~]# chkconfig --list|grep httpd
httpd 0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭
3.编译安装PHP5.3.6
1. 安装编译前提
a. 编译环境
# yum -y install gcc gcc-c++ make
b. php 相关模块
# yum -y install libjpeg-devel libpng-devel freetype-devel libxml2-devel libxslt-devel zlib-devel curl-devel mhash-devel openldap-devel gd-devel
c. libiconv模块安装
# wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz
# cd libiconv-1.13.1
# ./configure --prefix=/usr/local/libiconv && make && make install
d. libmcrypt模块安装
# wget http://downloads.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fmcrypt%2Ffiles%2FLibmcrypt%2F2.5.8%2F&ts=1304912647&use_mirror=nchc
# tar zxvf libmcrypt-2.5.8.tar.gz
# cd libmcrypt-2.5.8
# ./configure && make && make install
# cd libltdl
# ./configure --enable-ltdl-install && make && make install
e. mysql库链接
# ln -s /usr/local/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
2. php编译安装
a. 针对apache的编译安装
# vi /usr/local/httpd/bin/apxs
将第一行的
1 | #!/replace/with/path/to/perl/interpreter -w |
替换为
1 | #!/usr/bin/perl -w |
# ./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-iconv-dir=/usr/local/libiconv --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --with-curl --with-curlwrappers --with-mhash --with-mcrypt --with-gd --enable-gd-native-ttf --with-xsl --with-openssl --with-ldap --with-ldap-sasl --with-xmlrpc --without-pear --enable-zip --enable-soap --enable-mbstring --enable-ftp --enable-sockets --enable-pcntl --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --disable-rpath --enable-mbregex --with-apxs2=/usr/local/httpd/bin/apxs
# make && make install
配置
# vi /usr/local/httpd/conf/httpd.conf
找到
1 | AddType application/x-gzip .gz .tgz |
下行添加
1 | AddType application/x-httpd-php .php |
如果LoadModule php5_module modules/libphp5.so 前有‘#’,去掉注释
找到
1 | <IfModule dir_module> |
2 | DirectoryIndex index.html |
3 | </IfModule> |
修改为
1 | <IfModule dir_module> |
2 | DirectoryIndex index.html index.htm index.php |
3 | </IfModule> |
php 配置文件php.ini问题:
自己编译的php,一般都不会有php.ini,而需要使用cp 命令,将php源代码目录中的php.ini-*文件复制到指定路径下[此路径可以通过phpinfo()的显示信息中看到,php.ini一定需要放在此路径下,否则无效]