Error module php8 does not exist

Добрый день. У меня не вопрос, а ответ.

Добрый день. У меня не вопрос, а ответ.
На самом деле всё просто, но конкретно ни один готовый рецепт мне не подошёл (особенно на русском языке; возможно, неправильно гуглил). Я пережил несколько неприятных минут, но в конечном итоге экспериментальным путём я пришёл к некоему решению, которым и спешу поделиться. Мой собственный сайт сейчас не доступен (уже по другим причинам), так что я размещу это здесь. Для кого-то это будет повторением пройденного, а кому-то может сослужить службу.

Итак, после апгрейда Ubuntu Server 20.04 -> 22.04.1 перестал запускаться Apache из-за «ошибок синтаксиса» в файлах /etc/apache2/sites-enabled/[имясайта].conf. В частности, претензии такого вида:

>Invalid command ‘php_flag’, perhaps misspelled or defined by a module (…)

И другие строки, которые содержат директивы, относящиеся к php.

Если закомментировать данные строки, то сервер запускается и даже не выдаёт “500 internal server error”, однако в браузере сайты выглядят так, как будто Apache не исполняет код php.

Что мы можем здесь проверить?

Php в системе имеется:

# php -v

PHP 8.1.2 (cli) (built: Jul 21 2022 12:10:37) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.2, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.2, Copyright (c), by Zend Technologies

М. б. отсутствует модуль Apache, ответственный за php?

# apt install libapache2-mod-php

>…
>libapache2-mod-php is already the newest version (2:8.1+92ubuntu1).
 

# a2enmod php

>ERROR: Module php does not exist!

Вот оно! — подумал я. И да, это оно. А ларчик просто открывался, в моём случае нужно было говорить 

# a2enmod php8.1
Ну и далее не забыть

# service apache2 restart
У меня всё заработало. Впоследствии я раскомментировал упомянутые строки в конфигах сайтов (всё-таки они относятся к безопасности), и всё продолжило работать.
С нетерпением жду следующего обновления системы.

Спасибо за внимание.

Installing php7.4 on ubuntu 20(aws server) I have php 8 installed.
I tried to disable it and enable 7.4.
All my output commands below show valid output, but restarting apache I have php8 anyway:

