Accessing php files out of root folder(Laravel) - magento

Inside my Magento Project folder I want to install laravel so that I can access Mage from laravel. Directory structure is following
Magento(root)
--laravel
--app
...
...
How can I achieve That? Or suggest any other way so that I can access magento from laravel like following.
require_once ('../app/Mage.php');
Mage::app();
Mage::getSingleton('core/session', array('name' => 'frontend'));
$collection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('*');
UPDATE
Controller Location relative to magento
D:\xampp\htdocs\magento\custom\app\controllers\ProductsController.php

Make sure the path is correct, it should work.
Use this one
require_once (realpath(dirname(__FILE__) . '/../app/Mage.php'));

Your path ( require_once ('../app/Mage.php'); ) is not correct that's why you are facing this issue.Except this logic wise your code is correct.
If you are running your code from somefile.php in laravel then it should work.
Magento(root)
--laravel
|__somefile.php
--app
...
...

I have used dirname() function to solve this problem.
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/app/Mage.php');
I don't think this the nice or smart way, but it works. Thanks.

Maybe someone useful:
require_once (dirname(dirname(dirname(dirname(realpath(__FILE__))))).'/../app/Mage.php');
\Mage::app();
$blocks = \Mage::getModel('cms/block')->getCollection();
foreach ($blocks as $block) {
echo $block->getTitle()."<br>";
}

Related

/vendor/autoload.php error while running laravel

so im new to laravel, just downloaded composer, created new project through terminal in vscode, tried to run it and this error shows up
Error in localhost>public
The Code:
require_once __DIR__ . '/vendor/autoload.php';
and also getting errors while compiling on these:
$response = $kernel->handle(
$request = Request::capture() //Undefined type 'Illuminate\Http\Request'//
)->send();
the illuminate code:
use Illuminate\Http\Request;
Help would be appreciated
You should have following code for autoload.php. Basically, you're trying to look for vendor directory in the public folder, whereas it is normally placed in the base directory
require __DIR__.'/../vendor/autoload.php';
Did you try running a composer update command?
Re-installed everything in the same (C) directory and its working great now
Appreciate the help, thank you, everyone!

How to solve Error500 Http\Kernel::class on Laravel 5

Hi I have to install finished project created by laravel5 on my client'cloud (CentOS). Everything work find on my windows local host. But I got error500 on real server.
Some error clue:
$kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
$response = $kernel->handle(
$request = Illuminate\Http\Request::capture());
$response->send();
$kernel->terminate($request, $response);
This phpmyadmin screen sent from my client
Note that this is cloud server that is not my own. So I can not install composer / run command or install other libraries. Thank you for all answer.
You have to change the vendor and bootstrap folder path in index.php on your current structure
change these two lines from index.php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
to
require __DIR__.'/vendor/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';

How to deploy laravel to server using ftp

Hi I'm newbie on Laravel. I have to upload laravel project to Linux server(CentOS). Customer provide me ftp path. For example 10.222.20.10/srp. So I put all files into that path and after edited database inside .env file. I run 10.222.20.10/srp on webbrowser but I getting error 'This page is not working, error 500'. I attached picture as below. Appreciated for advise and thank you very much.
Please Follow this Steps:
1.
Copy all contents inside the /project/public directory to project/
Remember to copy the public/.htaccess to the project/ also
Now let’s modify the www/index.php to reflect the new structure. Don’t modify the project/public/index.php, okay? Only modify www/index.php, remember this!!!
Find the following line
require __DIR__.’/../bootstrap/autoload.php’;
$app = require_once __DIR__.’/../bootstrap/app.php’;
And update them to the correct paths as following
require __DIR__.’/../project/bootstrap/autoload.php’;
$app = require_once __DIR__.’/../project/bootstrap/app.php’;
2. Set permision 777 project/storage and project/bootstrap/cache
Maybe this tutorial will help you Deploy Laravel To Shared Hosting The Easy Way
Please Follow this Steps:
1.public folder(index.php) is the start point of your application set
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
according to your configuration or use symlink
2.Migrate Database (if you don't have ssh access create a route and use Artisan facade Artisan::call("migrate"); and don't forget to remove it )
3.Link storage if you need (if you don't have ssh access create a route and use Artisan facade Artisan::call("storage:link"); and don't forget to remove it )
4.Check server logs maybe folder premissions is wrong.

Move Laravel project to subdomain where Wordpress is already installed

I created a subdomain and move whole project except public folder. Create mysql database and upload my database there. Now, in public_html folder I already have wp files so I created new folder there which I named same as subdomain. So, subdomain is something.something.com and now I have path public_html/something/public where I upload all from public folder. I try to rename files in index.php public foder:
require __DIR__ . '/../bootstrap/autoload.php';
$app = require_once __DIR__ . '/../bootstrap/app.php';
to this:
require __DIR__ . '/../something/public/bootstrap/autoload.php';
$app = require_once __DIR__ . '/../something/public/bootstrap/app.php';
but still I get this:
And I edit .env file to find database. Where am I wrong?
Solved! It was PHP version mismatched. In local it was 7.1 but on server was 5. When I update on server it worked.

Get Magento Session in Directory that is outside Magento

I want to get customer session in a dir which is outside of my magento main dir. For e.g. root/magento/ => is my installation dir
root/temp/ => is my test folder
root/checksession.php => is the file on root of magento installation
root/temp/checksession.php => is the file outside of magento dir and inside of external dir.
Here i am getting the customer session in root/checksession.php but i dont know why the same coding is not working with root/temp/checksession.php
Have tried include, define and php session method, but still its not working.
Do any one have idea, how it is possible to get magento session in root/temp/checksession.php file???
require_once 'app/Mage.php';
Mage::app("default");
$coreSession = Mage::getSingleton('core/session', array('name' => 'frontend'));
session_start();
$_SESSION["coreSession"] = $coreSession;
echo "<pre>";print_r($coreSession);
I think you forgot the following:
Mage::app('admin')->setUseSessionInUrl(false);

Resources