Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Class 'SimpleXMLElement' not found

I am trying to use digital ocean spaces in my php7 laravel project. The code is pretty simple to just load a file and copy it to the directory. Everything works on my local machine but fails on my digital ocean server with this error

Class 'SimpleXMLElement' not found

Even on digital ocean server, if I use tinker to run the same storage commands, it works fine. What can be the issue?

My get_loaded_extensions() returns get_loaded_extensions()

[
     "Core",
     "date",
     "libxml",
     "openssl",
     "pcre",
     "zlib",
     "filter",
     "hash",
     "pcntl",
     "Reflection",
     "SPL",
     "session",
     "standard",
     "mysqlnd",
     "PDO",
     "xml",
     "apcu",
     "calendar",
     "ctype",
     "curl",
     "dom",
     "mbstring",
     "fileinfo",
     "ftp",
     "gd",
     "gettext",
     "iconv",
     "json",
     "exif",
     "mysqli",
     "pdo_mysql",
     "Phar",
     "posix",
     "readline",
     "shmop",
     "SimpleXML",
     "sockets",
     "sysvmsg",
     "sysvsem",
     "sysvshm",
     "tokenizer",
     "wddx",
     "xmlreader",
     "xmlrpc",
     "xmlwriter",
     "xsl",
     "zip",
     "Zend OPcache",
   ]

so it looks like xml and simplexml are installed. As suggested by the link, php-xml and php-simplexml should be installed. Do I need to install something separately?

Also, my file upload code looks like this

public function uploadNew($file, $title, User $user)
    {
        if (!File::directoryExists($user->username)) {
            Storage::makeDirectory($user->username);
        }
        $completeFileName = $user->username.'/'.$title.time();
        Storage::put($completeFileName, file_get_contents($file), 'public');
        $this->url = File::baseUrl().$completeFileName;
        $this->title = $title;
        $this->user_id = $user->id;
        $this->save();
        return $this;
    }

    public static function baseUrl()
    {
        return 'https://'.env('DO_SPACES_BUCKET').'.nyc3.digitaloceanspaces.com/';
    }

    public static function directoryExists($directory)
    {
        $existingDirs = Storage::directories();
        return in_array($directory, $existingDirs);
    }

Adding the stack trace of exception:

(1/1) FatalThrowableError
Class 'SimpleXMLElement' not found
in PayloadParserTrait.php (line 39)
at RestXmlParser->parseXml(object(Stream))
in RestXmlParser.php (line 33)
at RestXmlParser->payload(object(Response), object(StructureShape), array())
in AbstractRestParser.php (line 62)
at AbstractRestParser->__invoke(object(Command), object(Response))
in RetryableMalformedResponseParser.php (line 37)
at RetryableMalformedResponseParser->__invoke(object(Command), object(Response))
in AmbiguousSuccessParser.php (line 58)
at AmbiguousSuccessParser->__invoke(object(Command), object(Response))
in GetBucketLocationParser.php (line 30)
at GetBucketLocationParser->__invoke(object(Command), object(Response))
in WrappedHttpHandler.php (line 126)
at WrappedHttpHandler->parseResponse(object(Command), object(Request), object(Response), array())
in WrappedHttpHandler.php (line 93)
at WrappedHttpHandler->Aws\{closure}(object(Response))
in Promise.php (line 203)
like image 981
AmrataB Avatar asked Oct 06 '17 16:10

AmrataB


2 Answers

check the version of installed php using:-

$ php -v

If it's version 7, then install php7.0-xml

if it's version 7.2.*, then use php7.2-xml package on your machine along with php.

like image 163
nandal Avatar answered Oct 07 '22 03:10

nandal


Just install php-xml package.For reference, just install all the additional php libraries:

apt-get install php-pear php7.2-curl php7.2-dev php7.2-gd php7.2-mbstring php7.2-zip php7.2-mysql php7.2-xml

like image 28
max johnson Avatar answered Oct 07 '22 02:10

max johnson