Laravel 4.2 - NotFoundHttpException - php

I've just started building a Laravel application and came across a problem with routing.
Laravel version - 4.2
PHP version - 5.5
I'm using XAMPP
I have the rewrite module active on Apache
Here is my Routes file:
<?php
Route::get('/', array(
'as' => 'index',
'uses' => 'IndexController#index'
));
Route::get('/account', array(
'as' => 'account',
'uses' => 'AccountController#get_create'
));
My controllers look like this:
<?php
class IndexController extends BaseController
{
public function index()
{
return View::make('index');
}
}
<?php
class AccountController extends BaseController
{
public function get_create()
{
return 'asd';
}
public function post_create()
{
}
}
Here is my error:
Symfony\Component\HttpKernel\Exception\NotFoundHttpException thrown with message ""
Stacktrace:
#11 Symfony\Component\HttpKernel\Exception\NotFoundHttpException in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:5680
#10 Illuminate\Routing\RouteCollection:match in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:5004
#9 Illuminate\Routing\Router:findRoute in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:4992
#8 Illuminate\Routing\Router:dispatchToRoute in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:4984
#7 Illuminate\Routing\Router:dispatch in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:715
#6 Illuminate\Foundation\Application:dispatch in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:696
#5 Illuminate\Foundation\Application:handle in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:7744
#4 Illuminate\Session\Middleware:handle in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:8351
#3 Illuminate\Cookie\Queue:handle in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:8298
#2 Illuminate\Cookie\Guard:handle in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:10961
#1 Stack\StackedHttpKernel:handle in C:\xampp\htdocs\Protosite\bootstrap\compiled.php:657
#0 Illuminate\Foundation\Application:run in C:\xampp\htdocs\Protosite\public\index.php:49
EDIT: One thing I forgot to mention, the index works fine, it's the account page with the error.
I've looked at similar problems but for some reason they have not solved it.
Cheers!

It sounds like your rewriting isn't working. If you add index.php to the URL right before the /account does it work?
For example, yourdomain.com/account would become yourdomain.com/index.php/account
If your rewriting isn't working, but you have the .htaccess file in your public directory, then you probably need to allow overrides in your apache configuration. Here is an example virtual host configuration for XAMPP and Laravel.
I've marked the lines you need to change. Change the first and third to point to the public directory in your website's directory. Then change the second line to the domain name you're using with your website.
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/yourdomain/public" # Change this line
ServerName yourdomain.com # Change this line
<Directory "C:/xampp/htdocs/yourdomain/public"> # Change this line
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride All # This line enables .htaccess files
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You'll need to restart Apache for these settings to take effect.

Related

Laravel route not found when route exists

