Laravel 4 - class not found on live server - php

I'm uploading my laravel 4 app to a testing server which is shared hosting.
I'm uploading to a password protected directory which has a .htaccess file within it. My subdomain points to the public folder.
For the most part they app is working as expected I can log in, view most of the pages however every class that I have created such as a helper class and additional controllers are not being found on the live server yet all works on my local environment.
I've redone a composer dump-autoload and uploaded the composer.json file
I'm not sure where to start with this.
In my upload I've included all the files and folders to the live server (twice now). I read somewhere else I should namespace my classes but why would this help if the main laravel controllers do not namespace?
Confused - all help appreciated

When you do a composer update, if Composer finds anything new it will update some files in the folder
vendor/composer
Like the file autoload_classmap.php.
So, you have to reupload at least this folder too.

Maybe it's about git, you are pushing changings with some certain case sensitive Folders and Files, but git is changing this therefore it will work on Mac and Windows OSs but not on the server.
just use this command:
git config core.ignorecase false
above command for the current repository and you may add --global just after config keyword.
please note that ignorecase option available since version 1.5.6 and I assume you are running 2.0.x but just mentioning!

Related

Laravel 5.7 Nova - The Mix manifest does not exist (on server)

I set up laravel Nova locally last night, tested it, used it, everything works great on my local machine.
Uploaded it to the server, and everything works great except when i head to /nova which rightfully redirects me to /nova/login but then presents me with this error
The Mix manifest does not exist. (View: /home/loanappboi/nova/resources/views/auth/layout.blade.php)
i'm using shared hosting, and i uploaded the files to the root, and uploaded the public folder content, into public_html (i did the necessary file updates to reflect this change)
What could be the cause of this?
i need help
I got this same error. Running php artisan nova:publish fixed it for me. You need to have the nova resources generated.
mix() helper function use /public/manifest-json.js
Set it in config
mix.setPublicPath('public_html/')
OR
use link to public
ln -s ./public ./public_html
For Apache Options FollowSymLinks
Make sure that you are adding '/vendor' in your .gitignore and not 'vendor'. Adding just 'vendor' will ignore all folders named vendor in your codebase and nova resources are in the vendor folder in public folder.

Laravel home page is not displaying correctly

I have my laravel project installed using homestead and I connect to it via SSH using Vagrant(on Windows). The first time I launched my project there was a message indicating i have an error in my public/index.php file indicating that directory specified in 'require' on 14 line is not found it was written like this
require __DIR__.'/../vendor/autoload.php';
then I just replaced this line of code with directory of welcome.blade.php file (require .../welcome.blade.php) (the home page of Laravel) and this page displayed each time I went to my project website but there was another message displayed saying
Illuminate\Foundation\Application' not found in
/home/vagrant/code/myProject/bootstrap/app.php on line 14.
I think that is because of the laravel version installed enter image description here
What I find quite suspicious is that I haven't got env file and vendor folder inside my project folder. vendor folder was located in AppData/Roaming/Composer folder by default. I just moved that folder to my project folder
First thing, Revert the changes within public/index.php back to how it was. That deals with autoloading and bootstrapping the laravel application and should never really be changed.
Now ssh to your vagrant box and within the laravel project, run cp .env.example .env and then edit the newly copied .env file to have all your details for DATABASE and APP_NAME.
Next, go into your project, and run composer install and this will install all the needed dependencies from the composer.json file.
And lastly, from within your project, you should now run php artisan key:generate to generate the APP_KEY.
This should fix your issue.
I would also advice that you look carefully over the documentation at https://laravel.com/docs

How to upload laravel 5.5 project to cpanel in addon domain

This is Bablu Ahmed. I want to upload my laravel 5.5 project into cpanel and my domain is an addon domain name is w3public.com and it's root directory is not inside the public_html it is outside the public_html (www.w3public.com). I have separated the project's files into two directories, one is www.w3public.com and another is laravel and I moved public folder's files into www.w3public.com and all other files into the laravel folder in cpanel that is given in screenshot below. I have also modified the index.php file of www.w3public.com as follows:
require __DIR__.'/../../laravel/vendor/autoload.php';
$app = require_once __DIR__.'/../../laravel/bootstrap/app.php';
But it is not working. Can anyone help me with appropriate solutions?
Screenshot:
Your application should be installed in www.w3public.com and then change the root path from cpanel domains to the public folder inside laravel.
The best way to transfer files is git or the likes, but if they don't have it (usually is the case in shared hosting), you should use a ftp client, and if they don't allow that either, you can upload files/folders from cpanel (way too slow sadly).
If you use git be careful since by default vendor folder is in the .gitignore (you have to run "composer update --no-dev" after all the files are transferred)
Make sure also that your ".env" (usually in .gitignore too, so you prob have to make one) file have your server database info.

