简体   繁体   中英

PHP Fatal error: Uncaught Error: Class 'SoapClient' not found

I am trying to enable SoapClient on my Ubuntu 18.04.1 LTS VirtualBox server.
After seeing that my Soap application is failing with 500 HTTP error, I referred to my php error log and found the below lines:

>PHP Warning:  PHP Startup: Unable to load dynamic library '/usr/lib/php/20151012/php_soap.dll' - /usr/lib/php/20151012/php_soap.dll: cannot open shared object file: No such file or directory in Unknown on line 0 

>[Sat Jan 19 10:00:46.349246 2019] [:error] [pid 4211] [client 192.168.2.52:55730] PHP Fatal error:  Uncaught Error: Class 'SoapClient' not found in /var/www/html/sample.php:36\nStack trace:\n#0 {main}\n  thrown in /var/www/html/sample.php on line 36

I have already tried to follow this and several others already, here is what I noticed:

In phpinfo(); my system uses php7.0, however, there is no php7.0-soap package

 $ sudo apt-get install php7.0-soap  
Reading package lists... Done  
Building dependency tree  
Reading state information... Done  
E: Unable to locate package php7.0-soap  
E: Couldn't find any package by glob 'php7.0-soap'  
E: Couldn't find any package by regex 'php7.0-soap'  

Therefore, instead I have installed php7.2-soap.
What am I doing wrong? Please help!

first make sure you have php 7 installed and type and run sudo apt list php7* else you can run sudo apt list php*

your result should be like this :

php7.1-mapi/bionic,bionic 8.5.5-0ubuntu1 all
php7.2/bionic-updates,bionic-updates,bionic-security,bionic-security,now 7.2.10-0ubuntu0.18.04.1 all [installed,automatic]
php7.2-bcmath/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-bz2/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-cgi/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-cli/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-common/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed]
php7.2-curl/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-dba/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-dev/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-enchant/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-fpm/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-gd/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-gmp/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-imap/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-interbase/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-intl/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-json/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-ldap/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-mbstring/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-mysql/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-odbc/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-opcache/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-pgsql/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-phpdbg/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-pspell/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-readline/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-recode/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-snmp/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-soap/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-sqlite3/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-sybase/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-tidy/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-xml/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]
php7.2-xmlrpc/bionic-updates,bionic-security 7.2.10-0ubuntu0.18.04.1 amd64
php7.2-xsl/bionic-updates,bionic-updates,bionic-security,bionic-security 7.2.10-0ubuntu0.18.04.1 all
php7.2-zip/bionic-updates,bionic-security,now 7.2.10-0ubuntu0.18.04.1 amd64 [installed,automatic]

this will show you all php7 packages.then find your soap package and install it. in my case the package is php7.2-soap so i will install it with

sudo apt install php7.2-soap

Ok, after a lot of trials and research, here is how I resolved it:

sudo a2dismod php7.0
sudo a2enmod php7.2
sudo systemctl restart apache2

Basically, the issue was that my system had two valid versions of PHP and it was configured to use the old one, by these commands you dismod PHP7.0 (disable module) and enmod PHP7.2

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM