Category Archives: PHP

[Solved] PDOException::(“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long;

php artisan migrate Run Error:
PDOException:: (“SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 1000 bytes”)

Solution:
Add the following codes in the file of app/Providers/AppSeviceProvider.php:
use Illuminate\Support\Facades\Schema;
Add in the method of foot:
Schema::defaultStringLength(191);

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
		Schema::defaultStringLength(191);
    }
}

After the prompt
pdoexception:: (“sqlstate [42s01]: base table or view already exists: 1050 table ‘users’ already exists”)
, delete the user table and re-run PHP artist migrate

[Solved] PostgreSQL configure: error: readline library not found

preface

An error occurs when installing PostgreSQL, as shown below

configure: error: readline library not found
If you have readline already installed, see config.log for details on the
failure.  It is possible the compiler isn't looking in the proper directory.
Use --without-readline to disable readline support.

Solution:

Check whether the readLine package is installed in the system

rpm -qa | grep readline

Install readline-devel pack

yum -y install -y readline-devel

Execute configure again successfully

The explanation of readLine comes from the official website

--without-readline
Prevents use of the Readline library (and libedit as well). Thisoption disables command-line
editing and history in psql, so it is notrecommended.

Note: when you execute configure, you can add “– without readLine” to avoid this error, but PostgreSQL officials do not recommend it

[Solved] ‘node’ command failed to start the project, with an error: “unknown database’ mydb ‘”

[error]
node the command failed to start the project and reported an error: “unknown database ‘mydb'”

[other features]
at this time, view phpstudy and display “port occupied”.

[solution]
Start Run CMD, enter netstat - ano , look at the first column, followed by the port, find 3306, and remember the corresponding PID

Then open the task manager to view -> Select column -> Tick PID (process identifier) -> determine

Find the PID process in the task manager, check what program occupies the port, and close it

If you restart MySQL again, you will not report the error that the port is occupied. ⑤ use postman to test whether the background project interface is normal

[Solved] cURL error 60: SSL certificate problem: unable to get local issuer certificate

When the PHP server curl is based on the HTTPS protocol API, this problem will be reported if the environment does not handle it:

cURL error 60: SSL certificate problem: unable to get local issuer certificate

Solution:
(1) download the file used to support HTTPS

(2) Place the file in a location, such as “C:\env\cacert.PEM”

(3) Modify php.ini and add support for cacert.pem

[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));