• rarestoma

    (@rarestoma)


    I have a PHP Laravel project hosted on Heroku with a Postgresql database and I want to add a WordPress blog to /blog.

    I added in the public folder a blog folder and then copied the last version of WordPress there.

    After that, I followed, starting with step 6, this tutorial: https://www.merocode.com/hosting-wordpress-blog-on-heroku-with-support-of-postgres/. I also replaced the wp_config variables with the ones provided on Heroku.

    After deploying it to Heroku and trying to test my_site.herokuapp.com/blog I get:

    Warning: mysqli_real_connect(): (HY000/2002): No such file or directory in /app/public/blog/wp-content/pg4wp/core.php(32) : eval()’d code on line 1612

    Connecting to your PostgreSQL database without a password is considered insecure. If you want to do it anyway, please set “PG4WP_INSECURE” to true in your “db.php” file.

    Can anyone help me with this problem? Do you know another good tutorial with all the steps that can help me host a WordPress blog to an existing PHP Laravel project?

    Thank you!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m guessing your SQL DB host is “localhost”, which often causes SQL to listen on a Unix socket instead of TCP. Try specifying “127.0.0.1” instead of “localhost” (in wp-config.php). This forces SQL to use TCP.

    I’m sorry I cannot point you to any tutorials like you are looking for.

    Thread Starter rarestoma

    (@rarestoma)

    Hi,

    Thank you for your answer.

    For the DB_HOST I added the one provided in the credentials of Heroku postgres. Isn’t that the required one?

    Thank you

    Moderator bcworkz

    (@bcworkz)

    Yes it is. But if it is “localhost”, it’s a special sort of domain name that resolves to 127.0.0.1 IP address. It’s the same location. You are essentially managing the DNS resolution by using the IP instead of the domain name. But in doing so you make SQL listen on a different port instead of the default which isn’t valid in this scenario.

    Thread Starter rarestoma

    (@rarestoma)

    I tried this but still not working…

    Moderator bcworkz

    (@bcworkz)

    I found the referenced eval’d code at line 32 of core.php of the pg4wp plugin. It seems like constants like DB_PASSWORD and ABSPATH are not defined to get errors like that. You said you “replaced the wp_config variables”. If you changed the constant definition names, that would be a problem. You might change the assigned values, but you shouldn’t change the constant names. You can add other constants if necessary, but not change the existing ones.

    Thread Starter rarestoma

    (@rarestoma)

    Hi,

    So these have not to be modified

    if (isset($_ENV[“DATABASE_URL”]))
    {
    $db = parse_url($_ENV[“DATABASE_URL”]);
    define(‘DB_NAME’, trim($db[“path”],”/”));
    define(‘DB_USER’, $db[“user”]);
    define(‘DB_PASSWORD’, $db[“pass”]);
    define(‘DB_HOST’, $db[“host”]);
    }
    else
    {
    die(“Can’t determine database settings from DATABASE_URL\n”);
    }

    ?
    I have to define, for example, DB_name or path? Where do I define them?

    Thank you

    Moderator bcworkz

    (@bcworkz)

    I don’t have any reason to believe that code snippet wouldn’t work if the environment value DATABASE_URL has the correct parameters, including DB password. It should be of the form https://username:password@hostname/db_name. I’ve no idea where this is set. Since you cannot re-define constants, the only way to override constant values is to comment out the default definition code and insert your own custom definition.

    The line 32 error specifically fails with file_get_contents(ABSPATH.'/wp-includes/wp-db.php') which should work if ABSPATH is defined correctly. It’s normally defined at the bottom of wp-config.php where there’s code that is not supposed to be altered: define('ABSPATH', dirname(__FILE__) . '/'); which sets ABSPATH to the path of the current file. However, prior to this is if ( !defined('ABSPATH') ), so if some other code before this erroneously sets ABSPATH, the wp-config.php definition is skipped and the desired wp-db.php file would not be found.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘I try to add a blog to an existing heroku PHP laravel project’ is closed to new replies.