Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpbrew switch doesn't change php on apache #226

Closed
gmbelart opened this issue Apr 23, 2014 · 19 comments
Closed

phpbrew switch doesn't change php on apache #226

gmbelart opened this issue Apr 23, 2014 · 19 comments

Comments

@gmbelart
Copy link

hello

when I run this

phpbrew switch 5.4.27

then execute

php -v

it give me php version 5.4.27,

but when I execute script on browser,
it give me php version 5.3.28

I try to reload apache with

sudo service apache2 reload

nothing change,

still give me 5.3.28

but if I change file on /etc/apache2/mods-enabled/php5.load

from
LoadModule php5_module /usr/lib/apache2/modules/libphp5.3.28.so

to
LoadModule php5_module /usr/lib/apache2/modules/libphp5.4.27.so

then I reload apache,

finally

give me 5.4.27

it's bug of phpbrew switch? or not?

my laptop
OS: elementary os luna (based on ubuntu 12.04)
Apache: 2.2.22

sorry for my bad english .. 😃

thanks.

@schneidermayer
Copy link

This is normal behaviour. phpbrew switch 5.3.28 changes the version on command line (cli), changing the .so file affects apache webserver.

@marcioAlmada
Copy link
Member

thanks, @heanz.

@ghost
Copy link

ghost commented Jun 26, 2014

@heanz This really isn't documented very well at all in the readme.md, who's deals with documentation ?

p.s.

Nice one for the answer q-dos ;)

@chadrien
Copy link
Contributor

@molemann : to achieve the switch with apache, I think you may wrap phpbrew switch in way that it would sed your apache configuration and then restart the daemon.

I'm not sure if it could work or not as I use nginx/fpm which allow you to have as much php versions running at the same time as you want (</troll> 😄 )

But I you manage to do so, feel free to share with us so we can add it to the docs!

@schneidermayer
Copy link

This is an example bash script for changing the apache php version:

#!/bin/bash 
# Change Apaches PHP Module to 5.5.10

echo "Loading PHP 5.5.10 ..."
echo "LoadModule php5_module /usr/lib/apache2/modules/libphp5.5.10.so" > /etc/apache2/mods-available/php5.load
sudo service apache2 reload

Basically, it writes the path of the 5.5.10 module libphp5.5.10.so into the textfile /etc/apache2/mods-available/php5.load. Just make sure phpbrew copied the appropriate modules to the right directory.

@Anahkiasen
Copy link

Where do the .so files even go when installing with phpbrew, I can't find them anywhere on Mac?

@shinnya
Copy link
Member

shinnya commented Jan 12, 2015

@Anahkiasen You can know where apache library directory is by apxs -q LIBDIR and find .so files under modules/ subdirectory(for example, /usr/lib/httpd/modules/libphp5.3.20.so in my environment).

@Anahkiasen
Copy link

Yes no don't mind me, they weren't getting installed because I wasn't installing with +apxs2. Thought that was encompassed by +default

@alexserver
Copy link

shit, I'm having problems installing apsx2 in ubuntu. in ubuntu this is called apache2 and not apxs2.

@convenient
Copy link

I scripted this on my Ubuntu 15.10 instance. Created a little shell script phpbrewswitch which will only switch php version when the .so file is found.

Usage

Attempting to switch to a php version that wasn't built for apache

[21:02:55] luker [~]$ phpbrewswitch 5.4.45
5.4.45 is not configured for apache
  php-5.6.16     
  php-5.6.10     
* php-5.5.30     
  php-5.4.45     

Successfully changing to a php version that has an existing .so file.

[21:03:55] luker [~]$ phpbrewswitch 5.6.16
* php-5.6.16     
  php-5.6.10     
  php-5.5.30     
  php-5.4.45     
Updated /etc/apache2/mods-available/php5.load

/home/luker/bin/phpbrewswitch

#!/usr/bin/env bash
VERSION=$1

SOFILE=/usr/lib/apache2/modules/libphp$VERSION.so
CONFFILE=/etc/apache2/mods-available/php5.load

source ~/.phpbrew/bashrc

if [ -f $SOFILE ]; then
    phpbrew switch $VERSION
    phpbrew list

    FILECONTENTS="LoadModule php5_module $SOFILE"
    echo $FILECONTENTS > $CONFFILE

    echo "Updated $CONFFILE"
    sudo service apache2 restart

else
    echo $VERSION "is not configured for apache"
    phpbrew list
fi

@hell-n
Copy link

hell-n commented Jul 26, 2016

Hello!

I ran into the same problem, but can't get it to work, like gmbelart.
php -v returns my desired version, after using phpbrew switch php-5.4.45, but i'm too incompetent to get the right .so-file loaded by Apache. :D

Since I'm currently using Apache/2.4.18 (Ubuntu), which runs PHP 7.0 out of box, there isn't even a php5.load file in /etc/apache2/mods-enabled. And if i add the line to the php7.0.load apache won't reload. Error: apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Syntax error on line

I even tried to create the php5.load file, but this failed as well.

Please, help me guys!
Nik

@simonkulessa
Copy link

@hell-n
Me helped this one:
#738

@ve3
Copy link

ve3 commented Jan 15, 2017

Hello

Does anyone know how to switch version on Apache using PHP fast cgi?

@simonkulessa
Copy link

Die you build php with +apxs2?

@ve3
Copy link

ve3 commented Jan 16, 2017

@Pupp3tm4st3r Yes, I did. @schneidermayer comment works fine for me as Apache module.

@drupalranger
Copy link

drupalranger commented Apr 28, 2017

On Ubuntu 17.04 I'm using following bash function

#!/bin/bash

phpswitch() {
 echo "Starging phpbrew switch to $1"; 
 eval string="$1";
 eval version=${string:0:3};
 phpbrew switch php-"$1"; 

 echo "Disabling all versions apache php module";
 sudo a2dismod php*;

 sudo a2enmod php"$version";
 sudo service apache2 restart; 
 echo "apache2 has been restarted" 
}

it needs version number as an argument, so while I have following version installed:

$ phpbrew list
  php-7.1.4      
* php-7.0.18     
  php-7.0.13     
  php-5.6.30    

All I need to do is to type one command with version number, e.g.:
phpswitch 5.6.30

@iuli-dercaci
Copy link

@oscarromero
Copy link

Maybe too late, but for colleagues with apache2 + debian need to install the libapache2-mod-php7.3 and disable the default/system php that you have. after that, restart the apache2 service.

@ttodua
Copy link
Contributor

ttodua commented Jun 10, 2021

This is also helpful to tell apache2 to use phpbrew's .so files: https://stackoverflow.com/a/41904646/2377343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests