252

I'm trying a simple web service example and I get this error even though I uncommented extension=php_soap.dll in the php.ini file:

Fatal error: Class 'SoapClient' not found in C:\Program Files (x86)\EasyPHP-5.3.9\www\server.php on line 2

dodov
  • 5,206
  • 3
  • 34
  • 65
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108

15 Answers15

412

Diagnose

Look up the following inside your script file

phpinfo();

If you can't find Soap Client set to enabled like so: the way soap should appear in phpinfo()

Fix

Do the following:

  1. Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini
  2. Remove the ; from the beginning of extension=php_soap.dll
  3. Restart your Apache server
  4. Look up your phpinfo(); again and check if you see a similar picture to the one above
  5. If you do, problem solved!

On the other hand if this doesn't solve your issue, you may want to check the requirements for SOAP here. Also in the comment section you can find good advice on connecting to https.

Morgan Wilde
  • 16,795
  • 10
  • 53
  • 99
  • 15
    Don't forget to also uncomment this line: `;extension=php_openssl.dll` if the WSDL you are trying to reach is under https protocol – juliangonzalez Jan 08 '15 at 17:22
  • in my case it was not installed and there is no extension=php_soap.dll in the php.in um using php5.6 centos6.9 – zero8 Sep 29 '17 at 06:56
  • 12
    I am using xamp and just uncommenting `extension=soap` do the trick. – SAMPro Jan 10 '18 at 20:43
  • 4
    sudo apt-get install php7.0-soap for those of you who haven't installed it yet – FoxMcCloud Jul 12 '18 at 15:08
  • php -i | grep Soap using the the command line on linux systems. – chris Nov 16 '18 at 08:48
  • If it doesn't work maybe you need install soap first : sudo apt install php5.6-soap . Then restart apache – Zvezdochka May 12 '19 at 19:54
  • 2
    For me, The `SoapClient` class is still not found. I see it enabled in the phpinfo(), the extension is enabled, openssl is enabled too, everything is ok but the class isn't found. I use Wampserver 3.0 and PHP 5.6 and I restarted Apache but doesn't solve the problem. Please help. – Eve Sep 06 '19 at 12:43
  • I am using xampp. I did not have `extension=php_soap.dll` in my file. I just added this line of text and it worked. – Vanity Slug - codidact.com Sep 12 '19 at 01:25
  • How I can enable in shared server? – Md. Shariful Islam Sep 12 '19 at 04:51
  • I restarted `my computer` for set variable! – Mostafa Norzade Aug 17 '20 at 08:30
  • 2
    If I follow the above comment (`apt-get install php7.0-soap`) on Ubuntu 20.04.01, I get this error: Unable to locate package php7.0-soap. Running `apt-get install php-soap` fixes the issue and installs the appropriate soap version for this OS (7.4 in my case). – jbobbins Sep 21 '20 at 22:30
181

To install SOAP in PHP-7 run following in your Ubuntu terminal:

sudo apt-get install php7.0-soap

To install SOAP in PHP-7.1 run following in your Ubuntu terminal:

sudo apt-get install php7.1-soap

To install SOAP in PHP-7.2 run following in your Ubuntu terminal:

sudo apt-get install php7.2-soap

To install SOAP in PHP-7.3 run following in your Ubuntu terminal:

sudo apt-get install php7.3-soap
mhellmeier
  • 1,982
  • 1
  • 22
  • 35
Nahid
  • 2,911
  • 1
  • 20
  • 17
21

For AWS (RHEL):

sudo yum install php56-soap

(56 here is 5.6 PHP version - put your version here).

OZ_
  • 12,492
  • 7
  • 50
  • 68
18

To install SOAP in PHP5.6 run following in your Ubuntu 14.04 terminal:

sudo apt-get install php5.6-soap
service php5.6-fpm restart
service apache2 restart

See if SOAP was enabled:

php -m

(You should see SOAP between returned text.)

Jasom Dotnet
  • 1,225
  • 12
  • 17
11

I had to run

php-config --configure-options --enable-soap 

as root and restart apache.

That worked! Now my phpinfo() call shows the SOAP section.

9

I solved this issue on PHP 7.0.22-0ubuntu0.16.04.1 nginx

sudo apt-get install php7.0-soap

sudo systemctl restart php7.0-fpm
sudo systemctl restart nginx
Nanhe Kumar
  • 15,498
  • 5
  • 79
  • 71
9

For XAMPP users, open php.ini file located in C:/xampp/php and remove the ; from the beginning of extension=soap. Then restart Apache and that's it!

Jakub Adamec
  • 953
  • 16
  • 22
8

I couln't find the SOAP section in phpinfo() so I had to install it.

For information the SOAP extension requires the libxml PHP extension. This means that passing in --enable-libxml is also required according to http://php.net/manual/en/soap.requirements.php

From WHM panel

  1. Software » Module Installers » PHP Extensions & Applications Package
  2. Install SOAP 0.13.0

    WARNING: "pear/HTTP_Request" is deprecated in favor of "pear/HTTP_Request2"

    install ok: channel://pear.php.net/SOAP-0.13.0

  3. Install HTTP_Request2 (optional)

    install ok: channel://pear.php.net/HTTP_Request2

  4. Restart Services » HTTP Server (Apache)

From shell command

1.pear install SOAP

2.reboot

RafaSashi
  • 16,483
  • 8
  • 84
  • 94
  • WHM's EasyApache interface also has an option for enabling Soap in the Exhaustive Options list. – Andrew Aug 30 '15 at 23:53
6

For Docker* add this line:

RUN apt-get update && \
    apt-get install -y libxml2-dev && \
    docker-php-ext-install soap

*: For debian based images, ie. won't work for alpine variants.

Attila Fulop
  • 6,861
  • 2
  • 44
  • 50
4

For PHP 7.4 & Docker add this line in Dockerfile:

RUN apt-get update && apt-get install -y \
libxml2-dev \

RUN docker-php-ext-install soap

Rebuild the image and restart ;)

1

On Centos 7.8 and PHP 7.3

yum install php-soap
service httpd restart
PJunior
  • 2,649
  • 1
  • 33
  • 29
0

You have to inherit nusoap.php class and put it in your project directory, you can download it from the Internet.

Use this code:

require_once('nusoap.php');
Morgan Wilde
  • 16,795
  • 10
  • 53
  • 99
Wondie
  • 65
  • 1
0

For PHP 8:

sudo apt update
sudo apt-get install php8.0-soap
shikata
  • 95
  • 1
  • 11
0

In my case, the Symfony cache was causing the problem, after running composer install the problem was gone.

sh6210
  • 4,190
  • 1
  • 37
  • 27
0

I had a similar problem. It was due to the scope and solved by replacing new SoapClient by new \SoapClient.

M Shafaei N
  • 409
  • 3
  • 6