Class not found error when moving to host? - php

I am trying to make a new Facebook app and got hosting from Asmallorange. The app works perfectly in my local environment that is running PHP 5.5.14.
The app consists of packages that were imported by Composer and autoloaded in my app.
The app in itself is a Slim app and consists of Laravel's Eloquent ORM. I followed tutorials online to integrate those two, and it works perfectly in my local environment.
The code is as follows.
require 'vendor/autoload.php';
use Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection(array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'test',
'username' => 'test',
'password' => 'password',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => ''
));
$capsule->bootEloquent();
It works perfectly in my local environment. Just not on the server and fails with this:
PHP Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found in /home/moz/public_html/app/index.php
Referring to line 2 above. I have looked everywhere and couldn't find a solution yet.

Check that your deployment tool has uploaded the autoload_classmap.php file found in the vendors/composer directory. Uploading this should fix the problem.
Alternatively you could get composer to rebuild the autoload_classmap.php file on the server by running the following in the command line from same directory as composer...
php composer dump-autoload

Related

Integrating Sentinel with a script

I'm trying to use Cartalyst Sentinel for my scripts. I've downloaded the files from github. (https://github.com/cartalyst/sentinel). I've put it on my wamp, and I am trying to follow the instructions here (https://cartalyst.com/manual/sentinel/2.0#native).
This is what I have so far:
<?php
// Import the Sentinel Classes
use sentinel\src\Native\Facades\Sentinel;
use Illuminate\Database\Capsule\Manager as Capsule;
require 'vendor/autoload.php';
$capsule = new Capsule;
$capsule->addConnection([
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'sentinel',
'username' => '',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]);
$capsule->bootEloquent();
?> code here
I've followed the instructions but I have changed the directory from the first use... I cannot seem to find vendor/autoload.php. I get the cannot find stream error.
and when I remove that, I get this error.
( ! ) Fatal error: Class 'Illuminate\Database\Capsule\Manager' not found in C:\wamp\www\lab\login.php on line 10
So I'm kind of confused since the manual isn't really providing ways to solve problems and what we need.
Any help would be greatly appreciated!
It seems you have not updated later with the implementation for the Illuminate Database component.
To use it run:
composer require illuminate/database illuminate/events symfony/http-foundation
This will install Illuminate\Database\Capsule hope this works.
I am 4 years late to answer this but believe that this might help someone struggling.

Laravel/MySQL database connection

I have an unusual problem with my Laravel 4.2 project connecting to MySQL database. This is my database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'database_name',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
)
I use XAMPP for Ubuntu.
First, I've created a database in phpMyAdmin. When I tried to run php artisan migrate, it gave me an error of unknown database 'database_name'. I thought it was silly since I've just created a database in phpMyAdmin. Then I tried creating a database through the command line and tried running the migration again. It worked. Tables were created under the database I specified when I run show tables in the command line. It seems to me that the Laravel project is connected to a different mysql server than the phpMyAdmin. Is that even possible? How can I solve this problem?
I've been trying to solve this for hours but still, no luck. Hope someone can help me with my problem.
I solved the problem by following the solution in the link provided by Bulk. I just have to run sudo /opt/lampp/bin/php artisan migrate instead of the plain php artisan migrate. With this, artisan will use the MySQL version provided by XAMPP.

Laravel environment config not loading, migration fails - SQLSTATE[HY000] [2002] No such file or directory