ubuntu@ip-172-31-38-186 : ubuntu :~$ cd /etc/php
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ ls -la
total 36
drwxr-xr-x  9 root root 4096 Jul 22 11:28 .
drwxr-xr-x 96 root root 4096 Jul 25 03:59 ..
drwxr-xr-x  3 root root 4096 Jul 22 11:28 5.6
drwxr-xr-x  3 root root 4096 Jul 22 11:28 7.0
drwxr-xr-x  3 root root 4096 Jul 22 11:28 7.1
drwxr-xr-x  3 root root 4096 Jul 22 11:28 7.2
drwxr-xr-x  3 root root 4096 Jul 22 11:28 7.3
drwxr-xr-x  5 root root 4096 Jul 22 11:23 7.4
drwxr-xr-x  5 root root 4096 Jul 22 11:28 8.0
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ uname -a
Linux ip-172-31-38-186 5.8.0-1041-aws #43~20.04.1-Ubuntu SMP Thu Jul 15 11:07:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ php -v
PHP 8.0.8 (cli) (built: Jul  1 2021 15:26:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ sudo a2dismod php8.0
Module php8.0 already disabled
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ sudo a2dismod php8
ERROR: Module php8 does not exist!
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ sudo a2dismod php8.0.8
ERROR: Module php8.0.8 does not exist!
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ sudo a2enmod php7.4
Considering dependency mpm_prefork for php7.4:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.4:
Module php7.4 already enabled
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ sudo service apache2 restart
ubuntu@ip-172-31-38-186 : ubuntu :/etc/php$ php -v
PHP 8.0.8 (cli) (built: Jul  1 2021 15:26:46) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.8, Copyright (c) Zend Technologies
    with Zend OPcache v8.0.8, Copyright (c), by Zend Technologies

restarting OS did not help.
How to setup php 7.4 ?

Thanks!

asked Jul 25, 2021 at 5:12

mstdmstd's user avatar

Please run the below command and then check php vrsion on ubuntu .

1. apt-get install -y software-properties-common
 2. add-apt-repository ppa:ondrej/php -y

 3. apt-get update -y



4. apt-get install -y php7.4 libapache2-mod-php7.4 php7.4-curl php7.4-gmp php7.4-mbstring php7.4-phpdbg php7.4-sqlite3 php7.4-zip php7.4-bcmath php7.4-dba php7.4-imap php7.4-pspell php7.4-sybase php7.4-bz2 php7.4-dev php7.4-interbase php7.4-mysql php7.4-readline php7.4-tidy php7.4-cgi php7.4-enchant php7.4-intl php7.4-odbc php7.4-xml php7.4-cli php7.4-fpm php7.4-json php7.4-opcache php7.4-snmp php7.4-xmlrpc php7.4-common php7.4-gd php7.4-ldap php7.4-pgsql php7.4-soap php7.4-xsl php7.4-mongodb


5.sudo update-alternatives --set php /usr/bin/php7.4

now check php version

Thanks

answered Jul 25, 2021 at 5:55

Rakesh Gadhwal's user avatar

3

I have Ubuntu Server 16.04 installed with Webmin 1.831. I am getting this error when trying to run PHP ERROR: Module php7.0 does not exist

libapache2-mod-php7.0 is installed.

asked May 7, 2017 at 2:35

Dominic Kasheimer's user avatar

5

sudo apt purge libapache2-mod-php7.0 libapache2-mod-php

then

sudo apt install libapache2-mod-php7.0 libapache2-mod-php

fixed it.

pomsky's user avatar

pomsky

65.6k20 gold badges228 silver badges241 bronze badges

answered May 9, 2017 at 1:10

Dominic Kasheimer's user avatar

3

I have faced the same problem and Here is the solution:

You have to install an additional package:

sudo apt-get install libapache2-mod-php7.0

Now run

sudo a2enmod php7.0

to enable it

Restart the server

sudo systemctl restart apache2.service

pomsky's user avatar

pomsky

65.6k20 gold badges228 silver badges241 bronze badges

answered Jul 5, 2017 at 14:31

BSB's user avatar

For the latest php version as of Nov. 2020, I solved the same problem with the following commands — in that order.

$ sudo apt purge libapache2-mod-php7.4 libapache2-mod-php
$ sudo apt-get install libapache2-mod-php7.4
$ sudo a2enmod php7.4
$ sudo service apache2 stop
$ sudo service apache2 start

answered Nov 22, 2020 at 21:32

Rodgers-Ategyeka's user avatar

5

My OS is Ubuntu 22.04

I started out by installing php 8.1

I then installed Apache/2.4.52 (Ubuntu) Server

Then I added the following:

sudo apt-get install -y php php-cli php-common php-mysql php-zip php-gd php-mbstring php-curl php-xml php-bcmath libapache2-mod-php

The command: php -v, produces:

PHP 8.1.2-1ubuntu2.8 (cli) (built: Nov  2 2022 13:35:25) (NTS)

Then I modified:

/etc/apache2/mods-enabled/dir.conf: DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

I restarted the apache2 server.

I added an index.php file, but when I try to go to the web page, I only see the listing of index.php

<?php
echo 'This is a test';

I also have an index.html file in there:

<h1>This is a test</h1>

When I delete index.php, and I go back to the web page, I see

This is a test

In a large bold font, as expected.

The PHP manual (as well as the answer I found on this site) refers to an httpd.conf file, and wants me to add:

LoadModule php_module modules/libphp.so

but I don’t have an httpd.conf on Ubuntu 22.04, I have an apache2.conf in the /etc/apaache2 folder, which is a skeleton file that loads everything from various subfolders.

When I tried:

sudo a2enmod php

I got:

ERROR: Module php does not exist!

Any ideas?

Edit:

I did:

cd /etc/apache2
grep -R php

And this is what I got:

sites-available/default-ssl.conf:       <FilesMatch ".(cgi|shtml|phtml|php)$">
sites-available/default-ssl.conf.original:      <FilesMatch ".(cgi|shtml|phtml|php)$">
mods-enabled/dir.conf:  DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
mods-available/dir.conf:    DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm

And doing:

sudo a2enmod php8.1

Produces the same error:

ERROR: Module php8.1 does not exist!

And grep’ing for the installed packages, I get:

libapache2-mod-php8.1/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
libapache2-mod-php/jammy,now 2:8.1+92ubuntu1 all [installed]
php-bcmath/jammy,now 2:8.1+92ubuntu1 all [installed]
php-cli/jammy,now 2:8.1+92ubuntu1 all [installed]
php-common/jammy,now 2:92ubuntu1 all [installed]
php-curl/jammy,now 2:8.1+92ubuntu1 all [installed]
php-gd/jammy,now 2:8.1+92ubuntu1 all [installed]
php-mbstring/jammy,now 2:8.1+92ubuntu1 all [installed]
php-mysql/jammy,now 2:8.1+92ubuntu1 all [installed]
php-xml/jammy,now 2:8.1+92ubuntu1 all [installed]
php-zip/jammy,now 2:8.1+92ubuntu1 all [installed]
php8.1-bcmath/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-cli/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-common/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-curl/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-gd/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-mbstring/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-mysql/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-opcache/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
php8.1-readline/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed,automatic]
php8.1-xml/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1-zip/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 amd64 [installed]
php8.1/jammy-updates,jammy-security,now 8.1.2-1ubuntu2.8 all [installed,automatic]
php/jammy,now 2:8.1+92ubuntu1 all [installed]

