Ad

Status 500 Internal Server Error Between Droplet With Nginx And Google Cloud Storage

I have a web system in a droplet with Digital Ocean, the droplet has installed nginx, the system has an option to upload files, these files are sent to a Google Cloud Storage bucket. When I am in the localhost the files are sent correctly, but already in the system, I am receiving a Status 500 Internal Server Error. I leave some screenshots

Image of the System and Error

Also getting the response:

{ "message": "Server Error" }

But when I run it from localhost

All good in localhost

This is my GoogleStorageServiceProvider

public function boot()
{
    \Storage::extend('gcs', function($app, $config){

        $storageClient = new StorageClient([
            'projectId' => $config['project_id'],
            'keyFilePath' => $config['key_file'],
        ]);
        $bucket = $storageClient->bucket($config['bucket']);

        $adapter = new GoogleStorageAdapter($storageClient, $bucket);

        return new Filesystem($adapter);
    });
}

This is my .env

APP_NAME=Laravel
APP_ENV=production
APP_KEY=MY_KEY
APP_DEBUG=false
APP_URL=http://.com

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=database
DB_USERNAME=root
DB_PASSWORD=databasepass

GOOGLE_CLOUD_PROJECT_ID=starlit...
GOOGLE_CLOUD_KEY_FILE=/my-project/credentials.json
GOOGLE_CLOUD_STORAGE_BUCKET=my-bucket
FYLESYSTEM_DRIVER=gcs

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

This is my sudo vim /etc/nginx/sites-available/YOUR.DOMAIN.COM file

server {
listen 80;
listen [::]:80;

server_name YOUR.DOMAIN.COM;
return 301 https://$server_name$request_uri;
}

server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name YOUR.DOMAIN.COM;
root /var/www/html/first-project/public;

ssl_certificate /etc/letsencrypt/live/YOUR.DOMAIN.COM/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/YOUR.DOMAIN.COM/privkey.pem;

ssl_protocols TLSv1.2;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-   SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers on;

add_header X-Frame-Options "SAMEORIGIN";
add_header X-XSS-Protection "1; mode=block";
add_header X-Content-Type-Options "nosniff";

index index.php index.html index.htm index.nginx-debian.html;

charset utf-8;

location / {
        try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/var/run/php/php7.2-fpm.sock;
}

location ~ /\.ht {
        deny all;
}

location ~ /.well-known {
        allow all;
}
}

Any idea what's happening?

Ad

Answer

As @AlecJoy said, I had to check the laravel logs to get more context. Was in the default folder storage/logs/. There I found an error that said "production.ERROR: class 'Google\Cloud\Storage\StorageClient' not found" so I use the command composer install, couldn't use it, so I try with composer update, that gave me an error of "mmap() failed: [12] Cannot allocate memory" I was searching and found this commands. Also I have to used sudo in all the commands.

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024
/sbin/mkswap /var/swap.1
/sbin/swapon /var/swap.1

After that, I had the same problem, so I went to the Laravel Logs again, I found this Error " production.ERROR: Given keyfile path /my-project/credentials.json does not exist " so I had to edit my .env file and gave the full path " /var/www/html/my-project/credentials.json "

Ad
source: stackoverflow.com
Ad