My app/config/database.php has been setup like this:
'mysql' => array(
'driver' => 'mysql',
'host' => getenv('DB_HOST'),
'database' => getenv('DB_NAME'),
'username' => getenv('DB_USER'),
'password' => getenv('DB_PASS'),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
I have updated my env detection code like this in bootstrap/start.php:
$env = $app->detectEnvironment(function() {
return file_exists(dirname(__FILE__) . '/../.env.production.php')
?
'production'
:
'local';
});
Now, I have uploaded .env.production.php with the following:
<?php
return
[
'DB_HOST' => '178.xxx.xxx.xxx',
'DB_NAME' => 'USERNAME',
'DB_USER' => 'PASSWORD',
'DB_PASS' => 'DBNAME',
];
I tested the environment detection like this:
[www-data#server]$ php artisan env
Current application environment: production
As you can see, it's working as intended. I then proceeded to run the migration like this:
php artisan migration:install
When I do, I get the following error:
[www-data#server]$ php artisan migrate:install --env=production
[PDOException]
SQLSTATE[HY000] [2002] No such file or directory
migrate:install [--database[="..."]]
Any idea why this might be? it looks like it's failing to load the .env.production.php file.
Does anyone know how to fix this error? Thanks in advance.
In the Laravel 4 docs it states that it needs to be .env.php on your production server.
Now, on your production server, create a .env.php file in your project
root that contains the corresponding values for your production
environment. Like the .env.local.php file, the production .env.php
file should never be included in source control.
So simply change your environment detection code to this
$env = $app->detectEnvironment(function() {
return file_exists(dirname(__FILE__) . '/../.env.php')
?
'production'
:
'local';
});
Note - you still use .env.local.php on your development server.

Changing database name in Laravel/Homestead

I started learning Laravel just an hour ago and following tutorials.
My settings for database are as follow (File: app/config/database.php):
'default' => 'mysql',
'connections' => array(
'sqlite' => array(
'driver' => 'sqlite',
'database' => __DIR__.'/../database/production.sqlite',
'prefix' => '',
),
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'laraveltest',
'username' => 'root',
'password' => 'secret',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
In mySQL on homestead, I already created laraveltest database. I also created migration file in database/migration directory with following code:
public function up()
{
Schema::create('users', function($table)
{
$table->increments('id');
$table->string('email')->unique();
$table->string('name');
$table->timestamps();
});
}
and migration commands were:
vagrant#homestead:~/Code/Laravel$ php artisan migrate
Migration table created successfully.
Migrated: 2014_08_14_195103_create_users_table
As displayed, table users created but in homestead database, not in laraveltest database. Can someone please tell where I went wrong and how to force laravel to use laraveltest database?
Edit after first comment
File: bootstrap/start.php
$env = $app->detectEnvironment(array(
'local' => array('homestead'),
));
It is most likely an issue with environments. Check that you have a database configuration file in app/config/local/, and check that it has the proper settings.
If anyone finds this looking for the answer for Laravel 5 or later: It's the same as #camroncade says, but in this case it's your .env file in the project root you want to look at.
I am currently dealing with this issue as well. Changed the .env file numerous times as well as the config.php file. Nothing seemed to work.
After having done some deep digging into the framework I have found an acceptable temporary workaround to the problem that does not conflict with ANY of Laravel 5.0.2's Exceptions.
NOTE: I'm currently using Ampps 3.4 with php 7.0.2 phpmyadmin 4.4.15.1 on a Windows 8.1 OS.
Inside of the file "ConnectionFactory.php" (located at "laravel\vendor\laravel\framework\src\Illuminate\Database\Connectors"),
scroll down to the public function make located at line 41.
Within this function you can do the following after this statement $config = $this->parseConfig($config, $name); which should be on line 43:
$config['database'] = 'Insert the name of your database here';
This change will allow Laravel to continue with its normal process having no negative effect anywhere with the framework or your project. That is until this bug is fixed by the makers of Laravel or the community.
Till then happy coding! =)

Install of laravel 4 from pagodabox breaks on localhost

How do I get laravel to work on local host from pagodabox? I've installed laravel 4 through pagoda box, then cloned it to localhost. I then ran composer install to get all the dependencies and updates. When I try to navigate the URI to the public directory, it doesn't show me a "you have arrived" screen. Instead I get the following error message:
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. [tcp://tunnel.pagodabox.com:6379]
I then looked in "database.php" and noticed that the redis array was modified, so I copied the same one from a fresh installation of Laravel, but then I got the following error:
No connection could be made because the target machine actively refused it. [tcp://127.0.0.1:6379]
I Had the same problem, just change the bootstrap > start.php file, search for
'local' => array('your-machine-name')
and change it with your machine name.
This video help me to deal with that: http://www.youtube.com/watch?v=CJoU-LO8Ufo , in the video he changes it to the virtual host but that didn't work for me, i had to put my computer name.
On Mac the computer name can be found by typing hostname in the terminal.
Joshdcid's answer is right for some, but not all. I found this in my bootstrap > start.php file:
'local' => array('homestead')
..., and changing that variable in any way caused my laravel app to not load at all. Not only that, but in a fresh install of laravel, this local variable had the same value of 'homestead'.
After spending a bit of time in WinMerge, I found that you should use Wayne's tip of changing
'redis' => array(
'cluster' => false,
'default' => array(
'host' => 'tunnel.pagodabox.com',
'port' => 6379,
'database' => 0,
),
),
to
'redis' => array(
'cluster' => false,
'default' => array(
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
),
),
at the bottom of the app > config > database.php file, then you should also go to the top of the
app > config > session.php file and change
'driver' => 'redis',
to
'driver' => 'file',
..., just as a fresh install would have. You should be able to view your app now!

Categories