1
votes

following this tutorial to switch between php versions: (7.2 and 5.6):

http://mehedi.info/2017/06/07/use-php-5-6-php-7-0-alongside-one-another-ubuntu/

sudo add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install php5.6 php5.6-mysql php5.6-mbstring libapache2-mod-php5.6

From php5.6 to php7.2:

sudo a2dismod php5.6 ; sudo a2enmod php7.2 ; sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php7.2

From php7.2 to php5.6:

sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart
sudo update-alternatives --set php /usr/bin/php5.6

when running sudo a2dismod php7.2 ; sudo a2enmod php5.6 ; sudo service apache2 restart in the terminal i get this error:

Module php7.2 already disabled Considering dependency mpm_prefork for php5.6: Considering conflict mpm_event for mpm_prefork: Considering conflict mpm_worker for mpm_prefork: Module mpm_prefork already enabled Considering conflict php5 for php5.6: Module php5.6 already enabled Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

is is what i get from systemctl status apache2.service:

● apache2.service - The Apache HTTP Server    Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf    Active: failed (Result: exit-code) since Mon 2018-03-26 10:56:51 IDT; 38min ago   Process: 18615 ExecStop=/usr/sbin/apachectl stop (code=exited, status=139)   Process: 18891 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)  Main PID: 18540 (code=exited, status=0/SUCCESS)

Mar 26 10:56:51 Company systemd[1]: Starting The Apache HTTP Server...
Mar 26 10:56:51 Company apachectl[18891]: Segmentation fault (core dumped)
Mar 26 10:56:51 Company apachectl[18891]: Action 'start' failed.
Mar 26 10:56:51 Company apachectl[18891]: The Apache error log may have more information.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Control process exited, code=exited status=139
Mar 26 10:56:51 Company systemd[1]: Failed to start The Apache HTTP Server.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Unit entered failed state.
Mar 26 10:56:51 Company systemd[1]: apache2.service: Failed with result 'exit-code'.

and this is from systemctl status apache2.service:

-- 
-- The start-up result is done.
Mar 26 11:33:45 Company nm-dispatcher[20168]: req:1 'dhcp4-change' [wlp3s0]: new request (1 scripts)
Mar 26 11:33:45 Company nm-dispatcher[20168]: req:1 'dhcp4-change' [wlp3s0]: start running ordered s
Mar 26 11:33:45 Company kernel: userif-4: sent link down event.
Mar 26 11:33:45 Company kernel: userif-4: sent link up event.
Mar 26 11:33:52 Company vmnet-dhcpd[2740]: DHCPREQUEST for 192.168.90.128 from 00:0c:29:71:c5:c9 via
Mar 26 11:33:52 Company vmnet-dhcpd[2740]: DHCPACK on 192.168.90.128 to 00:0c:29:71:c5:c9 via vmnet8
Mar 26 11:34:01 Company CRON[20179]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:34:01 Company CRON[20180]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:34:01 Company CRON[20179]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:34:01 Company CRON[20179]: pam_unix(cron:session): session closed for user username
Mar 26 11:35:01 Company CRON[20202]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:35:01 Company CRON[20203]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:35:01 Company CRON[20202]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:35:01 Company CRON[20202]: pam_unix(cron:session): session closed for user username
Mar 26 11:36:01 Company CRON[20235]: pam_unix(cron:session): session opened for user username by (uid=0
Mar 26 11:36:01 Company CRON[20236]: (username) CMD (/home/username/collectit/bin/collectit.sh >>/tmp/coll
Mar 26 11:36:01 Company CRON[20235]: (CRON) info (No MTA installed, discarding output)
Mar 26 11:36:01 Company CRON[20235]: pam_unix(cron:session): session closed for user username

I have tested the exact process with a clean new OS (virtual machine) and got the exact same error btw.

1
Is there anything written to /var/log/apache2/error.log? - Nico Haase
I found this question similar to yours. stackoverflow.com/questions/42619312/… and also check this link for your apache error askubuntu.com/questions/629995/apache-not-able-to-restart - Ravi
If all you are doing is changing what apache2 uses, you don't need to worry about sudo update-alternatives. I switch between 7.0, 7.1, and 7.2 using that ppa and the sudo a2dismod php7.? sudo a2enmod php7.? with no problems. So I wonder if you have a mod or configuration enabled that is incompatible with php5.6. - Justin
@RaviHirani I have tried all methods stated in these posts except of the one including reinstalling apache2 - which will be a total mess for me to do so - W.Doch
Right. update-alternatives has nothing to do with your problem. That's what I was trying to say. - Justin

1 Answers

0
votes

You can define different FastCgi service paths for each Virtual Host

<VirtualHost *:80> DocumentRoot /var/www <FilesMatch \.php$> SetHandler "proxy:unix:path/to/php-fpm-version.sock|fcgi://localhost" </FilesMatch> </VirtualHost>