Yii2 configuring to use vendor folder in an external http storage

I have multiple restful apis build using yii2 framework, What i wouldlike is to use a single vendor directory stored in a different address
That is
I have an application hosted at www.example1.com and another one hosted at www.example2.com and the one i would like to contain the vendor files to be at www.example3.com so that in both example1 and example2 i only have to upload the resful folder without vendor directories
After some looking into yii2 advanced folder i have found these lines in index.php
require(__DIR__ . '/_protected/vendor/autoload.php');
require(__DIR__ . '/_protected/vendor/yiisoft/yii2/Yii.php');
Ive tried as a work around by doing
require(__DIR__ . 'http:://example1.com/pathto/_protected/vendor/autoload.php');
But the above fails, How best can i achieve this
You can't do it via HTTP.
The only solution is to create shared, NFS volume, which will be mounted on both servers as your vendor/ directory. After you will be able to use the same vendor dir for two servers.
If those two sites are deployed to the same server, it might be easier.
It is very simple .
you can just copy the vendor file into your next project and change the two lines of required file path (autoload.php & yii.php) to the correct vendor location.
the /config/web.php. add vendorPath to the config with your vendor directory.
As the vendor is moved from /var/www/html/myapp/vendor to /var/www/html/frameworks/yii2, you will find problem installing a new extension or updating the existing through composer command. To fix it, modify your composer.json (right under your project directory) by adding the vendor-dir attribute under the config section, eg:
// other settings ...
"config": {
"vendor-dir":"your path",
"process-timeout": 1800
},
// other settings ...
Also, you may find "a man-in-the-middle attack" message when either update or install the new extension (i don't know if there is a relation to the modification of composer.json but i get it several times during experiments). To fix it run composer update --dry-run. then it would ok.
This can be done: Include through http.
You need to set some php variables (allow_url_include, allow_url_fopen). And you need to get rid of __DIR__ constant in front of your php file path:
require('http://example1.com/pathto/_protected/vendor/autoload.php');
BUT
Don't do this. Really. You don't want to go through all these unsafe php setups. And you don't want to expose your vendor files to all the people in the world. If your script can access php source code via http, everyone can. Also, includes over http will be extremely slow.
The (probably) only solution
If you really want to share core php files between multiple websites, you can purchase virtual server, set up both websites on it and create one folder accessible from all websites on this server.
You don't even need virtual server, you can go with some kind of multihost service with custom folder for each website and shared folder for core (vendor) files.

Laravel, dump-autoload without Shell Access

I have two controllers with the same name:
app\controllers\CareersController.php (for public use)
app\controllers\Admin\CareersController.php (for admins)
Because of the naming conflict, I added namespace admin; to the admin controller.
Everything works fine locally but when I uploaded the new admin controller to my server, I get an error: Class Admin\CareersController does not exist
From what I understand, the fix is:
php artisan dump-autoload
and composer dump-autoload
However, I don't have Shell access to run those commands and composer isn't installed on the server anyway. So, is there a way to reload the auto-load file without Shell access?
Run composer dump-autoload locally. Then, in your hosting site,
you can update two files, autoload_classmap.php and autoload_static.php, manually in vendor/composer folder. I prefer to copy and paste the added classes from local to the hosting server.
You dont need shell access. Artisan includes a dump-autoload function. You can just it via a PHP call within your app:
Route::get('/updateapp', function()
{
\Artisan::call('dump-autoload');
echo 'dump-autoload complete';
});
Edit: just noticed you wrote "composer isn't installed on the server anyway". Not sure what will happen - try the command above and let us know.
If it doesnt work - then just run composer dump-autoload locally - then upload your new autoload.php.
As a side point - is there any option to switch servers? You going to keep running into various issues if you dont have command line & composer access. You could just use Forge and spin up a new server on DigitalOcean, Linode etc in less time than it would take to fix this issue :)
I was using a shared hosting by client's requirements and did not have access to ssh or composer, what I did was to composer dump-autoload on my local machine and then I figured that for my project autoloader just updates composer directory in my vendor directory, so I just re-uploaded that one folder after each dump-autoload and not all vendor directory
Edit:
Another pitfall for me that generated the same error but the cause was something else, I develop on Windows machine in which file and directory names are case insensitive when deploying to Linux server, the framework could actually not find my controllers so I changed
Route::get('/news', 'newsController#index');
to
Route::get('/news', 'NewsController#index');
now it is working, autoload is doing it's job correctly

Categories