编译PHP5.4 for Apache(PHP5.3已经安装了apt-get)

我已经通过Ubuntu的apt-get安装了PHP 5.3.10-1ubuntu3.1一段时间了。

我现在想安装PHP5.4,我打算从源代码编译。 我解压到/usr/src/php-5.4.3/并运行:

./configure --with-mysqli --with-pcre-regex --with-pdo-mysql --with-pear --with-curl --with-gd --with-openssl; make; make install

以及apt-get install其他所需的库以使其工作。

现在php -v是5.4,正如预期的那样,但是当我通过Apache使用PHP时,它仍然指向5.3。 我甚至做了apt-get remove --purge php5-dev但我错过了一些东西。 任何想法是什么?

谢谢你的帮助。

这里是一个例子,你会看到这个过程的步骤(看起来你缺lessapxs2和我们的问题中的Apache LoadModule指令):

 #!/bin/sh # #################################################### # PHP INSTALLATION SHELL for compiled version # By Hornetbzz - 17/09/2010 # localhost stands for the machine to be installed # remote host stands for the machine to be duplicated # chmod 700 and run as root # #################################################### # ######################## # USER CONTROL # ######################## [[ $(whoami) != "root" ]] && echo "pls run as root" && exit # ######################## # SOURCE DIR # ######################## SRC=/usr/local/src # ######################## # latest php tarball # check the most recent mtime tarball in the source directory (already downloaded) # ######################## LOCAL_SRC_INSTALLED=$(ls -t *tar.gz $SRC | head -1) echo "latest php tarball: $LOCAL_SRC_INSTALLED" [[ ! -z $LOCAL_SRC_INSTALLED ]] && LOCAL_SRC_INSTALLED=$SRC/$LOCAL_SRC_INSTALLED echo "latest php tarball (full path): $LOCAL_SRC_INSTALLED" # get source files from mirror if no tarball already existing in the src directory if [ -z $LOCAL_SRC_INSTALLED ];then echo "No php tarball found => it will be downloaded from mirror" && exit MIRROR="fr.php.net" VERSION="5.3.3" cd $SRC wget http://$MIRROR/get/php-$VERSION.tar.gz/from/this/mirror # tarball checksum : not done mv mirror "php-$VERSION.tar.gz" # get the last accessed tarball file LOCAL_SRC_INSTALLED=$SRC/"php-$VERSION.tar.gz" fi # name with full path echo "checkpoint: $LOCAL_SRC_INSTALLED" # ######################## # PROCEED to installation # ######################## if [ -f $LOCAL_SRC_INSTALLED ];then echo "Local PHP sources : $LOCAL_SRC_INSTALLED" # change directory - keep this even if already done - cd $SRC # untar tar xzf $LOCAL_SRC_INSTALLED # get the new dir name created on the localhost after untar echo "basename: " && echo $(basename $LOCAL_SRC_INSTALLED) NEW_DIR_NAME=$(basename $LOCAL_SRC_INSTALLED | sed -e "s/\.tar\.gz$//") echo "Info: New src directory created: $NEW_DIR_NAME" # change directory cd /usr/local/src/$NEW_DIR_NAME [[ -f "config.nice ]] && cp config.nice config.nice.original # NOTA: copying this shell, you may have to escape each included quote by a backslash, like this \" echo -e " # build: import remote host config.nice into the localhost installation shell # Created by configure './configure' \ '--prefix=/usr/local/php' \ '--with-apxs2=/usr/bin/apxs2' \ '--enable-embed' \ '--with-config-file-path=/usr/local/php/php.ini' \ '--with-config-file-scan-dir=/usr/local' \ '--with-gd=shared' \ # NOTA: remove "=shared" if you install a bundled lib as explained in my wiki page all other options there '--enable-mbstring' \ "$@" " > config.nice make clean ./config.nice make make install echo -e "LoadModule php5_module /usr/local/php/lib/libphp5.so \n AddType application/x-httpd-php .php \n PHPIniDir "/usr/local/php \n" >> /etc/apache2/httpd.conf /etc.init.d/apache2 stop /etc.init.d/apache2 start /etc.init.d/apache2 reload else echo "PHP source : local tarball not found in $SRC" fi 

你只安装了命令行版本..你没有安装apache模块。 您需要添加以下内容

 --with-apxs2 

确保你已经apache2-dev

看看你的httpd.conf文件/目录,并仔细看看你的LoadModule语句。 必然会有一个仍然指向PHP 5.3。