Ubuntu – How to install PHP5.6 when using apache2.4.28 complile from source on Ubuntu 16.04

16.04Apache2PHPserver

I try to compile Apache 2.4.28 from source, I can't use command

apt-get install apache2

Because this command install Apache 2.4.18 only.

Here is my install step:

  • Install dependency

    apt-get install build-essential 
    apt-get install libexpat1-dev
    apt-get install libpcre3-dev libssl-dev 
    
  • Download apache2.4.28

    cd /usr/local/src    
    wget http://mirrors.viethosting.com/apache//apr/apr-1.6.2.tar.gz 
    wget http://mirrors.viethosting.com/apache//apr/apr-util-1.6.0.tar.gz
    wget http://archive.apache.org/dist/httpd/httpd-2.4.28.tar.gz
    
  • Compile apache 2.4.28

    tar xzvf apr-1.6.2.tar.gz
    tar xzvf apr-util-1.6.0.tar.gz
    tar xzvf httpd-2.4.28.tar.gz
    mv apr-1.6.2/ httpd-2.4.28/srclib/apr
    mv apr-util-1.6.0/ httpd-2.4.28/srclib/apr-util
    ./configure --prefix=/etc/apache2 --enable-mods-shared="reallyall" --enable-mpms-shared="all"
    

    Configure result

    make && make install
    

    enter image description here

    ln -s /etc/apache2/bin/apachectl /etc/init.d/apache
    update-rc.d apache defaults----> It has this warning "insserv: warning: script 'apache' missing LSB tags and overrides"
    
    service apache start
    

After performing the above steps, Apache 2.4.28 has been run. But I when I use

apache2 -v ----> it's not show the version of apache2

enter image description here

Then I install PHP5.6 like this:

apt-get install software-properties-common
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php5.6

When I use this command it not only install php5.6 but also install apache2.4.18 and when I test PHP by:

echo "hello world"; ----> it not show any thing.

And

root@ubuntu:~# ps -aux | grep httpd
root        991  0.0  0.1  75268  3848 ?        Ss   02:47   0:00 /usr/local/apache2/bin/httpd -k start

@Edit: as the comment I change:

./configure --prefix=/etc/apache2 --enable-mods-shared="reallyall" --enable-mpms-shared="all"

to

./configure --prefix=/usr/local/apache2 --enable-mods-shared="reallyall" --enable-mpms-shared="all"

Please help me, thank in advance.

Best Answer

I believe you have done several things wrong. First this line:

./configure --prefix=/etc/apache2 --enable-mods-shared="reallyall" --enable-mpms-shared="all"

should have been:

./configure --prefix=/usr/local/apache2" --enable-mods-shared="reallyall" --enable-mpms-shared="all"

Your --prefix option during compile is wrong. I advice you remove it and fix that --prefix option

How to compile:

  1. Download the source file for the version you want

  2. Install build requirements:

    sudo apt-get install build-essential
    
  3. Install Zlib for compresssion with these steps:

    cd /usr/local/src
    wget http://www.zlib.net/zlib-1.2.8.tar.gz
    tar xvfz zlib-1.2.8.tar.gz
    cd zlib-1.2.8/
    ./configure --prefix=/usr/local
    make
    
  4. Compile apache with these steps:

    • Move the downloaded apache source file into /usr/local/src, then

      cd /usr/local/src
      tar xvfz httpd-2.4.10.tar.gz
      cd httpd-2.4.10/            
      sudo ./configure
      
      • If you get APR error run :

        sudo apt install libapr1-dev libaprutil1-dev                 
        
    • If successful run:

      sudo make
      sudo make install
      
  5. Check to see if it's working:

    sudo /usr/local/apache2/bin/apachectl start
    
    • put http://localhost or your machine ip address and you should see a message saying "It works!"
  6. Enable boot startup:

    sudo cp /usr/local/apache2/bin/apachectl /etc/init.d/apache2
    sudo chmod +x /etc/init.d/apache2
    
  7. Add to default runlevels:

    sudo /usr/sbin/update-rc.d -f apache2 defaults
    

Source:

http://www.linuxpathfinder.com/install-apache-from-source-on-ubuntu