1

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.

Imnotapotato
  • 5,308
  • 13
  • 80
  • 147
  • Is there anything written to `/var/log/apache2/error.log`? – Nico Haase Mar 26 '18 at 09:11
  • I found this question similar to yours. https://stackoverflow.com/questions/42619312/switch-php-versions-on-commandline-ubuntu-16-04 and also check this link for your apache error https://askubuntu.com/questions/629995/apache-not-able-to-restart – Ravi Hirani Mar 26 '18 at 09:29
  • 1
    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 Mar 26 '18 at 10:08
  • @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 – Imnotapotato Mar 26 '18 at 10:17
  • @Justin I tried `update-alternatives`, it looks nice, but doesn't work – Imnotapotato Mar 26 '18 at 10:18
  • 2
    Right. `update-alternatives` has nothing to do with your problem. That's what I was trying to say. – Justin Mar 26 '18 at 10:23
  • If it works with php7 and not php5, probably something is not compatible, don't you think? Try disabling mods and confgs. Something might rely on php7. – Justin Mar 26 '18 at 10:24
  • @Justin compared all mods and the only difference between them is `sodium` on php7.2 that i don't have on `php5.6` – Imnotapotato Mar 26 '18 at 10:51
  • The error occurs when restarting the apache2 server. I think it's from there more that it's from the php7.2, which apache2 log file should interest me? I when through a few and didn't find anything helpful @Justin – Imnotapotato Mar 26 '18 at 10:53
  • Oh, and not sure if enough mentioned.. php5.6 does work on CLI, the apache2 command line is the problem – Imnotapotato Mar 26 '18 at 10:56
  • It's an apache2 problem. Not a php problem. Things like phpMyAdmin use php and could fail if something is not supported. As mentioned earlier, the apache2 error log should log the startup notes `/var/log/apache2/error.log` – Justin Mar 26 '18 at 11:08
  • I removed and reinstalled `libapache2-mod-php5.6` and got this message in the end of the installation: "`libapache2-mod-php5.6: php7.1 module already enabled, not enabling PHP 5.6 `" How do i enable libapache2-mod-php5.6 instead of libapache2-mod-php7.1? – Imnotapotato Mar 26 '18 at 11:10
  • Update: I have tested the exact process with a clean OS (virtual machine) and got the exact same error btw. – Imnotapotato Mar 26 '18 at 11:39
  • @Justin no phpmyadmin on the VM.. stiff didn't work. I `tail -f`-ed `/var/log/apache2/error.log` and when trying to restart the server or refreshing a page - no update on the `error.log` file – Imnotapotato Mar 26 '18 at 11:43
  • You might try `apachectl configtest` to make sure there isn't a configuration file error. `libapache2-mod-php5.6` is just the long name for `mod php5.6`. To turn off php7.1, use `a2dismod php7.1`. Have you posted about this on the Ubuntu stack site? – Justin Mar 26 '18 at 11:50
  • Oh. so i'm swapping between them with the right syntax. Yes, I have posted it there too. no comments. – Imnotapotato Mar 26 '18 at 11:54
  • solved it! `sudo a2dismod php7.2 && sudo a2dismod php7.1 && sudo a2dismod php7.0` and then `sudo a2enmod php5.6` and it worked, maybe one of them was enabled... Although this doesn't make sense because `sudo a2enmod php7.2` worked properly. – Imnotapotato Mar 26 '18 at 12:10

2 Answers2

0

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>

0

It will take some time to figure out the issue as we can't find a proper error log for this.

Please follow the below step to fix the issue.

  1. To get better idea check the apache2 mods-enabled directory.
cd /etc/apache2/mods-enabled
ls -lrt php*
  1. if you have enabled below modules.
php7.4.conf -> ../mods-available/php7.4.conf
php7.4.load -> ../mods-available/php7.4.load

Uninstall the php7.2 or remove the unwanted php7.2 packages using the sudo apt autoremove command.

sudo apt autoremove libapache2-mod-php7.4 libzip5 php7.4-bcmath php7.4-curl php7.4-fpm php7.4-gd php7.4-mbstring php7.4-mysql php7.4-xml php7.4-zip
  1. Now you can run the enable command.
sudo a2enmod php5.6
  1. Check the enabled modules on the path below, now you should see php5.6 modules enabled.
ls -lrt /etc/apache2/mods-enabled/php*
  1. Restart the apache2 server.

sudo service apache2 restart

Now your apache2 is running without any issue.

I hope it helped :)

Aditya Y
  • 651
  • 6
  • 12