Category Archives: PHP

[Solved] PHPMailer Failed to Send Email: SMTP Error: Could not connect to SMTP host.

1. First step

Open the debugging mode to view the error message

$mail->SMTPDebug = 2;

2. Add the following code to skip validation

Generally, for example, QQ mailbox and 163 mailbox will not fail to connect to the SMTP server. For example, the mail server with its own company domain name is prone to sending failure.

$mail->SMTPOptions = array(
        'ssl' => array(
            'verify_peer' => false,
            'verify_peer_name' => false,
            'allow_self_signed' => true
        )
    );

The referendum decided:

Link: https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

stack overflow: https://stackoverflow.com/questions/3477766/phpmailer-smtp-error-could-not-connect-to-smtp-host

[Solved] Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path:


Warning: Unknown: Failed to write session data using user-defined save handler. (session.save_path: D:\Software\phpstudy_pro\Extensions\tmp\tmp) in Unknown on line 0

Reasons:

1. the path of session.save_path is not correct
2. session.save_path's file permissions are not correct
3. and other reasons for the error, (but mine is not the problem) this problem sent me a day of time

My mistake:

The session that occurs when using this method_set_save_handler(‘open’,‘close’,‘read’,‘write’,‘destory’,‘gc’);

reason

	1. the read callback function must return the value of the string, if not, other errors will be reported
	2. write callback function must return true, if false will return the above error
	3. write in the insert statement of the variable value must be added to the single quotes, otherwise it can not be inserted into the database
	4. all but the read callback function must return a bool value, write must return true to insert into the database, and the others I think should also return true (not tested here)

Encounter this wrong idea

1. Check the configuration file for errors first
2. then check for errors in the return value
3. then check the sql statement for errors
4. debug with echo or var_dump at each step

If you solve the big guys’ problems, please give me a favor.

Vant configures multiple sites, and new sites 404 error [How to Solve]

1.configure the homestead.yaml file
Add folder mapping, domain name directory mapping (note the layer mapped to the entry file)

2. Configure hosts file

3. Reload vagrant (reload the modified configuration file)

vagrant provision&&vagrant reload

#After reloading the configuration, open vagrant
vagrant up && vagrant ssh

4. Restart nginx

service nginx restart

5. Successfully open the newly added site

PHP: The Difference between \Throwable, \Error and \Exception

\Throwable

It is the exception class that begins to appear in php7.0, and it is the parent class of \error \exception

\Error

Inherited \throwable to handle some internal errors of the system, such as memory overflow

\Exception

Inherited \throwable to handle error reports during program execution, or actively throw exceptions (\error can also throw exceptions)

PHP large file upload error 413: request entity too large [How to Solve]

1. Nginx configuration modification

1. Modify the Nginx.conf (/ etc/Nginx/Nginx.conf) configuration file, and add or modify the following configuration in http{}:

client_max_body_size 20m; 

2. Restart nginx

systemctl restart nginx

2. PHP configuration modification

Find the location of the php.ini file:

Method 1

Use the command whereis php; to view the php related directories, if you can't find the ini file in the listed directories, you can refer to method 2.

Method 2

php --info > a.log;
vim a.log, To view the output, you can directly search for php.ini and you will see the directory where the file is located. As the following screenshot.

1. Modify the php.ini (/etc/PHP.ini) configuration file, find the following configuration and modify it:

post_max_size = 20M  
upload_max_filesize = 20M  

2. Restart PHP FPM

systemctl restart php-fpm

[Solved] file_get_contents(): SSL operation failed with code 1

Error content
file_get_contents(): SSL operation failed with code 1.OpenSSL Error messages:\nerror:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed

This is related to the local environment. Whether SSL authentication is enabled
solution: modify the configuration or code

$stream_opts = [
    "ssl" => [
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ]
];  
 
$response = file_get_contents($url, false, stream_context_create($stream_opts));

