1

I've cloned a Craft 3 repo that was created by another developer and I'm trying to get it running on my local server but I get

HTTP 503 – Service Unavailable – craft\web\ServiceUnavailableHttpException

I've created a quick db test script to test my database connection…

<?php
$dbname = 'local';
$dbuser = 'root';
$dbpass = 'root';
$dbhost = 'localhost';

$link = mysqli_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysqli_select_db($link, $dbname) or die("Could not open the db '$dbname'");

$test_query = "SHOW TABLES FROM $dbname";
$result = mysqli_query($link, $test_query);

$tblCnt = 0;
while($tbl = mysqli_fetch_array($result)) {
  $tblCnt++;
  #echo $tbl[0]."<br />\n";
}

if (!$tblCnt) {
  echo "There are no tables<br />\n";
} else {
  echo "There are $tblCnt tables<br />\n";
}
?>

which works fine. The settings for the db are the same as in my .env file…

# Craft general settings
ENVIRONMENT="dev"
SECURITY_KEY="[email protected]_t3DaoZZnY"

# Craft database settings
DB_DRIVER="mysql"
DB_SERVER="localhost"
DB_USER="root"
DB_PASSWORD="root"
DB_DATABASE="local"
DB_SCHEMA="public"
DB_TABLE_PREFIX=""
DB_PORT="4095"

I've checked the permissions of files and folders as described in the installation docs.

What else should I be looking for?

EDIT: As suggested, I've looked in storage/logs/web.log and this is what I get:

    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][info][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=local;port=4095;
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][profile begin][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=local;port=4095;
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][profile end][yii\db\Connection::open] Opening DB connection: mysql:host=localhost;dbname=local;port=4095;
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][info][yii\db\Command::query] SHOW TABLES
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][profile begin][yii\db\Command::query] SHOW TABLES
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][profile end][yii\db\Command::query] SHOW TABLES
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\Module::getModule] Loading module: exifReturn
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\Application::bootstrap] Bootstrap with modules\exifreturn\ExifReturn
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][info][yii\web\Session::open] Session started
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][error][yii\web\HttpException:503] craft\web\ServiceUnavailableHttpException in /app/pb-repo/vendor/craftcms/cms/src/web/Application.php:529
    Stack trace:
    #0 /app/pb-repo/vendor/craftcms/cms/src/web/Application.php(187): craft\web\Application->_processInstallRequest(Object(craft\web\Request))
    #1 /app/pb-repo/vendor/yiisoft/yii2/base/Application.php(386): craft\web\Application->handleRequest(Object(craft\web\Request))
    #2 /app/pb-repo/web/index.php(21): yii\base\Application->run()
    #3 {main}
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\View::renderFile] Rendering view file: /app/pb-repo/vendor/yiisoft/yii2/views/errorHandler/exception.php
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\View::renderFile] Rendering view file: /app/pb-repo/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\View::renderFile] Rendering view file: /app/pb-repo/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\View::renderFile] Rendering view file: /app/pb-repo/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php
    2019-12-05 08:35:09 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][trace][yii\base\View::renderFile] Rendering view file: /app/pb-repo/vendor/yiisoft/yii2/views/errorHandler/callStackItem.php
    2019-12-05 08:35:08 [-][-][d97bb3d28a3fdd84f8c8edc795e22e6d][info][application] $_GET = []

    $_POST = []

    $_FILES = []

    $_COOKIE = [
        'CraftSessionId' => 'd97bb3d28a3fdd84f8c8edc795e22e6d'
    ]

    $_SESSION = [
        'bd62416aa8538ede709019a5e113eea5__flash' => []
    ]

    $_SERVER = [
        'USER' => 'www-data'
        'HOME' => '/var/www'
        'SCRIPT_NAME' => '/index.php'
        'REQUEST_URI' => '/'
        'QUERY_STRING' => ''
        'REQUEST_METHOD' => 'GET'
        'SERVER_PROTOCOL' => 'HTTP/1.0'
        'GATEWAY_INTERFACE' => 'CGI/1.1'
        'REMOTE_PORT' => '50902'
        'SCRIPT_FILENAME' => '//app/pb-repo/web/index.php'
        'SERVER_ADMIN' => 'webmaster@localhost'
        'CONTEXT_DOCUMENT_ROOT' => '/app/pb-repo/web'
        'CONTEXT_PREFIX' => ''
        'REQUEST_SCHEME' => 'http'
        'DOCUMENT_ROOT' => '/app/pb-repo/web'
        'REMOTE_ADDR' => '172.17.0.1'
        'SERVER_PORT' => '80'
        'SERVER_ADDR' => '172.17.0.5'
        'SERVER_NAME' => 'pb.local'
        'SERVER_SOFTWARE' => 'Apache/2.4.10 (Debian)'
        'SERVER_SIGNATURE' => ''
        'PATH' => '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin'
        'HTTP_COOKIE' => 'CraftSessionId=d97bb3d28a3fdd84f8c8edc795e22e6d'
        'HTTP_UPGRADE_INSECURE_REQUESTS' => '1'
        'HTTP_ACCEPT_ENCODING' => 'gzip, deflate, br'
        'HTTP_ACCEPT_LANGUAGE' => 'en-GB,en;q=0.5'
        'HTTP_ACCEPT' => 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'
        'HTTP_USER_AGENT' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:70.0) Gecko/20100101 Firefox/70.0'
        'HTTP_CONNECTION' => 'close'
        'HTTP_X_FORWARDED_PROTO' => 'https'
        'HTTP_X_FORWARDED_HOST' => 'pb.local'
        'HTTP_X_FORWARDED_FOR' => '192.168.95.1'
        'HTTP_X_REAL_IP' => '192.168.95.1'
        'HTTP_HOST' => 'pb.local'
        'proxy-nokeepalive' => '1'
        'HTTPS' => 'on'
        'FCGI_ROLE' => 'RESPONDER'
        'PHP_SELF' => '/index.php'
        'REQUEST_TIME_FLOAT' => 1575534907.7596
        'REQUEST_TIME' => 1575534907
        'ALLOW_UPDATES' => '1'
        'ALLOW_ADMIN_CHANGES' => '1'
        'BACKUP_ON_UPDATE' => '0'
        'DEV_MODE' => '1'
        'ENABLE_TEMPLATE_CACHING' => '1'
        'ENVIRONMENT' => 'dev'
        'IS_SYSTEM_LIVE' => '1'
        'RUN_QUEUE_AUTOMATICALLY' => '1'
        'SECURITY_KEY' => '••••••••••••••••••••••••••••••••••••••••'
        'SITE_NAME' => ''
        'DB_DRIVER' => 'mysql'
        'DB_SERVER' => 'localhost'
        'DB_USER' => 'root'
        'DB_PASSWORD' => '••••'
        'DB_DATABASE' => 'local'
        'DB_SCHEMA' => 'public'
        'DB_TABLE_PREFIX' => ''
        'DB_PORT' => '4095'
        'ASSETS_URL' => ''
        'UPLOADS_URL' => '/uploads/'
        'SITE_URL' => 'https://pb.local/'
        'WEB_ROOT_PATH' => '.'
        'PUBLIC_PATH' => './web/'
        'DEFAULT_SITE_URL' => 'https://pb.local'
    ]