When I try to access my laravel site I get this error in the console.
Laravel development server started: <http://127.0.0.1:8000>
[Mon Nov 16 10:39:15 2020] PHP Fatal error: Uncaught InvalidArgumentException: Route [home] not defined. in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:389
Stack trace:
#0 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(822): Illuminate\Routing\UrlGenerator->route('home', Array, true)
#1 /Users/threeaccents/code/src/gitlab.com/few/bodylove/storage/framework/views/e071ac62e490c49233841ae8b6b3906075bc0187.php(6): route('home')
#2 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): include('/Users/threeacc...')
#3 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/threeacc...', Array)
#4 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\Vi in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 389
[Mon Nov 16 10:39:15 2020] PHP Fatal error: Uncaught InvalidArgumentException: Route [home] not defined. in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php:389
Stack trace:
#0 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Foundation/helpers.php(822): Illuminate\Routing\UrlGenerator->route('home', Array, true)
#1 /Users/threeaccents/code/src/gitlab.com/few/bodylove/storage/framework/views/e071ac62e490c49233841ae8b6b3906075bc0187.php(6): route('home')
#2 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(43): include('/Users/threeacc...')
#3 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(59): Illuminate\View\Engines\PhpEngine->evaluatePath('/Users/threeacc...', Array)
#4 /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/View/View.php(142): Illuminate\Vi in /Users/threeaccents/code/src/gitlab.com/few/bodylove/vendor/laravel/framework/src/Illuminate/Routing/UrlGenerator.php on line 389
But route home is clearly defined. I even set it at the top of my route file to make sure nothing else was overriding it.
routes/web.php
<?php
// New Home Page for App
Route::get('/', 'Web\HomeController#index')->name('home');
...
with php artisan route:list
+--------+----------------------------------------+--------------------------------------------------------------------------------------------+--------------------------------------------+------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Domain | Method | URI | Name | Action | Middleware |
+--------+----------------------------------------+--------------------------------------------------------------------------------------------+--------------------------------------------+------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| | GET|HEAD | .well-known/apple-developer-merchantid-domain-association | | App\Http\Controllers\Web\ApplePayDomainVerificationController | web |
| | GET|HEAD | / | home | App\Http\Controllers\Web\HomeController#index | web |
Update
I've cleared route cache, deleted vendor folder, re-installed PHP but nothing seems to solve the issue.
I've tried it on my work laptop (same setup) and everything works. It seems to be an issue with my current station but I'm not sure what would be causing it. I'm using PHP 7.2 on a mac os 10.14.4. Laravel 5.7
I also thought maybe it was an overall system issue but if I create a new laravel project everything works as expected so it does seem to be a project specific issue.
It was an issue with my apache config. It seems on my latest brew update apache got updated and the config file changed a bit. I had to change
#
# Deny access to the entirety of your server's filesystem. You must
# explicitly permit access to web content directories in other
# <Directory> blocks below.
#
<Directory />
AllowOverride none
Require all denied
</Directory>
to
<Directory />
AllowOverride all
Require all granted
</Directory>
Route like that is doesn't work except you edit the RouteServiceProvider
There is new version of laravel, please make sure you upgrade your PHP or XAMPP and try to update the composer global laravel and last create a new laravel project.
See Laravel documentation
And this post
https://youtu.be/MfE1tnMG6fE
You can remove name('home'), because error is Route [home] not defined
<?php
// New Home Page for App
Route::get('/', 'Web\HomeController#index');

Cakephp prefix routing not working on Linux - but works on Windows

