How to enable php-soap Client on Ubuntu 22.4.0 Server

Introduction

Steps to Enable SOAP Client on Ubuntu



1- Update the System

sudo apt update

2- Install the PHP SOAP Extension

php -v
sudo apt install php7.4-soap

PHP 8.1:

sudo apt install php8.1-soap

For PHP 8.3:

sudo apt install php8.3-soap

3. Restart Your Web Server

For Apache:

sudo systemctl restart apache2

For Nginx with PHP-FPM:

sudo systemctl restart php7.4-fpm  # Replace with your PHP version
sudo systemctl restart nginx

4. Verify SOAP is Enabled

To confirm that SOAP is successfully enabled, create a phpinfo.php file in your web server’s document root.

  1. Create a file named phpinfo.php:
sudo nano /var/www/html/phpinfo.php
  1. Add the following content:
<?php
phpinfo();
?>
  • Save the file and exit (Ctrl + X, then Y, then Enter).
  • Visit the file in your browser (e.g., http://your-server-ip/phpinfo.php).
  • Look for the “SOAP” section in the output. If you see it, that means the SOAP extension is enabled.

5. Remove the phpinfo.php File

For security reasons, remove the phpinfo.php file after checking the information.
sudo rm /var/www/html/phpinfo.php

6. Optional: Install the SoapClient class for CLI (Command Line)

sudo apt install php7.4-cli php7.4-soap
sudo apt install php8.0-cli php8.0-soap

7. Test the SOAP Client

<?php
try {
    $client = new SoapClient("http://www.dneonline.com/calculator.asmx?WSDL");
    $result = $client->Add(array('intA' => 1, 'intB' => 2));
    echo "Result: " . $result->AddResult;
} catch (SoapFault $e) {
    echo "Error: " . $e->getMessage();
}
?>



Read Also

How to Set Up Nginx with Certbot for HTTPS on Your WordPress Website

How to Install WordPress with Nginx on Ubuntu 22.0.4



Previous Post
Next Post