So it seems to be connecting OK, showing tables, loading some modules, starting the session, and then returning the httpException error.

5
  • I'd recommend turning on devMode for the development environment to get more information about the error, and checking storage/logs/web.log for a stack trace. Commented Dec 5, 2019 at 4:46
  • I've added the most recent output from web.log.
    – Tyssen
    Commented Dec 5, 2019 at 8:42
  • 1
    Also worth looking at your table names to ensure it's not using a tablePrefix (if your tables all begin with something like craft_, then you may need to include this in your database config / .env. Commented Dec 5, 2019 at 19:09
  • 1
    That was it! There was a table prefix but I hadn't bothered to look closely at the tables after I imported the database.
    – Tyssen
    Commented Dec 5, 2019 at 21:32
  • I had a similar problem, and found that my database user was not set up with proper permissions. I found this in the logs, very helpful.
    – 4midori
    Commented Mar 16, 2022 at 0:35

2 Answers 2

1

This answer was contributed after troubleshooting in comments on the original question.

This error can appear for a variety of reasons, but most commonly when Craft believes it isn't installed.

The installation process begins at /admin/install, but is dependent upon the cpTrigger config value. That this page wasn't accessible (or, more specifically, produced the same error instead the Admin or installation wizard) led the asker to conclude that the config value had been updated by the prior developer.

Craft may believe it isn't installed if it can't find the expected tables—sometimes complicated by using a tablePrefix setting, in the database configuration. This setting exists in the event you need to maintain more than one Craft install side-by-side, in the same database.

In this case, a combination of these two settings made it difficult to tell why Craft was producing the 503 error.

4

Try accessing the CP-Panel, in most cases this error occurs due to config files not being set correctly, thus not allowing craft to connect to the DB.

If you get the installer page when accessing the CP-Pannel, that means it's most likely not able to access the DB with your current configs.

Usually the URL would be my-host.com/backstage however this may differ based on your cpTrigger config value in config/general.php.

Edit: devMode should be set to true in config/general.php.

If this doesn't resolve the issue, try clearing your entire logs folder, calling your page and then uploading those log files as a zip file to any file hoster so we can take closer look at it, your current output from your web.log doesn't show too much...

2
  • admin is the default cpTrigger value—might be worth updating, granted most installs will be configured as such, out of the box. Otherwise, great recommendations, thorough answer! 💞 Commented Dec 5, 2019 at 19:07
  • 2
    This was another stumbling block. The cpTrigger had been set to a different value so I was getting the same error when trying to access the default /admin.
    – Tyssen
    Commented Dec 5, 2019 at 21:33

Not the answer you're looking for? Browse other questions tagged or ask your own question.