Category Archives: PHP

PHP php-config is not installed error in ubuntu 16 [How to Solve]

Environment

Ubuntu 16.04.1 LTSPHP 7.0.33

Question

When compiling and installing php extensions with php config, it is found that php-config does not exist.

Check whether php-config exists or not?

$ whereis php-config
php-config:

As above, it returns null, indicating that it does not exist.

Solution:

This problem occurs because the php-dev package is not installed. You can install it once.

Install php-dev

$ apt-get install php-dev

If php5 is version, run apt-get install php5-dev.

re-check php-config

$ whereis php-config
php-config: /usr/bin/php-config /usr/bin/php-config7.0 /usr/share/man/man1/php-config.1.gz

As shown above, the installation is successful.

[Solved] PHP Error: Warning: file_get_contents(): Failed to enable crypto

I. Description
file_get_contents() error when reading https content

II. Reason
Local service is not configured ssl certificate, can not get the contents of the path to https

III. Solution
1, Linux server configuration https ssl certificate.
Linux server configuration https ssl certificate.
2. curl_ request to obtain the content (see the following method curlGet ())

    /**
     * get the content
     * @param $url
     * @return bool|string
     */
    function curlGet($url)
    {
        $ch = curl_init($url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36');
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        $content = curl_exec($ch);
        curl_close($ch);
        return ($content);
    }

3.Use file_get_contents() function to skip https authentication

        $streamOpts = [
            'ssl' => [
                'verify_peer' => false,
                'verify_peer_name' => false
            ]
        ];
        $html = file_get_contents($pageUrl, false, stream_context_create($streamOpts));

[Solved] Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60

Guzzle

Error prompt

If an error occurs as follows:

Fatal error: Uncaught GuzzleHttp\Exception\RequestException: cURL error 60: SSL certificate problem: unable to get local issuer certificate (see https://curl.haxx.se/libcurl/… in xxx.php

The reason is that the local CURL SSL certificate is too old to recognize.

Solution:

  • Download an up-to-date certificate from http://curl.haxx.se/ca/cacert… Then save it to an arbitrary directory.
  • Then put catr.pem in the bin directory of php and edit php.ini, open the php.ini file with notepad or notepad++, about line 1932.
  • Remove the comment “;” in front of curl.cainfo, then write the full path and file name of the cacert.pem certificate at the end, mine is as follows

Finally, restart the wamp.

Mac: make: *** [Zend/zend_language_parser.lo] Error 1

Error reporting content:

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1317:5: error: implicit declaration of function 'yystpcpy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

                                yystpcpy(yyres, "end of file");

                                ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1317:5: note: did you mean 'stpcpy'?

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:130:7: note: 'stpcpy' declared here

char    *stpcpy(char *__dst, const char *__src);

         ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1324:29: error: implicit declaration of function 'yystrlen' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

                yystr_len = (unsigned int)yystrlen(yystr);

                                          ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1324:29: note: did you mean 'strlen'?

/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/string.h:82:9: note: 'strlen' declared here

size_t   strlen(const char *__s);

         ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1345:4: error: implicit declaration of function 'yystpcpy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

                        yystpcpy(yyres, buffer);

                        ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1352:10: error: implicit declaration of function 'yystrlen' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

                return yystrlen(yystr) - (*yystr == '"' ?2 : 0);

                       ^

/Users/dre0m1/CTF/Study_notes/PHP_source_code/php-src/Zend/zend_language_parser.y:1365:2: error: implicit declaration of function 'yystpcpy' is invalid in C99 [-Werror,-Wimplicit-function-declaration]

        yystpcpy(yyres, yystr);

        ^

5 errors generated.

make: *** [Zend/zend_language_parser.lo] Error 1

Implicit declaration of function ‘yystpcpy’ is invalid in C99. Looking up information on the Internet, we can find that this error type is related to the header file or the previous define. From the prompts in the error report, we can see that the function yystpcpy is missing.

Access the file php-src/Zend/zend_language_parser.c. You can see this code below:

Add the definitions of yystpcpy and yystrlen to it, guess that their original functions should be stpcpy and strlen functions: re-make after modification, and compile successfully.

[Solved] tp6.0 open_basedir Error: Warning: require(): open_basedir restriction in effect.

Error message

Warning: require(): open_basedir restriction in effect. File(/work/tp6/vendor/autoload.php) is not within the allowed path(s): (/work/tp6/public/:/tmp/) in /work/tp6/public/index.php on line 15

Warning: require(/work/tp6/vendor/autoload.php): failed to open stream: Operation not permitted in /work/tp6/public/index.php on line 15

Fatal error: require(): Failed opening required '/work/tp6/public/../vendor/autoload.php' (include_path='.:') in /work/tp6/public/index.php on line 15

 

Check the problem description and data, and find that it is the problem of PHP open_basedir  configuration is that PHP cannot import the files above the authorized directory;

In general, this problem will not occur. The reason for this problem is mostly due to the server. This restriction is made for security!

If the entry file of is switched to public, the following file should be modified to remove public

Solution:

HTML + PHP inline execute JavaScript Error [How to Solve]

Error message

read.php:1 Refused to run the JavaScript URL because it violates the following Content Security Policy directive: “script-src ‘self’”. Either the ‘unsafe-inline’ keyword, a hash (‘sha256-…’), or a nonce (‘nonce-…’) is required to enable inline execution. Note that hashes do not apply to event handlers, style attributes and javascript: navigations unless the ‘unsafe-hashes’ keyword is present.

 

Solution:

Add unsafe-inline in the header

header("Content-Security-Policy: script-src 'self' 'unsafe-inline';);

[Solved] Centos7 xmapp Install Error: error while loading shared libraries: libc.so.6

1. Version information:

CentOS version: CentOS release 6.9 (final)

xmapp version: xampp-linux-x64-5.6.40-1-installer.run

2. Error message:

[root@localhost ~]# /opt/lampp/lampp
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/bin/bash: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

id: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/share/xampp/xampplib: line 11: test: -ne: unary operator expected
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
XAMPP: egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
netstat: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
netstat: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/httpd: error while loading shared libraries: librt.so.1: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
XAMPP: hostname: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
netstat: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
XAMPP: /bin/sh: error while loading shared libraries: libdl.so.2: cannot open shared object file: No such file or directory
egrep: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
netstat: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory
/opt/lampp/bin/gettext: error while loading shared libraries: libc.so.6: cannot open shared object file: No such file or directory

3. Solution:

1. Open /opt/lampp/lampp

vim /opt/lampp/lampp

2. Edit
Modify this line

export LD_ASSUME_KERNEL=2.2.5

to

export LD_ASSUME_KERNEL=2.8.0

Find a word in the file [under the command line/keyword, enter to find, enter n to find the next]

How to Solve phpExcel Error: ERR_INVALID_RESPONSE

1. Occurrence scenario

  1. In thinkphp framework using phpoffice/phpexcel, exporting Excel tables directly to the browser for download, the error is reported: ERR_INVALID_RESPONSE
  2. Note: The export is fine in the local windows environment, but the problem only occurs in the online Linux environment.
  3. Screenshot of the problem.

2. Find a solution

1. Online solutions

1) Buffer problem

calling ob_clean() before calling save(“ php://output "), part of the code is as follows:

        ob_clean(); //Emptying the cache

        // final output via browser
        $fn = "The name of the file (" . date("Y.m.d") . ").xls"; // the name of the file to be saved
        header('Content-Type: application/vnd.ms-excel; charset=utf-8');
        header("Content-Disposition: attachment;filename={$fn}");
        header('Cache-Control: max-age=0');
        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
        $objWriter->save('php://output');
        exit;

2) Error is reported in line 581 of factory581, and break is deleted

Error in factory581 line, delete break;

PHPExcel\Calculation\Functions.php file, remove break at line 581

our phoffice/phpexcel is installed by composer. We have to change the source code every time we update it. It is not recommended to modify the source code. Even if it can solve the problem, it will not be adopted

2. My solution to this problem is to install the zip extension under Linux

[solution] my problem is that Linux lacks the zip extension. You can install it~

3. Zip extension

PHP under windows (my version is 7.3.3) has its own zip extension, and there is no directory_zip.dll file under the php/ext path, as shown in the figure

PHP under Linux does not have zip extension installed

/www/server/php/56/sbin/php-fpm:error while loading shared libraries:libssl.so.1.0. 0:cannot open shared object file:No such file or directory

When opening PHP, you need to use libssl.so.1.0.0 or libcrypto.so.1.0.0 but since most of them do not have the 1.0.0 version, I solved it based on the link, taking libcrypto.so.1.0.0 as an example

1. First check what versions of libcrypto.so are in the current system files

ll /usr/lib64/libcrypto.so.*

2. It is true that there is no such thing libcrypto.so.1.0.0, but there is this/usr/lib64/libcrypto.so.1.0.2k,so you can create the connection

sudo ln -s /usr/lib64/libcrypto.so.1.0.2k /usr/lib64/libcrypto.so.1.0.0

[Solved] Laravel admin Error: Symfony\Component\Debug\Exception\FatalThrowableError : Class ‘Doctrine\DBAL\Driver\PDOMySql\Driver’ not found

laravel-admin error

Error reporting information

An error occurs when running PHP artisan admin:make:

symfony\component\debug\exception\fatalthrowableerror: class'doc\dbal\driver\pdomysql\driver'not found

Operating environment

Windows 10
php:7.3.4
mysql:5.7.26
laravel:5.8
laravel admin:1.8.17

Cause

Doctrine/dbal not found

The reason why I read other people online may be that doctrine/dbal is 3* Caused by the version of.

Solutions

Run at terminal:

composer require doctrine/dbal:2.12.1

Or modify the composer.json as the following:

    "require": {
    	*
    	*
        "doctrine/dbal": "^2.12.1",
        *
        *
    },

Then run

composer update

[Solved] OpenSSL Error messages: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

In these two days, the service has been reporting when calling Baidu’s addressing and positioning interface and reverse address resolution:

file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

The query results of the interface are affected, and finally the curl call problem is solved:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_FAILONERROR, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
$reponse = curl_exec($ch);

CURLOPT_SSLVERSION Fetch value and meaning
CURL_SSLVERSION_TLSv1_2 requires php version >= 5.5.19
TLS 1.1 and TLS 1.2 are supported since OpenSSL 1.0.1

CURL_SSLVERSION_DEFAULT (0)
CURL_SSLVERSION_TLSv1 (1),
CURL_SSLVERSION_SSLv2 (2), 
CURL_SSLVERSION_SSLv3 (3),
CURL_SSLVERSION_TLSv1_0 (4),
CURL_SSLVERSION_TLSv1_1 (5),
CURL_SSLVERSION_TLSv1_2 (6).

[Solved] Model Error: must return a relationship instance

Model Error: must return a relationship instance

There is a method in the model as follows:

public function adjustbills()
    {
        if($this->user_combined == '1'){
            $invoiceNumberArr = ['xxx'];
            return Adjustbill::whereIn('invoice_number',$invoiceNumberArr)->where('user_id', $this->user_id);
        }else{
            return $this->hasMany(Adjustbill::class, 'invoice_number', 'invoice_number')->where('user_id', $this->user_id);
        }
    }

When the calling method is model -> When adjustbills,

  1. If it goes to the following judgment, no error will be reported
  2. If it goes to the above judgment, it will report an error must return a relationship instance, because laravel uses the following hasMany relationship by default, if not, it will report an error.

Solution:

  1. Find a way to modify the above logic to the following way of relationship
  2. Called as :model->adjustbills->get()