I have a CakePHP 3 app and it has different plugins. The plugins appear to load and accessing them on a dev Windows machine, WAMP, it all works fine.
Once on the CentOS server, the plugin's prefix routing eg 'admin' stops working, getting a missing controller error:
Log error:
2018-04-11 12:40:23 Error: [Cake\Routing\Exception\MissingControllerException] Controller class Contacts could not be found.
Exception Attributes: array (
'class' => 'Contacts',
'plugin' => 'Contacts',
'prefix' => 'admin',
'_ext' => NULL,
)
Request URL: /myapp/contacts/admin/contacts
Referer URL: https://***/myapp/anotherplugin/participants
Stack Trace:
#0 /srv/www/myapp/myapp-app/webroot/index.php(36): Cake\Routing\Dispatcher->dispatch(Object(Cake\Network\Request), Object(Cake\Network\Response))
#1 /srv/www/myapp/myapp-app/index.php(16): require('/srv/www/mya...')
#2 {main}
The controller does exists and contains:
namespace Contacts\Controller\Admin;
use Contacts\Controller\AppController;
use Cake\ORM\TableRegistry;
use Authentication\Utility\TimeUtility;
use Cake\I18n\Time;
use Cake\Core\Configure;
class ContactsController extends AppController{
Non-prefix routing seems fime. The plugins are added in bootstrap.php like this:
Plugin::load('Contacts', ['bootstrap' => false, 'routes' => true]);
In plugins routing file:
<?php
use Cake\Routing\Router;
Router::plugin('Contacts', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
Router::plugin('Contacts', function ($routes) {
$routes->prefix('admin', function ($routes) {
$routes->fallbacks('InflectedRoute');
});
});
In Apache the app is setup as an alias with mod rewrite - both on WAMP and on the CentOS server:
http://server-or-localhost/myapp/
Differences between local and server:
Server is Linux, uppercase/lower case issues?
Same PHP versions, but
maybe some modules missing on server PHP?
The server redirects http to https
Blast! Check your CakePHP version 3.2.0 has this bug. Fixed in 3.2.1.
https://bakery.cakephp.org/2016/01/30/cakephp_3110_and_321_released.html
It's working now.

Laravel 5.5: PHPUnit (with coverage) doesn't like routes from multiple files and throws "A facade root has not been set". Without coverage it's green

I have Laravel 5.5 where I decided to group routes in files to organise them in a more meaningful way.
Here's a simplified example - the web route files live in:
app/Http/Routes/Web/static.php
app/Http/Routes/Web/test.php
static.php contains:
<?php
declare(strict_types=1);
namespace Foo\Http\Routes\Web;
use Illuminate\Support\Facades\Route;
Route::get('/', function () {
return view('welcome');
});
test.php contains:
<?php
declare(strict_types=1);
namespace Foo\Http\Routes\Web;
use Illuminate\Support\Facades\Route;
Route::get('/test', function () {
return 'test'; // just to simplify
});
RouteServiceProvider.php contains:
<?php
declare(strict_types=1);
namespace Foo\App\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
protected $namespace = 'Foo\Http\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* #return void
*/
public function boot()
{
//
parent::boot();
}
/**
* Define the routes for the application.
*
* #return void
*/
public function map()
{
$this->mapWebRoutes();
}
protected function mapWebRoutes()
{
Route::group([
'middleware' => 'web',
'namespace' => $this->namespace,
], function($router) {
require app_path('Http/Routes/Web/static.php');
require app_path('Http/Routes/Web/test.php');
// more files will land here in the future
});
}
}
Up to now I can confirm that everything works by calling php artisan route:list:
Now I was going to write some tests but I require code coverage, so I added:
<logging>
<log type="coverage-html" target="./report" charset="UTF-8"
yui="true" highlight="true"
lowUpperBound="50" highLowerBound="80"/>
</logging>
into my phpunit.xml.
When I call phpunit I get:
PHPUnit 7.0.1 by Sebastian Bergmann and contributors.
PHP Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/slick/Code/foo/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:218
Stack trace:
#0 /Users/slick/Code/foo/app/Http/Routes/Web/static.php(10): Illuminate\Support\Facades\Facade::__callStatic('get', Array)
#1 phar:///usr/local/Cellar/phpunit/7.0.1/libexec/phpunit-7.0.1.phar/php-code-coverage/CodeCoverage.php(929): include_once('/Users/slick/Co...')
#2 phar:///usr/local/Cellar/phpunit/7.0.1/libexec/phpunit-7.0.1.phar/php-code-coverage/CodeCoverage.php(243): SebastianBergmann\CodeCoverage\CodeCoverage->initializeData()
#3 phar:///usr/local/Cellar/phpunit/7.0.1/libexec/phpunit-7.0.1.phar/phpunit/Framework/TestResult.php(671): SebastianBergmann\CodeCoverage\CodeCoverage->start(Object(Tests\Feature\ExampleTest))
#4 phar:///usr/local/Cellar/phpunit/7.0.1/libexec/phpunit-7.0.1.phar/phpunit/Framework/TestCase.php(687): PHPUnit\Framework\TestResult->run(Object(Tests\Feature\ExampleTest))
#5 phar:///usr/local/Cell in /Users/slick/Code/foo/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 218
Fatal error: Uncaught RuntimeException: A facade root has not been set. in /Users/slick/Code/foo/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php on line 218
Straight after I remove the coverage lines I added to xml file and run phpunit again - it's green.
$ phpunit PHPUnit 7.0.1 by Sebastian Bergmann and contributors.
.. 2
/ 2 (100%)
Time: 381 ms, Memory: 20.00MB
OK (2 tests, 2 assertions)
What's wrong? Why phpunit with code coverage doesn't like routes in multiple files (but without coverage it works perfectly fine)?
Someone had the same issue and fixed that by excluding routes directories from code coverage. So I added into phpunit.xml:
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
<exclude>
<directory suffix=".php">./app/Http/Routes</directory>
</exclude>
</whitelist>
</filter>
And phpunit with coverage works good.
Goshh… facades are tricky.

Laravel 5 / Apache 2.4.9 Configuration problems

I am trying to install and configure Laravel 5 on a CentOS brand new server.
But I am afraid I don't have enough knowledge to understand and fix what is wrong with my environment. So I will try to describe as accurate as I can my actual setup and problems.
Let's start with Apache 2.4.9
Everything in the httpd.conf is almost default. I just edited the document root path to point directly at the future laravel public folder:
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/usr/local/apache/htdocs/public"
<Directory "/usr/local/apache/htdocs/public">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options -Indexes -FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
And before you ask, yes the mod_rewrite module is enabled.
Then my PHP also has basic configuration and it's version is 5.6.15.
Then I installed composer and used it to create a new laravel project
composer create-project laravel/laravel {directory} "~5.0.0" --prefer-dist
Everything successfully ran with no issues.
But now I try to visit my freshly installed laravel app by entering my server IP address but it only displays a blank page and if I check the console it gives me an 500 error.
So here is in order what I did to try to fix the problem:
I found a post on the laravel blog that said we should give full right to the /storage folder which I did and now I don't have a white page anymore but instead I have the: 'whoops something went wrong' error.
I try the alternate .htaccess config file suggested on the official laravel doc - nothing changed
I don't why exactly I did this but I ran the php artisan serve command and now I see the Laravel welcome page... even if I exit the serve mode it still runs ?!? I am not sure if I understand why but even if I did it actually doesn't work completely... I only get the welcome page but if I try http://my-ip-address/home it shows me a 404 not found.
I feel like I have searched everywhere but yet I couldn't find an answer and I am close to the depression. Does anyone here has any clues about my problem ?
Thanks to anyone who can help me with this !
#update
Sorry I forgot the server logs:
[2015-12-17 04:22:03] production.ERROR: exception 'ReflectionException' with message 'Class encrypter does not exist' in /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php:776
Stack trace:
#0 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(776): ReflectionClass->__construct('encrypter')
#1 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('encrypter', Array)
#2 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Container\Container->make('encrypter', Array)
#3 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(887): Illuminate\Foundation\Application->make('Illuminate\\Cont...')
#4 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(848): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter))
#5 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(813): Illuminate\Container\Container->getDependencies(Array, Array)
#6 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Container/Container.php(656): Illuminate\Container\Container->build('Illuminate\\Cook...', Array)
#7 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(613): Illuminate\Container\Container->make('Illuminate\\Cook...', Array)
#8 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(127): Illuminate\Foundation\Application->make('Illuminate\\Cook...')
#9 /usr/local/apache/htdocs/public/index.php(57): Illuminate\Foundation\Http\Kernel->terminate(Object(Illuminate\Http\Request), Object(Symfony\Component\HttpFoundation\Response))
#10 {main}
[2015-12-17 04:22:03] production.ERROR: exception 'ErrorException' with message 'file_put_contents(/usr/local/apache/htdocs/vendor/services.json): failed to open stream: Permission denied' in /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Filesystem/Fi$
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'file_put_conten...', '/usr/local/apac...', 74, Array)
#1 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php(74): file_put_contents('/usr/local/apac...', '{\n "provider...', 0)
#2 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(193): Illuminate\Filesystem\Filesystem->put('/usr/local/apac...', '{\n "provider...')
#3 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(139): Illuminate\Foundation\ProviderRepository->writeManifest(Array)
#4 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php(59): Illuminate\Foundation\ProviderRepository->compileManifest(Array)
#5 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(439): Illuminate\Foundation\ProviderRepository->load(Array)
#6 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/RegisterProviders.php(15): Illuminate\Foundation\Application->registerConfiguredProviders()
#7 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(167): Illuminate\Foundation\Bootstrap\RegisterProviders->bootstrap(Object(Illuminate\Foundation\Application))
#8 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(195): Illuminate\Foundation\Application->bootstrapWith(Array)
#9 /usr/local/apache/htdocs/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(106): Illuminate\Foundation\Http\Kernel->bootstrap()
This is the 2 errors I get.
Sorry I couldn't add a comment.
I think you might be missing the php-mcrypt extension.
First generate key for laravel 5.1 application using below command.
e.g.
$ php artisan key:generate
Application key [Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3] set successfully.
Now copy this key and paste it in yourproject/config/app.php
'key' => 'Idgz1PE3zO9iNc0E3oeH3CHDPX9MzZe3',
Try this:
sudo chmod 775 /usr/local/apache/htdocs/vendor/services.json
Sorry, I haven't replied during the weekend, I was a bit busy.
Everybody had a bit of right in their answers. It was definetlely directories permission problem. I haven't found yet the perfect level of permission because I am not an expert. But I can tell you if I chmod -R 777 /storage /vendor and /public it works.
I know chmod 777 is probably insecure but I am really not an expert in permissions..
But anyway I'll mark this answer as solved because I indeed solved my problem in a way :)
But if anybody has a better answer or would like to give a more detailled explanation I'll update this post or mark the best answer as solved.

cake console 2.2.1: Bake errors

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"

Categories