DB Connection with XAMPP

Hi !

I’m really glad I have chosen to learn cakePHP to strength my programming skills! But I am having issues connecting to my database.
I am following the creating a first app guide and I’m having problems getting cake to connect to my phpmyadmin database.

  • I have the cake server running on default ports 8765. And I have my XAMPP server running on 8080.
  • I have created the db tables in phpmyadmin on xampp server.
  • I have set up the app_local.php db connection code with the correct credentials and pointing to localhost:8080 which is where phpmyadmin in xampp is.

Is this the right way to set everything on? Feels a bit clunky running xampp as well as cake server…

Much help is appreciated, I cannot get the green DB connection icon!

Thanks in advance.


There’s a few things going on, we’re looking at full stack, so your XAMPP is making your PC behave like a webserver, and handling the SQL & PHP etc. The CakePHP server app is really just triggering the php translator to pick up the code you have there in your app (so one cake server app for each cake app - if that makes sense).

What you may be missing is that you need to set your SQL values in your cfg/app_local.php file. Look for and correct these values to how you have your SQL server: -

    'Datasources' => [
        'default' => [
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'secret',
            'database' => 'cake_db',

as the wizard/bake does not do that for you (at least, it didn’t when I last played with it).

Failing that you may need to copy/paste your debug info (ensuring no private data is shared) to a post here.

Hope that helps.


Edit: I just noticed this comment in that same file: -

             * CakePHP will use the default DB port based on the driver selected
             * MySQL on MAMP uses port 8889, MAMP users will want to uncomment
             * the following line and set the port accordingly
            //'port' => 'non_standard_port_number',

(ironic that I copy/pasted around it!) so you may need to set the port too.

This is the only error I’m getting on the original welcome page.

CakePHP is NOT able to connect to the database. Connection to Mysql could not be established: SQLSTATE[HY000] [2002] No such file or directory

This is my config settings:

Screenshot 2021-02-07 at 09.26.30

When I start the server I get this PHP warning message. And the in path is blank. Could that be causing any issues?

Does it accept a blank password? (or you just removed it for your post.)

I don’t know if international settings would cause a problem though.

I can only suggest building a new test app, showing the commands use in doing so, and the structure of your SQL creation script.

For comparison, I did this, running XAMPP (all default I think!).


Then made a new app, cake_test: -
composer self-update
composer create-project --prefer-dist cakephp/app:4.* cake_test
then run it
cd cake_test\bin
cake server
(I run the server from within the \bin\ folder to resolve any relative paths a may have external to my CakePHP app.)

And go to my new app, which is broken from the SQL

I then copy adminer.php into webroot (I love adminer!!)
MySQL, English https://github.com/vrana/adminer/releases/download/v4.7.8/adminer-4.7.8-mysql-en.php
I know phpmyadmin ships with XAMPP, but I still prefer adminer (just don’t publish it in your release!)

Using my credentials root/secret I login

(I think I set that password ages ago, it may be blank password by default - but if you don’t know you may be up for reinstalling XAMPP for a clean MySQL)

I create my database, test

Update config\app_local.php: -

            'username' => 'root',
            'password' => 'secret',
            'database' => 'test',



Note this is all default values. I get default stuff to work first before I even consider tailoring it to my needs, and even then it’s one change at a time!
After any change to your models or database clear the cache with bin\cake cache clear_all

8080 is almost certainly the port where Apache is running, not MySQL. See @Jawfin’s XAMPP control panel screen shot, in his case (which is the standard), MySQL is running on 3306. Check your control panel to see where your MySQL is.

I’m running all conventional ports (3306 for MySQL) and while I can get ‘cake server’ to give the splash page, it refuses to connect to my database. I can connect to the database with both phpMyAdmin and MySQLWorkbench without issue. I can add tables, users, etc. with zero issue. But, when I add the credentials in app_local.php as shown in the CakePHP instructions, it just refuses to connect. I’m at a loss, after a day of trying I’m getting nowhere.

    'Datasources' => [
        'default' => [
            'className' => 'Cake\Database\Connection',
            'driver' => 'Cake\Database\Driver\Mysql',
            'port' => 3306,
            'persistent' => false,
            'host' => 'localhost',
            'username' => 'root',
            'password' => 'password',
            'database' => 'cake_php',
            'encoding' => 'utf8mb4',
            'timezone' => 'UTC',
            'cacheMetadata' => true,

Is phpMyAdmin running on the same server as your CakePHP application? What does “refuses to connect” mean, what error do you get?