OSX machine running MAMP. CakePHP 2.2.1 installed and configured properly (meaning that I have all green bars when I browse to the Index.php file, I have completed the Blogs tutorial and am working on my second app with which scaffolding is up and running). Now I am trying to Bake for the first time.
Per the cookbook (and others), I installed a fresh copy of cake into a directory (my users directory) and then put the path variable in my .bash_profile file
export PATH="$PATH:/Users/p_scott/cake221/app/Console"
after which I was able to go into Terminal, type cake and have the console come up. You can see that up to that point, I was invoking the console from the app directory.
I first tried running cake bake from the terminal using the -app parameter and designating the path to my practice apps. The first time I did this, I got the following
Welcome to CakePHP v2.2.1 Console
-------------
App : app
Path: /Applications/MAMP/htdocs/blog/app/
-------------
Interactive Bake Shell
---------------
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
What would you like to Bake? (D/M/V/C/P/F/T/Q)
> c
--------------------
Bake Controller
Path: /Applications/MAMP/htdocs/blog/app/Controller/
--------------------
\Use Database Config: (default/test)
[default] >
No matter what I put in for the database (if I leave it blank, it asks me again), but any answer gives me the following error:
Warning Error: PDO::__construct(): [2002] No such file or directory (trying to connect via unix:///var/mysql/mysql.sock) in [/Users/p_scott/cake221/lib/Cake/Model/Datasource/Database/Mysql.php, line 149]
Error: Database connection "SQLSTATE[HY000] [2002] No such file or directory" is missing, or could not be created.
#0 /Users/p_scott/cake221/lib/Cake/Model/Datasource/DboSource.php(260): Mysql->connect()
#1 /Users/p_scott/cake221/lib/Cake/Model/ConnectionManager.php(101): DboSource->__construct(Array)
#2 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ModelTask.php(906): ConnectionManager::getDataSource('default')
#3 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(396): ModelTask->getAllTables('default')
#4 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(419): ControllerTask->listAll(NULL)
#5 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(136): ControllerTask->getName()
#6 /Users/p_scott/cake221/lib/Cake/Console/Command/Task/ControllerTask.php(61): ControllerTask->_interactive()
#7 /Users/p_scott/cake221/lib/Cake/Console/Command/BakeShell.php(113): ControllerTask->execute()
#8 /Users/p_scott/cake221/lib/Cake/Console/Shell.php(393): BakeShell->main()
#9 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(201): Shell->runCommand(NULL, Array)
#10 /Users/p_scott/cake221/lib/Cake/Console/ShellDispatcher.php(69): ShellDispatcher->dispatch()
#11 /Users/p_scott/cake221/app/Console/cake.php(33): ShellDispatcher::run(Array)
#12 {main}
Once I started getting this error, I tried navigating in terminal to the <cake install dir>/app/Console folder and the <different instance of cake install dir>/app/Console folder to try the console from within my app/s. I either get the same errors or it asks me different questions, like:
What is the path to the project you want to bake?
[/Users/p_scott/myapp] > /Applications/MAMP/htdocs/history/app
What is the path to the directory layout you wish to copy?
[/Applications/MAMP/htdocs/history/lib/Cake/Console/Templates/skel] >
PHP CLI is installed and it appears to be working
PHP 5.3.8 (cli) (built: Dec 5 2011 21:24:09)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
My PDO support appears to be enabled. In terminal I typed:
php --ri pdo
PDO
PDO support => enabled
PDO drivers => mysql, sqlite, sqlite2
I don't have a php.ini file in Apache (because I am on a Mac), but the one in the PHP 5.36 directory, I have the following extensions enabled:
extension=imap.so
extension=yaz.so
extension=mcrypt.so
extension=gettext.so
extension=pgsql.so
extension=pdo_pgsql.so
extension=pdo_mysql.so
After taking a break, I found an article
(http://www.dereuromark.de/2011/10/31/freshly-baked-cake2-0-tips/) that talks about a change of console location in 2.0. I should try using it from that location (<cake installed dir>/lib/Cake/Console ). Once I tried this, I either got the questions about what layout I wanted to use or... ONCE, I was able to get the bake application to ask me to create a database configuration. I went through the steps and it pooped out this error at the end:
Fatal error: Class 'DATABASE_CONFIG' not found in /Applications/MAMP/htdocs/history/lib/Cake/Console/Command/Task/DbConfigTask.php on line 264
Which leads me to one more piece of info. This is my default DB configuration in the <cake installation dir>/history/app/Config/database.php file.
class DATABASE_CONFIG {
public $default = array(
'datasource' => 'Database/Mysql',
'persistent' => false,
'host' => 'localhost',
'login' => 'cakeHistoryUser',
'password' => 'cakeHistoryPassword',
'database' => 'cake_history',
'prefix' => '',
//'encoding' => 'utf8',
);
Before posting this question (and all of this information), I spend some quality time out here and it seems like most of my issues are or CLI related but I just don't see where I need to change something and hours and hours later, I need some help.
Help me Obi Wan, you are my only hope
The problem is you are trying to interact with the database via the command line, however the PHP-CLI is a different install than the one proveided by MAMP so it doesn't know about the database server.
Try changing localhost to 127.0.0.1 in your app/Config/database.php file and that should do the trick.
Something like this happened to me, and the easiest way I found to make it work which I don't see here is changing localhost to 127.0.0.1 and adding the port number at the end, e.g., MAMP uses port number 8899, so:
"mysql:host=127.0.0.1:8889"
Related
I have a very specific configuration that I have to hold until I can start moving feature from my old PHP 5 application to somewhere else.
I'm trying to tie my testing environment with PhpStorm but I cant figure it out. Since I'm not using Composer, I have to specify phpunit.phar path (which is /usr/local/bin/phpunit - a symlink to /usr/local/bin/phpunit.phar). I keep having this error.
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot create phar '/usr/local/bin/phpunit', file extension (or combination) not recognised or the directory does not exist' in /opt/.phpstorm_helpers/phpunit.php:181
Stack trace:
#0 /opt/.phpstorm_helpers/phpunit.php(181): Phar->__construct('/usr/local/bin/...')
#1 /opt/.phpstorm_helpers/phpunit.php(250): IDE_PHPUnit_Loader::init()
#2 {main}
thrown in /opt/.phpstorm_helpers/phpunit.php on line 181
The setup on my Docker is
PHP 5.5.9 with PHPUnit 4.8.9
My remote Docker PHP interpreter works in PhpStorm, and my PHPUnit works when I run test in bash (using docker exec phpunit) - so it seems that the pieces are working, mostly the glue doesn't work.
Here are my settings
I just ran into this problem with composer and the issue is you need to set up a PHPUnit interpreter in PHPStorm with the autoload.php file.
Open Settings > Languages & Frameworks > PHP > Test Frameworks
Click the Plus + icon to add a Remote Interpreter
Select the CLI interpreter previously defined and use existing path mappings
Select Use Composer Autoloader
Path to script should be /path/to/vendor/autoload.php
Check off Default configuration file and set it to /path/to/phpunit.xml
I also needed to have the following section in my docker-compose.yml:
services:
my-api:
# Other contents omitted
environment:
- PHP_IDE_CONFIG=serverName=my-api.company.com
Where my-api.company.com is the server definition name from Settings > Languages & Frameworks > PHP > Servers
I am trying to run the Magento Cron job but get this error message. I checked phpinfo() which shows everything should be loaded and the get_loaded_extensions() shows => PDO [27] => pdo_mysql [28] => pdo_sqlite [29]
Any thoughts what I can do next to find the cause?
Thanks,
Chris
PHP Fatal error: Uncaught exception 'Zend_Db_Adapter_Exception' with
message 'The PDO extension is required for this adapter but the extension is
not loaded' in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php:342
Stack trace:
#0 /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Abstract.php(248):
Zend_Db_Adapter_Pdo_Abstract->setFetchMode(2)
#1 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(175):
Zend_Db_Adapter_Abstract->__construct(Array)
#2 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource.php(110):
Mage_Core_Model_Resource->_newConnection('pdo_mysql', Object(Mage_Core_Model_Config_Element))
#3 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract.php(320):
Mage_Core_Model_Resource->getConnection('core_write')
#4 /home/k117235a/domains/greenman-chris.eu/private_html/app/code/core/Mage/Core/Model/Resource/Db/Abstract
in /home/k117235a/domains/greenman-chris.eu/private_html/lib/Zend/Db/Adapter/Pdo/Abstract.php
on line 342
Probably you are checking the phpinfo() from the browser, but the extension might be loaded just for apache/nginx, and not for commandline, which is how I'm assuming the cronjob php file will run.
Check that the extension is enabled for CLI, typically in the following location:
/etc/php5/cli/conf.d/20-pdo_mysql.ini (the name might not be exactly the same)
It might be only on /etc/php5/apache2/ or /etc/php5/php-fpm/
You can just copy it from the other locations or create a new file with the following content:
extension=pdo_mysql.so
After that check that the extension is loaded by running from command-line:
php -i | grep pdo
If it's loaded you should see some output and the cronjob should now work.
I hope it helps.
Use "$ which php" to ensure you're using the PHP you think you are.
Look at the php.ini your command line PHP is using and see if any extensions are disabled
An alternate method is to have Apache run the cron jobs by using wget:
[specified time] wget -q http://magento.url.com/cron.php
Using this method also helps in cases where file permissions are an issue (specially when Magento's cache is involved).
I am running into an issue with a customer's Drupal sites. He has a number of D6 installs, and a new D7 that he's just starting on. All of these sites are on the same shared hosting package.
The problem is when running certain drush commands only on the D7 site. There are no issues on the D6 sites. The specific error for drush up on the D7 site follows:
foo#bar [~/www/foo]# drush up
Command pm-update needs a higher bootstrap level to run - you will need to invoke drush [error]
from a more functional Drupal environment to run this command.
Command pm-update needs the following modules installed/enabled to run: update. [error]
The drush command 'up' could not be executed. [error]
Drush was not able to start (bootstrap) the Drupal database. [error]
Hint: This may occur when Drush is trying to:
* bootstrap a site that has not been installed or does not have a configured database. In
this case you can select another site with a working database setup by specifying the URI
to use with the --uri parameter on the command line. See `drush topic docs-aliases` for
details.
* connect the database through a socket. The socket file may be wrong or the php-cli may
have no access to it in a jailed shell. See http://drupal.org/node/1428638 for details.
Drush was attempting to connect to:
Drupal version : 7.28
Site URI : http://default
Database driver : mysql
Database username : username_foo
Database name : database_foo
PHP configuration :
PHP OS : Linux
Drush version : 7.0-dev
Drush temp directory : /tmp
Drush configuration :
Drush alias files :
Drupal root : /home/foo/www/foo
Site path : sites/default
Everything I can find (and indeed the link in the error message) say the solution is to change the host value in the settings.php file from localhost to 127.0.0.1. However, this has not been the solution for us.
The frontend site has no problems connecting to the database, and drush itself seemingly does in many cases too.
drush sql-connect will generate a string that you can use to connect to MySQL.
drush sql-cli will successfully connect to MySQL
The settings.php file is definitely in a folder called default (path: www/foo/sites/default) and I get the exact same error when specifying --root and --uri options.
Drush was originally a ~5.x release, and it had the same issues. We updated to the ~7.x to try to eliminate the error. The host value in settings.php has been localhost as well as 127.0.0.1 with equally poor results.
We've verified that MySQL is available via socket from the PHP CLI. Drush is up to date and a fresh install. The Drupal 7 site is a brand new fresh install.
I'm at a loss. Why would this work with the D6 sites, but not the D7? Any suggestions?
Is your settings.php file in a folder called 'default'? If not, you might need to tell Drush where to find it by using --uri=mysite.com or -l mysite.com.
There are several ways to specify which Drupal site Drush will target. The most basic option is fairly verbose; run:
$ drush --root=/path/to/drupal --uri=http://example.com status
You can do the same thing with a slightly different syntax:
$ drush /path/to/drupal#example.com status
You can also specify the Drupal site implicitly, by setting the cwd to the folder that contains the settings.php file for your site:
cd /path/to/drupal/sites/default # or /path/to/drupal/sites/mysite.com, as appropriate
$ drush status
In all of the cases above, if settings.php is in a folder called "default", then you do not need to specify the --uri component; you may, for example, cd /path/to/drupal followed by drush status, and the correct Drupal site will be found. If settings.php is not in a folder named 'default', then you will need to either specify --uri, or cd to the folder that contains the settings.php file.
Source
According to this message:
pm-update needs the following modules installed/enabled to run: update
Drush requires Update module to be enabled, so the following command should fix the problem:
drush -y en update
When I execute this command in my app path "./Console/cake acl_extras.acl_extras aco_sync" and I get the error, that this output:
Welcome to CakePHP v2.4.7 Console
---------------------------------------------------------------
App : app
Path: l:\server\htdocs\test\app\
---------------------------------------------------------------
Error: Database connection "Mysql" is missing, or could not be created.
#0 L:\server\htdocs\test\lib\Cake\Model\Datasource\DboSource.php(260): Mysql
->connect()
but the database connection is working
A bit late, but Cake's console was using a different php.ini. In that php.ini, the extension php_pdo_mysql.dll was commented out.
Once the extension was no longer commented out, the error disappeared.
Update
This was based on a WAMP installation. If you run a PHP script with only phpinfo(), you should find the following row:
Loaded Configuration File
In my case, it displays: C:\wamp\bin\apache\apache2.4.9\bin\php.ini. This was the ini file to modify.
I'm trying to use the migration tool, but am getting the following error:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] Connection refused' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382
Stack trace:
#0 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(330): CDbConnection->open()
#1 /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php(308): CDbConnection->setActive(true)
#2 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CModule.php(387): CDbConnection->init()
#3 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(442): CModule->getComponent('db')
#4 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(451): MigrateCommand->getDbConnection()
#5 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(482): MigrateCommand->getMigrationHistory(-1)
#6 /Applications/MAMP/htdocs/yii-sandbox/framework/cli/commands/MigrateCommand.php(84): MigrateCommand->getNewMigrations()
#7 [internal function]: MigrateCommand->actionUp(Array)
#8 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommand.php(172): ReflectionMethod->invokeArgs(Object(MigrateCommand), Array)
#9 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleCommandRunner.php(71): CConsoleCommand->run(Array)
#10 /Applications/MAMP/htdocs/yii-sandbox/framework/console/CConsoleApplication.php(92): CConsoleCommandRunner->run(Array)
#11 /Applications/MAMP/htdocs/yii-sandbox/framework/base/CApplication.php(180): CConsoleApplication->processRequest()
#12 /Applications/MAMP/htdocs/yii-sandbox/framework/yiic.php(33): CApplication->run()
#13 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic.php(7): require_once('/Applications/M...')
#14 /Applications/MAMP/htdocs/yii-sandbox/projects/trackstar/protected/yiic(4): require_once('/Applications/M...')
I have checked the DB settings in console.php, which are as follows:
'db'=>array(
'connectionString' => 'mysql:host=127.0.0.1;dbname=yii_trackstar, unix_socket=/Applications/MAMP/tmp/mysql/mysql.sock',
'emulatePrepare' => true,
'username' => 'yii',
'password' => 'xxx',
'charset' => 'utf8',
),
As you can see, I've tried setting the host to 127.0.0.1 and setting the unix socket as per other suggestions.
I'm using MAMP (as you can see). from the protected dir, I'm running the command: ./yiic migrate
No matter what I change, I get the same error message.
*Update: *
I've just realized something. Changing the host=localhost to host=127.0.0.1 actually gives me a different error of connection refused. If I set that back to localhost the error is as follows:
exception 'CDbException' with message 'CDbConnection failed to open the DB connection: SQLSTATE[HY000] [2002] No such file or directory' in /Applications/MAMP/htdocs/yii-sandbox/framework/db/CDbConnection.php:382
You can check the yii framework forum, there is already similar question posted at http://www.yiiframework.com/forum/index.php/topic/16-db-connection-string
NOTE
Specifically, what solved it is this from that thread:
A note on PHP and Mac OSX:
A version of PHP4 comes bundled on Mac OSX and is typically what is executed when you try the php command from the command line. You need to have the php command execute a version of PHP5.x or higher. Usually, you have already installed a version of PHP5.x or higher, but need to tell the php command to execute the newer version rather than the older one. There are certainly many ways to achieve this, but here is one:
At any terminal prompt, type in:
prompt>which php
this should tell you where the OS is looking for the php command tells me /usr/bin/php.
If I navigate to /usr/bin and issue an ls *php* I will see three files:
php
php-config
phpize
These are all for the bundled version PHP4.x
Rename these files to use a 4 in their names, to remember these are the executables for PHP4
mv php php4
mv php-config php-config4
mv phpize phpize4
Then, create sym links for each of these these to point to the PHP5.x or higher version you have installed. In my case these are located in /usr/local/apache/php/bin. So I would issue from the /usr/bin directory
ln -s [absolute path to your php5.x] php
and similarly for the other files.
While running yyic I've got problems until I've changed localhost to 127.0.0.1 in the connection string.
Try specifying the port in the host string. So localhost:8889 instead of just localhost or 127.0.0.1 — whichever you use.
This fixed my issue.
You can try setting the unix_socket with the correct keyword Socket and in the same way as the other vars in the string with ; and no spaces:
'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar;Socket=/Applications/MAMP/tmp/mysql/mysql.sock',
You can check more connection strings over here: http://www.connectionstrings.com/mysql
Try setting host=127.0.0.1 on your db.php file
Simple Solution:
Just open the mail-local.php page inside backend/common/config directory. Then change localhost to 127.0.0.1 .
Now you run php yii migrate .
Hope, It will successfully create the tables in Databse
change connection string to this
'connectionString' => 'mysql:host=localhost;dbname=yii_trackstar',
Open your terminal and use this
echo "export PATH=/Applications/MAMP/bin/php/php5.x.x/bin:$PATH" >> ~/.profile
5.x.x is your version of PHP you use
This is because Yii framework use your default PHP come with OSX, not the PHP of MAMP.
To make sure, type "which php" to see if it's /Applications/MAMP/bin/php/php5.x.x/bin/php then you are done.
Hope this help :)
It's a mac problem where it uses an older version of php that is installed on the machine as opposed to the php5 that comes with MAMP. So I had to force it to use PHP version 5 that comes with MAMP.
So I had to write this in the Terminal and it worked:
/Applications/MAMP/bin/php/php5.5.3/bin/php /Applications/MAMP/htdocs/projectname/protected/yiic migrate
Edit file config/db.php
return [
'class' => 'yii\db\Connection',
'dsn' => 'mysql:host=localhost;dbname=namedb',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
];
MAMP PRO click Enable Allow access to MySql at Mysql Menu.