Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have had PHP Version 5.3.10-1ubuntu3.1 installed through Ubuntu's apt-get for some time.

I now want to install PHP5.4, which I was planning on compiling from source. I have extracted into /usr/src/php-5.4.3/ and run:

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

aswell as apt-get installing other required libs to make that work.

Now php -v is 5.4, as expected, but when I use PHP through Apache it still points to 5.3 somehow. I've even done apt-get remove --purge php5-dev but I'm missing something. Any ideas what?

Thanks for your help.

share|improve this question
    
I guess you're mixing the cli with the dso module. You may include the complied php as an Apache DSO Module, adding the LoadModule directive in your apache conf file (eg httpd.conf) –  hornetbzz May 8 '12 at 23:27
    
@hornetbzz I have LoadModule php5_module /usr/lib/apache2/modules/libphp5.so in /etc/apache2/mods-enabled/php5.load, but I wouldn't know what to change to make this work. I've made some progress as you can see in the comments for @Mike s question. I'll try what you've just added as an answer though. Thanks –  Adam May 8 '12 at 23:36

3 Answers 3

up vote 1 down vote accepted

Here is an example where you 'll see the steps for that process (looks like you're missing the apxs2 and the apache LoadModule directive in our question) :

#!/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 
share|improve this answer
    
I can't run that script as is. It throws a few errors, but I do have axps installed now, and there is a LoadModule in mods-enabled but that itself is throwing an error. This is from Mikes answer apache2: Syntax error on line 210 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/mods-enabled/php5.load: Cannot load /usr/lib/apache2/modules/libphp5.so into server: /usr/lib/apache2/modules/libphp5.so: undefined symbol: OnUpdateLong –  Adam May 8 '12 at 23:50
    
sure you can't, this is just to show you the steps. Pls take care apxs is not apxs2. As you have installed the non-threaded-MPM-apache (prefork), the apxs you need is part of the apache2-prefork-dev package, not of apache2-threaded-dev. apache2-threaded-dev is for the apache running with a multi-threaded MPM (worker). apt-get remove apache2-threaded-dev apt-get install apache2-prefork-dev –  hornetbzz May 8 '12 at 23:58
    
Aha! It's working. Mike already prompted me to install apache2-prefork-dev but I couldn't see the apxs binary until I did updatedb; locate apxs. Now I've got the joy of finding all the missing extensions it didn't install. Thanks for your help –  Adam May 9 '12 at 11:21

You installed the command line version only.. You didn't install the apache module. You need to add the following

--with-apxs2

Make sure you have apache2-dev installed

share|improve this answer
    
During the configure I'm getting: Sorry, I cannot run apxs. Possible reasons follow: 1. Perl is not installed 2. apxs was not found. Try to pass the path using --with-apxs2=/path/to/apxs 3. Apache was not built using --enable-so (the apxs usage page is displayed) –  Adam May 8 '12 at 22:20
    
Does this mean I have to compile apache from source or, is there a path to apxs I don't know about (whatever apxs is)? –  Adam May 8 '12 at 22:21
    
what happens if you run apxs from command line? –  Mike May 8 '12 at 22:24
    
Command not found. There's an apxs2 in apache2-threaded-dev and apache2-prefork-dev –  Adam May 8 '12 at 22:26
    
which version of apache do you have? install that same version for -dev dpkg -l | grep apache –  Mike May 8 '12 at 22:29

Have a look in your httpd.conf file/dir and take a close look at your LoadModule statements. There is bound to be one still pointing towards php 5.3.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.