Error restarting apache after changing php version
Im trying to downgrade to php7.4 from 8 on ubuntu 20.04. Fresh install from the Digital Ocean "Marketplace" LAMP setup.
Trying to follow guides to do this:
I can select the cli php like this:
update-alternatives --config phpbut selecting an option only changes the cli php, not the website php version.
I then ran this to try and get the web php to be 7.4.
sudo a2enmod php7.4
> php 7.4 not installed. I then ran these commands
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php
sudo apt install php7.4
sudo a2enmod php7.4
systemctl restart apache2and got error:
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xe" for details.
systemctl status apache2.service
root@lamp-ubuntu-s-1vcpu-1gb-sgp1-01:/etc/apache2# systemctl status apache2.service
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Thu 2022-04-21 18:18:36 UTC; 27s ago Docs: Process: 45635 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)
journalctl -xe
- no entries. What is going wrong here? how can i simply change the php version for websites on this server?
UPDATE: Journalctl -xe seems to have content now:
-- The job identifier is 17693.
Apr 22 12:27:07 wairc-kman-1 apachectl[39336]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppre>
Apr 22 12:27:07 wairc-kman-1 kernel: apache2[39336]: segfault at 8 ip 00007f599f125215 sp 00007fff5ed2df10 error 4 in libphp7.4.so[7f599ef45000+260000]
Apr 22 12:27:07 wairc-kman-1 kernel: Code: 41 5d e9 0e fa ff ff 66 66 2e 0f 1f 84 00 00 00 00 00 0f 1f 00 f3 0f 1e fa 41 56 41 55 49 89 d5 41 54 49 89 f4 55 48 89 fd 53 <8b> 47 08 a8 0c 0f 85 28 01 00 0>
Apr 22 12:27:20 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=162.142.125.84 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=40 ID=64004 PROTO=TCP SPT=>
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: Segmentation fault (core dumped)
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: Action 'start' failed.
Apr 22 12:27:27 wairc-kman-1 apachectl[39330]: The Apache error log may have more information.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: apache2.service: Control process exited, code=exited, status=139/n/a
-- Subject: Unit process exited
-- Defined-By: systemd
-- Support:
--
-- An ExecStart= process belonging to unit apache2.service has exited.
--
-- The process' exit code is 'exited' and its exit status is 139.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: apache2.service: Failed with result 'exit-code'.
-- Subject: Unit failed
-- Defined-By: systemd
-- Support:
--
-- The unit apache2.service has entered the 'failed' state with result 'exit-code'.
Apr 22 12:27:27 wairc-kman-1 systemd[1]: Failed to start The Apache HTTP Server.
-- Subject: A start job for unit apache2.service has failed
-- Defined-By: systemd
-- Support:
--
-- A start job for unit apache2.service has finished with a failure.
--
-- The job identifier is 17693 and the job result is failed.
Apr 22 12:27:29 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=29 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:27:46 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=91.240.118.246 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=245 ID=39592 PROTO=TCP SPT>
Apr 22 12:28:05 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=71 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:28:27 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=68 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:28:44 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=162.142.125.238 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=40 ID=55003 PROTO=TCP SPT>
Apr 22 12:28:58 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=193.163.125.43 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=246 ID=18628 PROTO=TCP SPT>
Apr 22 12:29:16 wairc-kman-1 CRON[38918]: pam_unix(cron:session): session closed for user root
Apr 22 12:29:23 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=42 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:29:47 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=92.63.197.94 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=251 ID=8419 PROTO=TCP SPT=48>
Apr 22 12:30:09 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=89.248.165.97 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=250 ID=57521 PROTO=TCP SPT=>
Apr 22 12:30:21 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=91.240.118.244 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=246 ID=26437 PROTO=TCP SPT>
Apr 22 12:30:38 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=44 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Invalid user fin from 167.172.153.164 port 54352
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Received disconnect from 167.172.153.164 port 54352:11: Bye Bye [preauth]
Apr 22 12:31:02 wairc-kman-1 sshd[39388]: Disconnected from invalid user fin 167.172.153.164 port 54352 [preauth]
Apr 22 12:31:14 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=80.218.99.137 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=52 ID=13396 PROTO=TCP SPT=1>
Apr 22 12:31:33 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=40 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
Apr 22 12:31:48 wairc-kman-1 kernel: [UFW BLOCK] IN=eth0 OUT= MAC=92:8c:09:7c:5d:30:fe:00:00:00:01:01:08:00 SRC=128.14.133.50 DST=128.199.47.247 LEN=41 TOS=0x00 PREC=0x00 TTL=239 ID=54321 PROTO=UDP SPT=>
lines 3243-3290/3290 (END)
systemctl status apache2.service
● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: failed (Result: exit-code) since Fri 2022-04-22 12:42:14 UTC; 9s ago Docs: Process: 39548 ExecStart=/usr/sbin/apachectl start (code=exited, status=139)
Apr 22 12:41:53 wairc-kman-1 systemd[1]: Starting The Apache HTTP Server...
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: Segmentation fault (core dumped)
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: Action 'start' failed.
Apr 22 12:42:14 wairc-kman-1 apachectl[39548]: The Apache error log may have more information.
Apr 22 12:42:14 wairc-kman-1 systemd[1]: apache2.service: Control process exited, code=exited, status=139/n/a
Apr 22 12:42:14 wairc-kman-1 systemd[1]: apache2.service: Failed with result 'exit-code'.
Apr 22 12:42:14 wairc-kman-1 systemd[1]: Failed to start The Apache HTTP Server.And config test is ok after setting ServerName 127.0.0.1 to fix previous warning
> apachectl configtest
Syntax OKLooking into what php is installed:
update-alternatives --get-selections | grep -i php
php auto /usr/bin/php8.1
php-fpm.sock auto /run/php/php7.4-fpm.sock
phpdbg auto /usr/bin/phpdbg7.4Looking at php-fpm options:
update-alternatives --config php-fpm
update-alternatives: error: no alternatives for php-fpmIf I select php7.4, it shows it has selected it, but running php-v shows the old value, 8.1.
update-alternatives --config phar There are 3 choices for the alternative phar (providing /usr/bin/phar).
Selection Path Priority Status
0 /usr/bin/phar8.1 81 auto mode
1 /usr/bin/phar7.4 74 manual mode 2 /usr/bin/phar8.0 80 manual mode 3 /usr/bin/phar8.1 81 manual mode
Press to keep the current choice[*], or type selection number: root@wairc-kman-1:~# php -v PHP 8.1.5 (cli) (built: Apr 21 2022 10:14:45) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.5, Copyright (c) Zend Technologies with Zend OPcache v8.1.5, Copyright (c), by Zend Technologies
1 Answer
Run this command to figure out why Apache is failing.
journalctl -xeMost likely problem is that you have more than on PHP module enabled, e.g. php8.0 was enabled and then you also enabled php7.4. Apache does not like that. Enable on one PHP module.
There are multiple PHP extensions that support Apache: php, php-cgi and php-fpm.
The first step is to figure out which PHP installations are configured:
update-alternatives --get-selections | grep -i phpWith modern PHP Apache installations, php-fpm is probably configured.
To change the PHP version that Apache uses, use this command:
update-alternatives --config php-fpmAlso, optionally change the phar configurations:
update-alternatives --config phar
update-alternatives --config phar.pharYou can also easily switch the PHP version by adding this to VirtualHost:
<FilesMatch \.php$> # PHP Version 7.4 SetHandler "proxy:unix:/run/php/php7.4-fpm.sock|fcgi://localhost" # PHP Version 8.0 # SetHandler "proxy:unix:/run/php/php8.0-fpm.sock|fcgi://localhost"
</FilesMatch>List the /run/php directory to see which PHP sockets are configured.
Restart Apache after configuration changes:
systemctl restart apache2 3