搜尋

首頁  >  問答  >  主體

解碼應用程式的資料庫連線:尋求協助

我是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粉551084295239 天前473

全部回覆(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
  • 取消回覆