-1

I'm using MAMP on MacOS 12.3.1 to serve a PHP based website. The site uses a .env file. I have set this site set up on many Windows machines. To do this I simply copy over the site files, with the vendor folder and change the .env file to match my local database settings.

On my new M1 based Mac though I get the following error. As a test I set up a brand new WordPress site and this connected to the same database no problem so the local database is running.

I've been pulling my hair out all day, from my research it seems to either be related to a port or a socket connection. I'm out of my depth so I don't want to start editing config files unless I know what I'm editing might work.

Any help will be very much appreciated.

Richard

Fatal error: Uncaught PDOException: SQLSTATE[HY000] [2002] Connection refused in /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/database.php:20 Stack trace: #0 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/database.php(20): PDO->__construct('mysql:host=loca...', 'root', 'root', Array) #1 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/database.php(38): DB::instance() #2 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/products.php(320): DB::run('SELECT * FROM p...', Array) #3 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/vars.php(20): Products::loadProducts() #4 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/core.php(79): include('/Users/ricky/Do...') #5 /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/header.inc.php(1): include('/Users/ricky/Do...') # in /Users/ricky/Documents/Projects/Jay-Be/Web/website-commerce-2022/site/dist/_/inc/classes/database.php on line 20

New - reports port zero

Ricky55
  • 67
  • 1
  • 7
  • yes I did. DB_CONNECTION=mysql DB_HOST=localhost DB_PORT=3306 DB_DATABASE=test_db DB_USERNAME=root DB_PASSWORD='root' – Ricky55 May 10 '22 at 18:33
  • MAMP is set to port 3306 the default but when I view phpmyadmin via the MAMP link its says localhost:8889. I have tried setting MAMP to use this port and it still doesn't work. Like I say on my Windows machine it just works no issues. – Ricky55 May 10 '22 at 18:34
  • Well that'd be a different error actually anyway. Can you connect to mysql directly? – user3783243 May 10 '22 at 18:36
  • The config file is just a .env file in the root of the project. Its not using a framework. – Ricky55 May 10 '22 at 18:37
  • It does have a composer.json file but on every other machine I've just copied the vendor folder. I've not had to install or run composer to get it to work. – Ricky55 May 10 '22 at 18:38
  • Here's the folder structure https://ibb.co/1YCfPBT – Ricky55 May 10 '22 at 18:39
  • Sorry, can you just try connecting to MySQL external of PHP and see if the credentials work? – user3783243 May 10 '22 at 18:40
  • How would I do that? I have a Wordpress demo site connecting to the same database and it works with that. - Just as a test obviously. – Ricky55 May 10 '22 at 18:42
  • `mysql -uroot -proot` from terminal should put you to it. – user3783243 May 10 '22 at 18:44
  • I just get zsh: command not found: mysql – Ricky55 May 10 '22 at 18:45
  • Guess mamp doesn't define alias, try steps at https://stackoverflow.com/questions/9335403/access-mamps-mysql-from-terminal – user3783243 May 10 '22 at 18:50
  • That works. I can login using root user with root password – Ricky55 May 10 '22 at 18:57
  • Okay, and once connected what does it show for port running? https://serverfault.com/questions/116100/how-to-check-what-port-mysql-is-running-on – user3783243 May 10 '22 at 19:02
  • Just run that command and it reports the port as being zero. – Ricky55 May 10 '22 at 19:11
  • mysql> SHOW GLOBAL VARIABLES LIKE 'PORT'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | port | 0 | +---------------+-------+ 1 row in set (0.01 sec) mysql> – Ricky55 May 10 '22 at 19:13
  • You should search for some of this information, https://stackoverflow.com/questions/9979134/how-can-i-change-mysql-port-from-0-to-3306 – user3783243 May 10 '22 at 19:15
  • Working!!! thank you so much. I followed this post.https://stackoverflow.com/questions/9979134/how-can-i-change-mysql-port-from-0-to-3306. Edited the my.cnf file uncommitted the ports back to 3306 then turned on allow network access to mysql from mamp – Ricky55 May 10 '22 at 19:37
  • 1
    Does this answer your question? [How can I change mysql port from 0 to 3306?](https://stackoverflow.com/questions/9979134/how-can-i-change-mysql-port-from-0-to-3306) – user3783243 May 10 '22 at 19:51

0 Answers0