how to import Laravel 4.2 live project into locallhost - laravel

i am importing a live Laravel 4.2 Web application and setup it into my localhost for development.
in the Laravel 5 we usually find the .env file in the root dictionary but in Laravel 4.2 i couldn't be able to find .env and another component and their dictionaries are also different.
can anybody tell me how to import my laravel 4.2 web app into the local host step by step?

All of the configuration files for the Laravel framework are stored in the app/config directory 1. You have to set everything directly there or build an own .env.local.php file with default values like this:
<?php
//file: /.env.local.php
// return the configuration for the 'local' environment
return array(
'db_host' => '127.0.0.1',
'db_name' => 'DB_NAME', // specify database name
'db_user' => 'DB_USER', // specify database username
'db_pass' => 'DB_PASS', // specify database password
);

Related

Stancl\Tenancy\Exceptions\NotASubdomainException Hostname DOMAIN.COM does not include a subdomain

I am using Laravel Forge with AWS EC2 Instance to build a CI/CD Pipeline for a SAAS Laravel project.
Error Attachment: https://i.stack.imgur.com/hsMdK.png
The configurations are fine but when it comes to a tenancy-based project I get this error.
(Stancl\Tenancy\Exceptions\NotASubdomainException
Hostname domain.com does not include a subdomain)
Note: I am using TenancyForLaravel package
I got it fixed in 2 steps.
It wasn't a server-side issue.
1st Step
The TenancyForLaravel package was making an impact, I need to add initializing code for sub-domains in my laravel project.
app/Providers/TenancyServiceProvider.php
public function boot() {
\Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain::$onFail =
function () {
return redirect(env('CENTRAL_DOMAIN'));
};
}
2nd Step
In your laravel root folder
/config/tenancy.php
add your domain name in central_domain
'central_domains' => [
'127.0.0.1',
'localhost',
'domain.com',
],

CodeIgniter 4 plus Myth/Auth throws error when running Migrations via php spark migrate -all

I have discovered some wired behavior, I have that one CI4 project i am working on since a couple of weeks. everything is working just fine, but until now i have just been working with the project on my local machine. When i wanted to run the project on my Laptop in ran into an error when i tried to run the migrations with php spark migrate -all
CodeIgniter CLI Tool - Version 4.0.4 - Server-Time: 2020-07-20 06:16:02am
Running all new migrations...
An uncaught Exception was encountered
Type:        CodeIgniter\Database\Exceptions\DatabaseException
Message:     Unable to connect to the database.
Filename:    /opt/lampp/htdocs/sms/vendor/codeigniter4/framework/system/Database/BaseConnection.php
Line Number: 425
The project includes Myth/auth, so i tried just to run "my" migration with php spark migrate . That just worked fine, no problem at all, the tables are there, no errors. Just for fun, i moved my Math/auth migrations from the vendor folder to the "normal" Database/Migrations folder and was able to migrate them that way.
That's very wired, especially since everything is working just fine on the PC I have been using before. There I am able to run the migrations using php spark migrate -all without any errors, when is set up a fresh MySQL/MariahDB database. But somehow only there.
I was able to reproduce the error on my laptop on my Manjaro partition, my Windows 10 partition and on my iMac.
So if you want to reproduce the error do the following:
composer create-project codeigniter4/appstarter whatever
rename the env to .env
set CI_ENVIRONMENT = development and obviously uncomment that line
configure and uncomment your database setting in the .env
create a sample migration like the one from the docs using > php spark migrate:create AddBlog
add the following content to the new migration and save the file:
forge->addField([
'blog_id' => [
'type' => 'INT',
'constraint' => 5,
'unsigned' => true,
'auto_increment' => true,
],
'blog_title' => [
'type' => 'VARCHAR',
'constraint' => '100',
],
'blog_description' => [
'type' => 'TEXT',
'null' => true,
],
]);
$this->forge->addKey('blog_id', true);
$this->forge->createTable('blog');
}
public function down()
{
$this->forge->dropTable('blog');
}
}
run > composer require myth/auth
Edit app/Config/Email.php and verify that a fromName and fromEmail are set as that is used when sending emails for password reset, etc.
Edit app/Config/Validation.php and add the following value to the ruleSets array: \Myth\Auth\Authentication\Passwords\ValidationRules::class
Ensure your database is setup correctly, then run the Auth migrations: php spark migrate -all
As a result you will also have the above error. I was not able to
get around that error, except for the system in was working with at
first.
If you just use php spark migrate it will migrate the sample migration without any errors
I am running CI 4.04 on Kubuntu 18.04 LTS, running apache2.4.29 and PHP 7.4.9
The short answer is...
Using php spark migrate -all searches everywhere it knows about for Database/Migrations Folders and files.
There just so happens to be a such folder/file under
tests/_support/Database/Migrations/2020-02-22-222222_example_migration.php
The bits added to make the short answer longer
So the Database error we are seeing is due to not having set up Database credentials for $tests in /app/Config/Database.php
All it's doing is looking to connect to the DB set up under $tests, but appears not to actually run as we don't want it to.
That appears to be enabled when ENVIRONMENT is set to "testing".
So 3 options for the time being...
Ignore the error. But that always leaves you wondering what's really happening.
Setup the credentials for the $tests Database. (Not really warranted.) OR
Delete/Rename the tests folder if you are not using it. (Stop it finding it.)
Would be to use the -n switch/option and specify the namespace to use (but not sure that's working.)
Changing DB hostname to '127.0.0.1' from localhost in your .env file usually solves the problem of running any migrations from the command line.
Open your PHP.ini file, find this :
;extension=sqlite3
and remove the semicolon to activate sqlite3. You need this library in Codeigniter 4 in order to use FORGE.

Fatal error with Stripe Class 'Stripe\Stripe' not found

I'm trying to implement Stripe Checkout into my website. In local the api work normal but in host I get the error :
Class 'Stripe\Stripe' not found
Note: In my host I don't have SSH. And I added files manually with FTP.
\Stripe\Stripe::setApiKey("sk_test_XXXXXX");
$token = $request->stripeToken;
$customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);
As mentioned you have installed Stripe library manually and uploaded on server.
To use this library include init file.
require_once('/path/to/stripe-php/init.php');
ON next step set Api key, Make sure to use test api key for testing.
\Stripe\Stripe::setApiKey( "sk_test_XXXXXX");
Make sure to download latest stripe library from Githut repo
As i have seen mentioned in the comments:
Stripe needs to be installed using (preferably) composer.
This can be done with the command: composer require stripe after having SSHed into the right directory.
You then need to include the vendor/autoload.php that is generated by composer.
In your case where you cant run composer do the following:
Download stripe`s latest release manually from the github page: https://github.com/stripe/stripe-php/releases
Then you need to include the init.php file found in the downloaded stripe-php directory like this require_once('/path/to/stripe-php/init.php');
Ensure you are running at least PHP 5.4 (Note! This version has reached its end of life. Upgrade if possible to PHP 7.2). You also need the PHP extensions curl, json and mbstring.
After having used require_once('/path/to/stripe-php/init.php'); in the file the stripe code will be running in you can then set your API key using \Stripe\Stripe::setApiKey("sk_test_XXXXXX"); and then run your code like f.ex: $customer = \Stripe\Customer::create([
'email' => $client->email,
'source' => $token,
]);
`
Please use stripe library with the below code to resolve the error
$stripe_obj = new Stripe();
$stripe = $stripe_obj->setApiKey(env('STRIPE_SECRET'));