How to enable Apache mod_php using a2enmod, and how to find out what the name of the module is.

6349 views

d

By. Jacob

Edited: 2022-08-01 07:23

ERROR: Module php7 does not exist!

When trying to enable mod_php using the a2enmod command you may run into a message stating that the module does not exist; this is because the module is named php7.4 (for the latest version) rather than «php7».

To enable mod_php, type the following command:

The practice of naming various software by the version number is very bad and unintuitive for users. We can hope that we will some day have a «common name» that links to the latest version by default. This would probably avoid confusion caused by version numbers.

Of course, there are also circumstances where you want to install a specific version, such as when you are trying to maintain support for older software that only runs on older versions of PHP; but I think this happens so rarely nowadays that it is more the exception than the rule.

How to find the correct version

I would much prefer that «php» was an alias linked to the latest version of PHP — but you do get used to these things after a while. When using apt to install PHP, and if in doubt, we can simply search for packages that contain «PHP» in their name:

To get a list of installed Apache modules, try running the following command:

sudo apt-cache search libapache2*

This should result in something like:

libapache2-mod-php - server-side, HTML-embedded scripting language (Apache 2 module) (default)
libapache2-mod-php7.4 - server-side, HTML-embedded scripting language (Apache 2 module)

Then simply enable the latest version:

  1. How to have files uploaded through SFTP correctly inherit the group permissions of the parent directory.

  2. Tutorial showing how to configure a VirtualBox Guest VM with HOST-only and NAT adapter, while using the WWW folder from the HOST OS.

  3. Allow and Deny are being replaced with Require from mod_authz_host.

More in: Apache

PHP 8.0 brings several new features and improvements in performance, syntax, security, and stability. Installing PHP 8.0 on just about any sort of server/development setup is made easy with pre-compiled packages available in all currently supported Debian and Ubuntu versions.

Extensions and Dependency Changes in PHP 8.0

Despite the massive amount of changes, there are not many changes in PHP 8.0 in its dependencies and extension structure.

  1. JSON extension is now always available, and there is no compile flag to exclude it. This means there is no need to explicitly install php-json packages anymore.
  2. xmlrpc extension is moved to PECL with good reasons. Software repositories mentioned in this post does not include xmlrpc extension for PHP 8.0.

In addition, the GD extension has its name changed from php_gd2.dll to php_gd.dll in Windows that will be covered in a separate article.

INI changes in PHP 8.0

There are few INI file changes as well.

  1. Assertions throw exceptions by default — (assert.exception=1)
  2. Default error display is set to E_ALL — (error_reporting=-1)
  3. Startup errors are displayed by default — (display_startup_errors=1)

Due to new features and changes in PHP 8.0,

  • The new JIT feature in PHP 8.0 adds several new INI directives.
  • zend.exception_string_param_max_len INI setting due to Configurable exception stack trace string length

