When preparing to deploy Laravel to a production environment, the following issues arise. You will have few problems locally, but many problems online. We have sorted out some problems and bugs that we hope you can use when you deploy laravel project. No problems with the deployment, that would be great.
First of all, when we do debugging again, please first enable PHP display error, so that we can do debugging
Vim/usr/local/PHP/etc/PHP ini modify display_errors = Off to display_errors = OnCopy the code
Remember to restart the server after the change.
1 The directory permission is incorrect
To run Laravel, we need to configure permissions for some project directories.
The Laravel project needs to grant read and write permissions to the directories storage/, bootstrap/cache, and public /
Chmod -r 777 bootstrap/ chmod -r 777 storage/ chmod -r 777 public/Copy the code
If you are using the LNMP one-click installation package, please note that the LNMP one-click installation package contains.user.ini and the permissions will be denied.
To use:
Chattr -i /{directory}/.user.ini and delete:
rm .user.ini
2 Nginx configuration file problem
Suppose your nginx. Conf file path is here: / usr/local/nginx/conf/nginx. Conf file, find server {} in the field
The following code
#include enable-php.conf; This file does not exist in your nginx, please comment, because this will cause error 500. The reason is:
Introduction of PHP configuration in which the try_files statement is reported as an error when opened.
Location / {try_files $uri $uri/ /index.php? $query_string; ${# try_files $uri /index.php =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; Sock is not 127.0.0.. 1 fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; }Copy the code
Attachment: Nginx configuration for a Laravel
server { listen 80; Server_name Web domain name; index index.php index.html index.htm default.html default.htm default.php; root /var/www/html/act/public; #include rewrite/none.conf; #error_page 404 /404.html; # Deny access to PHP files in specific directory #location ~ /(wp-content|uploads|wp-includes|images)/.*\.php$ { deny all; } #include enable-php-pathinfo.conf; Location / {try_files $uri $uri/ /index.php? $query_string; } error_page 404 /404.html; location = /40x.html { } error_page 500 502 503 504 /50x.html; location = /50x.html { } location ~ \.php$ { root /var/www/html/act/public; Fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } # if (! -e $request_filename){ # rewrite ^/(mo_bile|admin|physician|home|seller)/(.*)$ /$1/index.php? $2; # } location ~ \.php$ { fastcgi_param PATH_INFO $request_uri; } access_log /home/wwwlogs/hd.log; }Copy the code
3 PHP extensions to remember to open
Before deploying the project, make sure that the php.ini extensions are enabled. These include php_FileInfo, PHp_MBString, and php_OpenSSL, which laravel needs.
If you have changed nginx or php.ini, remember to restart nginx and php-fpm.
4. Laravel project may be missing some core libraries when it is cloned online from Git
Warning: require(): open_basedir restriction in effect. File(/home/wwwroot/***/bootstrap/autoload.php) is not within the allowed path(s): (/home/wwwroot/***/public/:/tmp/:/proc/) in /home/wwwroot/***/public/index.php on line 22 Warning: require(/home/wwwroot/***/bootstrap/autoload.php): failed to open stream: Operation not permitted in /home/wwwroot/***/public/index.php on line 22 Fatal error: require(): Failed opening required '/home/wwwroot/***/public/.. /bootstrap/autoload.php' (include_path='.:/usr/local/php/lib/php') in /home/wwwroot/***/public/index.php on line 22Copy the code
In this case, you need to update the third-party vendor component to perform the Composer update in the project directory. Please update the composer to the latest version by yourself.
If there is an error in the update, please find the corresponding composer error online, which is easy to solve.
If app_key error occurs when laravel clone git from online directory, please add app_key to.env.
// Generate key, Run the app_key PHP artisan key:generate command in the project root directory to obtain the laravel project app_key PHP artisan key:generate // or modify the app_key parameter in the configuration file. Env APP_KEY=base64:akjIOLlieujKw0yEUbwjJdP5lPWHkk3uw39CnAhfdasfsaddfggghssda+Copy the code
6 Laravel Upload The cipher and/or key length are invalid
A lot of this is caused by reading.env for null.
First, you should check whether there is a key and cipher configuration in config app.php
'key' => env('APP_KEY'),
'cipher' => 'AES-256-CBC',
Copy the code
If there is an app_key in env, look for it. If it exists, please operate:
php artisan config:cache
Since env failed, the next thing you need to do is clear the cache and start over. An important step is to restart nginx, phP-fpm
PHP artisan DB :seed (artisan DB :seed, artisan DB :seed) The error message is [ReflectionException] Class
*
TableSeeder does not exist
Make sure the new seeder file is in the same seeder directory as the global database seeder. The reason for this problem is that we need to clean up the classMap information generated by the previous execution.
Execute composer dump-autoload in the console, and then PHP Artisan DB :seed
I’ve had so many problems, maybe you’ll have more problems, maybe you won’t have problems. Perhaps the above problems I encountered can give you some help!