我已经通过 Ubuntu 安装 PHP 版本 5.3.10-1ubuntu3.1 有apt-get
一段时间了。
我现在想安装 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
但我遗漏了一些东西。有什么想法吗?
感谢您的帮助。
答案1
下面是一个示例,您将在其中看到该过程的步骤(看起来您错过了apxs2和阿帕奇加载模块我们的问题中的指令):
#!/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
答案2
您只安装了命令行版本。您没有安装 apache 模块。您需要添加以下内容
--with-apxs2
确保已apache2-dev
安装
答案3
查看你的httpd.conf
文件/目录并仔细查看你的LoadModule
语句。肯定有一个仍指向 php 5.3。