Installing PHP 8.0 on Ubuntu and Debian is made easy by the great efforts of Ondřej Surý. He maintains a PHP PPA that contains PHP 8.0 and several popular PECL extensions ready to install on any current Debian/Ubuntu system.


1. List existing PHP packages

If you are updating from an existing PHP version to 8.0, it’s important to get a list of existing PHP packages. Albeit the small extension changes, installing the PHP 8.0 counterpart packages is the easiest way to make sure the upgrade is smooth and covers the same packages from the current PHP version.

dpkg -l | grep php | tee packages.txt

This command will list all the packages containing name php, and writes it to a file named packages.txt, which can be referred anytime.

2. Add ondrej/php PPA

Ubuntu

sudo add-apt-repository ppa:ondrej/php # Press enter when prompted.
sudo apt-get update

Debian

sudo apt install apt-transport-https lsb-release ca-certificates wget -y
sudo wget -O /etc/apt/trusted.gpg.d/php.gpg https://packages.sury.org/php/apt.gpg 
sudo sh -c 'echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt update

Steps above will add the PPA as a source of packages, that contains all PHP packages and their dependencies such as argon2 and libzip.

3. Install PHP 8.0 and extensions

All PHP 8.0 packages follow php8.0-NAME pattern, and php8.0-common package includes a sensible set default of extensions (such as `php8.0-).

Install PHP 8.0 with CLI

sudo apt install php8.0-common php8.0-cli -y

This command will install several PHP extensions due to php8.0-common, and the CLI for PHP 8.0.

You can confirm the installation by running:

php -v # Show PHP version.
php -m # Show PHP modules loaded.

Additional extensions

You can install additional extensions from the same php8.0-NAME pattern. Refer to the packages.txt file to see a list of existing packages if you are upgrading an existing system.

Note that you do not need to install php8.0-json as it is now included by default.

An example to install a few more useful extensions:

sudo apt install php8.0-{bz2,curl,intl,mysql,readline,xml}

For development environments, code coverage tools or the Xdebug debugger can be installed as well.

sudo apt install php8.0-pcov # PCOV code coverage tool
sudo apt install php8.0-xdebug # Xdebug debugger

Install Server APIs

Depending on the web server you use, you will need to install additional packages to integrate with the web server.

For Apache using mpm_event, Nginx, Litespeed, etc., php8.0-fpm package provides integration with PHP 8.0 via FPM.

sudo apt install php8.0-fpm

For Apache using mod_php, install libapache2-mod-php8.0.

sudo apt install libapache2-mod-php8.0

Note that the Apache2Handler is renamed to php_module from php7_module in PHP 8.0. The libapache2-mod-php8.0 package automatically configures the Apache module location, but if you are updating from an existing PHP setup, you might need to update configuration files; in particularly <IfModule> blocks.

4. Test PHP 8.0 installation

To test the PHP installation and the extensions, run the following commands:

php -v
php -m
# php -v
PHP 8.0.0-dev (cli) (built: Oct 4 2020 14:04:36) ( NTS )
Copyright (c) The PHP Group
Zend Engine v4.0.0-dev, Copyright (c) Zend Technologies

# php -m
[PHP Modules]
Core
ctype
curl
...

Purge old PHP versions

If the new installation is working as expected, you can remove the old PHP packages from the system.

sudo apt purge '^php7.4.*'

This assumes you are using PHP 7.4 as the previous version. Change php7.4 part of the command above with the appropriate PHP version.

Running PHP 8.0 with Other Versions

Instead of removing old PHP versions, it is also possible to run multiple PHP versions side-by-side.

The PHP 8.0 CLI will be installed at /usr/bin/php8.0 location by default. Similarly, other PHP binary files will be located in the same directory (/usr/bin/php7.4, /usr/bin/php7.3, etc). The default php name will be symlinked to the latest PHP version by default, but it is possible to change where the default php command links to.

The update-alternatives command provides an easy way to switch between PHP versions for PHP CLI.

sudo update-alternatives --config php

This brings up a prompt to interactively select the alternative PHP binary path that php points to.

There are 2 choices for the alternative php (providing /usr/bin/php).
Selection Path Priority Status

------------------------------------------------------------

* 0 /usr/bin/php8.0 80 auto mode
1 /usr/bin/php7.4 74 manual mode
2 /usr/bin/php8.0 80 manual mode

Press to keep the current choice[*], or type selection number:

To set the path without the interactive prompt:

update-alternatives --set php /usr/bin/php7.4

What’s new and changed in PHP 8.0

For a complete list of changes in PHP 8.0, see What’s new and changed in PHP 8.0


PHP 8 logo is by Vicent PONTIER. Debian and Ubuntu icons are from Strongicon and ProGlyphes.

Sometimes installing PHP via the regular method does not help you install PHP properly and even after following the standard methods of installing all you get when trying to enable the PHP5 or the PHP module is this error:

ERROR: Module php5 does not exist!

Scratched your head enough already? Well here is a simple solution to the problem but this involves a bit of manual work to do which is very simple anyways.

PHP Logo

PHP Logo

All you need to do is create two configuration files like these:

File 1

Create a file called php.conf in your /etc/apache2/mods-available/ directory and paste the following code snippet in it and save the file:

<IfModule mod_php5.c>
  AddType application/x-httpd-php .php .phtml .php5
  AddType application/x-httpd-php-source .phps
</IfModule>

File 2

Now create another file called php.load in the same directory — /etc/apache2/mods-available/ and put the following line in the file and save it:

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

Now from command line, enter the following command and your Apache PHP installation should be back to work in no time at all:

a2enmod php && /etc/init.d/apache2 restart

Please let us know if the above solution worked for you.

?>


У меня установлен Ubuntu Server 16.04 с Webmin 1.831. Я получаю эту ошибку при попытке запустить PHP ОШИБКА: модуль php7.0 не существует

libapache2-mod-php7.0 установлен.


2

Привет, Доминик, извини, какую команду ты пытаешься выполнить? Это отсутствует в вопросе, спасибо.



Лусио


1

Я запускаю команду: a2enmod php7.0 Я пытаюсь установить ruTorrent, это требует установки Apache и PHP. Я заметил, что PHP не работает, и когда я запускаю a2enmod php7.0, чтобы проверить, работает ли PHP, я получаю сообщение об ошибке выше.



Доминик Кашеймер


Больше информации, когда я устанавливаю libapache2-mod-php7.0, я получаю эту ошибку:Setting up libapache2-mod-php7.0 (7.0.15-0ubuntu0.16.04.4) ... dpkg: error processing package libapache2-mod-php7.0 (--configure): subprocess installed post-installation script returned error exit status 1 Errors were encountered while processing: libapache2-mod-php7.0 E: Sub-process /usr/bin/dpkg returned an error code (1)



Доминик Кашеймер


1

Не могли бы вы отредактировать свое сообщение, когда хотите добавить информацию? Особенно файл или программа вывода объявлений (с помощью {}кнопки на панели инструментов редактора) будет гораздо более удобным для чтения там; в качестве альтернативы вы можете использовать сервис pastie для более длинных списков и включить ссылку своего pastie в свой вопрос. В целом, лучше иметь все необходимое в одном месте. Кроме того, комментарии могут быть удалены по разным причинам. Благодарю.



Дэвид Фёрстер


Не могли бы вы отредактировать свой вопрос, чтобы включить полный дословный вывод sudo apt-get install -f libapache2-mod-php7.0? Благодарю.



Дэвид Фёрстер,

Ответы:


sudo apt purge libapache2-mod-php7.0 libapache2-mod-php

тогда

sudo apt install libapache2-mod-php7.0 libapache2-mod-php

починил это.


1

В конце концов это было то, что сделал это для меня! В Ubuntu 18.04 вы php7.2тоже можете использовать .



Д. Дан


Я столкнулся с той же проблемой, и вот решение:

Вам необходимо установить дополнительный пакет:

sudo apt-get install libapache2-mod-php7.0

Теперь беги

sudo a2enmod php7.0

чтобы включить его

Перезагрузите сервер

sudo systemctl restart apache2.service

Понравилась статья? Поделить с друзьями:
  • Error module php5 does not exist
  • Error module not specified intellij idea
  • Error module not specified android studio
  • Error module name must be unique arena
  • Error module is not defined