Magento – Get Magento2 to run locally on MAMP

localhostmagento2.2mamp

I have a MAMP with PHP 7.1.8 up and running. I downloaded my production Magento 2.2 based website and also imported the MySQL database into my localhost phpMyAdmin.Then I changed the URL in the core_config_data table to reflect the localhost URL to get to the site.

However now when I go to the site in the browser I get this error
An error has happened during an application run. See exception log for details.

when I look at the exception.log I see it says

main.CRITICAL: PDOException: SQLSTATE[HY000] [2002] No such file or directory in /Applications/MAMP/htdocs/devkisseurope/vendor/magento/zendframework1/library/Zend/Db/Adapter/Pdo/Abstract.php:128

I googled around and see mention that it may mean that the PHP version. being used is not the same version that MAMP uses.
However, I edited the ~/.bash_profile as well as the ~/.profile files and rebooted. now when I run

which PHP

I see the below which is the correct bath the php I am using

/Applications/MAMP/bin/php/php7.1.8/bin/php

So I am not sure what i am missing to get my Magento2 running locally for development?

I have been able to install a Magento 2.2 from scratch with no issues. I am just not able to get a copy of an already developed production magento 2.2 site to run locally on my mamp server so I can further develop it.

Best Answer

  1. Check the PHP version your webserver you are using. Do it by creating a phpinfo.php page with the below contents.

<?php phpinfo(); ?>

  1. Run the php -i | grep 'php.ini' on your SSH / CLI terminal. Check the PHP settings from the file found.

If the settings/version present in step 1 & step 2 to differ then apply the same PHP settings present on your webserver to your CLI.

  1. Say, the PHP version you want to point to is 5.6.32, then run the below command on your CLI.

export PATH=/Applications/MAMP/bin/php/php5.6.32/bin/:$PATH

  1. Start off with a new terminal. Also, check if the changes are reflected by executing the command again on CLI php -i | grep 'php.ini'

If you need more details, please find here

Related Topic