首页  >  问答  >  正文

解码应用程序的数据库连接:寻求帮助

我是一名 Php 新手,最近收到了一些应用程序 (php/laravel) 的工作,该应用程序在服务器 (AWS) 上运行,使用 MySQL 和 RDS,并由 nginx 托管 app/php 内容

这是定义在 /etc/nginx/conf.d 中找到的 nginx 路径的文件

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

我有源代码,但之前的自由职业者已停止与客户合作。我没有数据库凭据,我需要访问数据库,但我不能。我尝试从 php 文件中查找密码,我所能找到的只是一个配置文件夹,其中包含一个文件database.php,其内容如下:

'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,
        ],
];

我已经使用 printenv 检查了环境变量,但找不到任何 DB_USERNAME 等环境变量。由于应用程序运行良好,因此它能够连接到数据库。

如何获取数据库的凭据。有什么方法可以弄清楚应用程序如何连接到数据库并运行良好?

P粉551084295P粉551084295223 天前432

全部回复(2)我来回复

  • P粉458913655

    P粉4589136552024-04-03 11:48:26

    在 laravel 根目录中,您应该看到一个名为“.env”的文件,打开此文件,您应该在其中看到所有 laravel 实例变量

    回复
    0
  • P粉135799949

    P粉1357999492024-04-03 00:45:16

    这是一个 PHP/Laravel 应用程序,连接信息存储在服务器环境中。数据库连接逻辑是框架的一部分,你不必摆弄它(它是第三方代码,不是业务逻辑的一部分)

    在某些情况下,环境存储在名为 .env 的文件中(位于 PHP 应用程序的根文件夹中)

    在某些设置中,环境可能不在文件中,但它是在部署期间创建的,并与系统环境变量一起存储。

    无论哪种方式,您都应该查找 DB_* 环境变量来获取数据库连接凭据、服务器和端口。

    回复
    0
  • 取消回复