[Solved] PHP getimagesize(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL

Today, I encountered a problem with the client application server (CentOS). When using getimagesize(), an error is always reported:

PHP getimagesize(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_ get_ server_ certificate:certificate verify failed

It is preliminarily judged that openssl.cafile in php.ini is not set. After opening the PHP configuration file, it is found that it is set. The current setting value is:

openssl.cafile=/etc/pki/tls/certs/ca-bundle.crt

After that, it was suspected that the certificate might expire. First, compare the contents of the file on your own server. If you find that the size is inconsistent, copy and paste the contents from your own server. After saving, the problem of reloading PHP configuration still exists;

Remember that similar problems have occurred on Windows systems before. At that time, curl.cainfo was configured, so from this website
: http://curl.haxx.se/ca/cacert.pem Download the certificate and put it in the /usr/local/OpenSSL/ directory to modify the configuration

[curl]
curl.cainfo = /usr/local/openssl/cacert.pem

[openssl]
openssl.cafile=/usr/local/openssl/cacert.pem

When this problem occurs on the Internet, the solutions found are also operated in this way. However, the overload configuration problem remains after saving. Change the configuration back again.

Finally, see this article on: https://stackoverflow.com/questions/17084886/ssl-error-routinesssl3-get-server-certificatecertificate-verify-failed

It is found that the Linux system has the command to update the local certificate. The commands are different for different systems. The CentOS operation is as follows:

#Install ca certificate tool
yum install ca-certificates -y

# Update Certificate
update-ca-trust

Problem-solving.

[WordPress Error] Fatal error undefined function is_network_admin()

Fatal error undefined function is_network_admin()

Problem Description:

When you upgrade WordPress, a fatal error undefined function is displayed when you try to log in_network_Admin() fatal error.

Solution: upgrade manually

This error is caused by the WordPress upgrade failure. Try upgrading manually.

1. Download the latest WordPress package and unzip it.

2. Back up your current WordPress.

3. Rename the WP includes and WP admin directories to WP includes.bak and wp-admin.bak.

4. Upload WP includes and WP admin directories to the server via FTP.

5. Upload the contents of the new WP content directory to the corresponding location on the server.

6. Upload other files to the WordPress root directory.

7. Delete the. Maintenance file through FTP.

8. Log in to WordPress again and you will see a link like http://your domain name/WordPress/WP admin/upgrade.php. Follow the instructions.

9. Empty the cache and see if you have taken effect.

[Solved] PHP -v Error: error while loading shared libraries: libonig.so.5:cannot open share directory

When upgrading from PHP 5.6 to PHP 7.4, you can directly replace the compiled installation package. When you enter PHP – V, you will report an error while loading shared libraries: libonig. So. 5: cannot open share directory

#php -v
#php: error while loading shared libraries: libonig.so.5:cannot open share directory

Solution:

Step 1

Modify /ect/ld.so.conf     Add the following line

#vim /etc/ld.so.conf
include ls.so.conf.d/*.conf
/usr/local/lib
/usr/local/x264/lib
/usr/local/openssl/lib
/usr/local/python3.7.1/lib

After saving   Execute ldconfig

#ldconfig

Step 2:

Install oniguruma library

Download Link:

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-devel-6.8.2-1.el7.x86_64.rpm

https://download-ib01.fedoraproject.org/pub/epel/7/x86_64/Packages/o/oniguruma-6.8.2-1.el7.x86_64.rpm

oniguruma-6.8.2-1.el7.x86 64.rpm

oniguruma-devel-6.8.2-1.el7.x86 64.rpm

Use the follow commands to install:

#rpm -ivh oniguruma-devel-6.8.2-1.el7.x86_64
#rpm -ivh oniguruma-6.8.2-1.el7.x86_64

Then run the command PHP – V     Perfect display

If installation error

Generating autotools files.
./autogen.sh: line 6: autoreconf: command not found

Solution:

[[email protected] oniguruma-6.9.4]# yum install autoconf automake libtool

[Solved] PHP installation Phalcon expansion error

sudo apt-get install php7.1-phalcon
sudo: unable to resolve host official
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package php7.1-phalcon
E: Couldn’t find any package by glob ‘php7.1-phalcon’
E: Couldn’t find any package by regex ‘php7.1-phalcon’ 

Solution:
sudo apt-get install curl
curl -s https://packagecloud.io/install/repositories/phalcon/stable/script.deb.sh | sudo bash
sudo apt-get install php7.1-phalcon

[Solved] Fatal error: Uncaught Error: Class ‘Imagick‘ not found

Resolve fatal error: uncaught error: class’ imageick ‘not found

reason

PHP requires the imageick extension to be installed

environment

CentOS Linux release 7.9
PHP 7.3.26

Installation steps

Download the appropriate ImageMagick program and ImageMagick extension according to the environment

Installing imagemagic

wget http://www.imagemagick.org/download/ImageMagick.tar.gz

tar zxvf ImageMagick.tar.gz 
cd ImageMagick-7.1.0-8/
./configure --prefix=/usr/local/webservice/imagemagick
make && make install

Check whether the installation is successful

/usr/local/webservice/imagemagick/bin/convert -version

Version: ImageMagick 7.1.0-8 Q16-HDRI x86_64 2021-09-18 https://imagemagick.org
Copyright: (C) 1999-2021 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI OpenMP(3.1) 
Delegates (built-in): fontconfig freetype jng jpeg lzma png x xml zlib
Compiler: gcc (4.8)

Installing the PHP extension: imagick

Download address

https://pecl.php.net/package/imagick
View the appropriate version download

 wget https://pecl.php.net/get/imagick-3.5.1.tgz
 tar zxvf imagick-3.5.1.tgz

cd imagick-3.5.1/
/usr/local/webservice/php73/bin/phpize
./configure --with-php-config=/usr/local/webservice/php73/bin/php-config --with-imagick=/usr/local/webservice/imagemagick
make && make install

Successful installation is displayed

Build complete.
Don't forget to run 'make test'.

Installing shared extensions:     /usr/local/webservice/php73/lib/php/extensions/no-debug-zts-20180731/
Installing header files:          /usr/local/webservice/php73/include/php/

Modify the configuration file and write extension=imagick.so

Add
extension=/usr/local/webservice/php73/lib/php/extensions/no-debug-zts-20180731/imagick.so at the end of vim /usr/local/webservice/php73/etc/php.ini

Restart php-fpm and test whether the installation is successful
systemctl restart php-fpm

php -m | grep imagick