skip to Main Content

I’m a Php newbee and I recently received some work for an app (php/laravel) which is running on the server (AWS) using MySQL with RDS with nginx hosting the app/php contents

this is the file that defines paths for nginx found in /etc/nginx/conf.d

server {

    server_name mytable.sa;
    http2_max_field_size 64k;
    http2_max_header_size 512k;
    client_max_body_size 100m;

    index index.php admin.php;

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log main;

    location = /favicon.ico {
        access_log off; log_not_found off;
    }
    location = /robots.txt {
        access_log off; log_not_found off;
    }

    root /var/www/project/public_html;

    # ssl files
    #include project.tech/ssl.conf;

    include compression.conf;
        location ~ /.well-known/apple-app-site-association {
         default_type application/pkcs7-mime;
    }


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

    location / {
        try_files $uri /index.php$is_args$args;
        #try_files $uri /Home.html;
    }

    location /admin {
        try_files $uri $uri/ /admin.php$is_args$args;
        proxy_connect_timeout 900;
        proxy_send_timeout 900;
        proxy_read_timeout 900;
        send_timeout 900;
        # location ~ .php$ {
        #     include snippets/fastcgi-php.conf;
        #     fastcgi_pass unix:/run/php-fpm/www.sock;
     }

  location /api {
        try_files $uri $uri/ /api.php$is_args$args;
    }

    location /opelia {
        try_files $uri /adminRest.php$is_args$args;
    }

    location /delivery-app {
        try_files $uri /delivery-app.php$is_args$args;
        proxy_connect_timeout 900;
        proxy_send_timeout 900;
        proxy_read_timeout 900;
        send_timeout 900;
    }

    location /social {
        try_files $uri /social.php$is_args$args;
    }


    location ~ .php$ {
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;
    }

    location ~ /.ht {
        deny all;
    }

    location /project {
        index index.html;
        autoindex on;
    }

    location /docs {
        index index.html;
    }

    # Proxy any URL request to S3 bucket and remove any Amazon headers
    location ~ "^/uploads/(.*)$" {
        add_header X-Asset-Location $hostname;

        set $bucket "mytable-files-new";
        set $key $1;
      rewrite .* /uploads/$key break;

        # no client headers
        proxy_pass_request_headers off;

        # let amazon take the buffering load
        proxy_buffering off;

        # let amazon retry a few times if first timeouts are 5xx response
        proxy_next_upstream error timeout http_500 http_502 http_503 http_504;

        proxy_set_header Host $bucket.s3.amazonaws.com;

        proxy_pass https://s3.amazonaws.com;
        proxy_hide_header "x-amz-id-2";
        proxy_hide_header "x-amz-request-id";
    }


    set $no_cache 0;

    # If non GET/HEAD, don't cache & mark user as uncacheable for 1 second via cookie
    if ($request_method !~ ^(GET|HEAD)$) {
        set $no_cache "1";
    }

    if ($request_uri ~* "/(uploads/|admin/|opelia/)") {
        set $no_cache 1;
    }

    if ($request_uri ~* "^/entity1/search") {
        set $no_cache 1;
    }
    if ($request_uri ~* "^/entity1/") {
        set $no_cache 1;
    }
    if ($request_uri = "/booking") {
        set $no_cache 1;
    }

    if ($request_uri = "/api/me") {
        set $no_cache 1;
    }
    if ($request_uri = "/api/me/favourite/entity1") {
        set $no_cache 1;
    }
    if ($request_uri = "/api/me/need-review") {
        set $no_cache 1;
    # refactor frontend languages to seprate urls to enable cache
    if ($request_uri ~* "^/register_restaurant_step") {
        set $no_cache 1;
    }


    # Don't cache or serve pages specified above
#    fastcgi_cache_bypass $no_cache;
 #   fastcgi_no_cache $no_cache;

    # Select which cache to use
  #  fastcgi_cache microcache;
    # Cache successful responses for one second, you could also cache redirects here by adding status code 302!
    #fastcgi_cache_valid any 60s;
   # # Show cache status in HTTP headers, useful for debugging
    #add_header X-Cache $upstream_cache_status;


listen 80;

I have the source code but the previous freelancer has stopped cooperating with the client. I have no db credentials and I need to access database but I can’t. I tried locating the password from the php files and all I could find was a config folder with a file database.php that has contents like this:

'connections' => [

        'sqlite' => [
            'driver' => 'sqlite',
            'database' => env('DB_DATABASE', database_path('database.sqlite')),
            'prefix' => '',
        ],

        'mysql' => [
            'driver' => 'mysql',           
            'read' => [
                'host' => [
                    env('DB_HOST_READ_2'),
                    env('DB_HOST_READ_1'),
                    env('DB_HOST_READ'),
                    // env('DB_HOST_WRITE'),
                ],
            ],
            'write' => [
                'host' => [
                    env('DB_HOST_WRITE'),
                 ],
            ],                
            //'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '3306'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'unix_socket' => env('DB_SOCKET', ''),
            'charset' => 'utf8mb4',
            'collation' => 'utf8mb4_unicode_ci',
            'prefix' => '',
            'strict' => false,
            'engine' => null,
        ],

        'pgsql' => [
            'driver' => 'pgsql',
            'host' => env('DB_HOST', '127.0.0.1'),
            'port' => env('DB_PORT', '5432'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
            'schema' => 'public',
            'sslmode' => 'prefer',
        ],
        'sqlsrv' => [
            'driver' => 'sqlsrv',
            'host' => env('DB_HOST', 'localhost'),
            'port' => env('DB_PORT', '1433'),
            'database' => env('DB_DATABASE', 'forge'),
            'username' => env('DB_USERNAME', 'forge'),
            'password' => env('DB_PASSWORD', ''),
            'charset' => 'utf8',
            'prefix' => '',
        ],

    ],

    /*
    |--------------------------------------------------------------------------
    | Migration Repository Table
    |--------------------------------------------------------------------------
    |
    | This table keeps track of all the migrations that have already run for
    | your application. Using this information, we can determine which of
    | the migrations on disk haven't actually been run in the database.
    |
    */

    'migrations' => 'migrations',

    /*
    |--------------------------------------------------------------------------
    | Redis Databases
    |--------------------------------------------------------------------------
    |
    | Redis is an open source, fast, and advanced key-value store that also
    | provides a richer set of commands than a typical key-value systems
    | such as APC or Memcached. Laravel makes it easy to dig right in.
    |
    */

    'redis' => [

        'client' => 'predis',

        'default' => [
            'host' => env('REDIS_HOST', '127.0.0.1'),
            'password' => env('REDIS_PASSWORD', null),
            'port' => env('REDIS_PORT', 6379),
            'database' => 0,
        ],
];

I have checked the environment variables using printenv but i could not find any env variables that are DB_USERNAME etc. Since the app is running fine therefore it is able to connect to the database.

how can I get the credentials for the database. is there a way I can figure out how the app is able to connect to the database and is functioning just fine?

3

Answers


  1. In the laravel root directory, you should see a file named ‘.env’ open this file, you should see all your laravel instance variables in there

    Login or Signup to reply.
  2. check the .env file on the application root folder for keys like: DB_USERNAME= and DB_PASSWORD=

    Login or Signup to reply.
  3. This is a PHP/Laravel application and the connection information is stored in the server environment. The database connection logic is part of the framework, you don’t have to fiddle with it (it’s third-party code, not part of the business logic)

    In some cases, the environment is stored in a file, called .env (it’s in the root folder of the PHP application)

    There could be some setups where the environment is not in the file but it’s created during deployment and stored alongside the system environment variables.

    Either way you should look for the DB_* environment variables to get your DB connection credentials, server and port.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search