Laravel error when using Route::resources('book', 'BookController');

Super new to laravel .So I put Route::resources('books','BookController');
in my web.php but I am getting an error in my terminal (img)
also when i run my local host I get something similar (img)
Route::resource('resource', 'Controller');
resource not resources, resources would be for setting up multiple resources at one go:
Route::resources([
'something' => 'SomethingController',
'resource' => 'ResourceController',
]);
Laravel 5.5 - Docs- Controllers - Resource Controllers
Do Like this
Route::resource('itemCRUD','ItemCRUDController');
http://itsolutionstuff.com/post/crud-create-read-update-delete-example-in-laravel-52-from-scratchexample.html

Why Laravel uses wrong database file after setting environment?

In bootstrap/start.php I have the following:
$env = $app->detectEnvironment(function()
{
if($myenv = getenv('APPLICATION_ENV')):
return $myenv;
else:
return 'local';
endif;
});
Ok so I setup a local folder and put in a database.php file with my local connections.
Just to make sure its picking up the correct environment I put in the template: {{ App::environment(); }} which outputs local.
But when making a DB call its giving me error: Undefined index: DB1_HOST
My base (production) database.php file has:
'host' => $_SERVER["DB1_HOST"],
'database' => $_SERVER["DB1_NAME"],
'username' => $_SERVER["DB1_USER"],
'password' => $_SERVER["DB1_PASS"],
Why is it looking at the production database file?
Laravel also stores the config information in
bootstrap/cache/config.php
In some cases it's not updated which may result in wrong database information. Deleting the file should resolve the issue.
If you are trying to use artisan in your terminal and you want to set the environment variable once and for all, you can do :
export APPLICATION_ENV=local
And check you current environment using php artisan env
Production config files are loaded first and then merged with overrides from other environments. If the production file generates an error (e.g. undefined index) the config loading will bail early without loading the overrides. In the production config file, check the value is set before attempting to use it and the local config file will then load correctly.
Clean the config cache as it may affect
php artisan config:cache

Resources