2

I've just made the transition to Ubuntu from Windows, and I've set up a fresh install of nginx, mysql, php7.0-fpm (including the Opcache/ApcCache) and cloned a project from git (Yii2 project).

This repository worked on windows, but it now seems some of the built-in functions are no longer working. I've checked the docs, and it does not seem like any of the functions are deprecated.

This is the errors i've found so far, code-snippets and their corresponding error messages:

curl_init()

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->getSlackPayloadUrl());
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($ch);
curl_close($ch);

Call to undefined function backend\components\curl_init()

utf8_encode()

$data = 'payload=' . json_encode(array_map("utf8_encode", [
            'channel'       =>  $channel,
            'text'          =>  $message,
        ]));

array_map() expects parameter 1 to be a valid callback, function 'utf8_encode' not found or invalid function name

And for thoroughness, the nginx config:

nginx config

server {
    charset utf-8;
    client_max_body_size 128M;

    listen 80; ## listen for ipv4
    #listen [::]:80 default_server ipv6only=on; ## listen for ipv6

    server_name project.dev;
    root        /var/www/project/backend/web;
    index       index.php;

    access_log  /var/www/project/log/access.log;
    error_log   /var/www/project/log/error.log;

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
    }

    location ~ ^/assets/.*\.php$ {
        deny all;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_pass unix:/run/php/php7.0-fpm.sock;
        try_files $uri =404;
    }

    location ~* /\. {
        deny all;
    }
}

If there is any other information that is relevant, add a comment and I'll update.

Jørgen
  • 2,827
  • 5
  • 26
  • 45

2 Answers2

4

As per our discussion discussion , below solution comes:-

1.Need to install CURL on your system by the command :-

sudo apt-get install php7.0-curl

2.Regarding second error i got this link:- utf8_(en|de)code removed from php7?

It states that utf8_encode/decode is function related to php xml extension which you have to install your system by below command:-

sudo apt-get install php7.0-xml

Important Note:- after install of these library packages restart your server so that changes will reflect. Thanks.

Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
2

utf8_encode() is a function under the php xml extension, and curl of-course under the curl extension.

Solved by

sudo apt-get install php7.0-curl

and

sudo apt-get install php7.0-xml
Serving Quarantine period
  • 66,345
  • 10
  • 43
  • 85
Jørgen
  • 2,827
  • 5
  • 26
  • 45