Artisan commands not working on shared hosting domain
Hi, I have a little issue.
I recently uploaded my Laravel 10 ecommerce project on Namecheap on a shared hosting plan using an addon domain.
Unfortunately, anytime I run an artisan command, for instance; 'php artisan key:generate' in the cpanel terminal, there is no message and the terminal just moves to the next line. When I check my .env file, I notice that the key hasn't been generated.
How do I solve this?
@loveck Most shared hosting environments may restrict certain commands or features in the terminal. Contact your hosting provider to ensure that you have the necessary permissions to run artisan commands.
you may need to consider alternative methods for running artisan commands, such as SSH access to your server
@enoch91 So I finally got SSH access to my server and logged into my server directory from putty on my pc but the problem still persists. When I type php artisan commands, they do not run and the terminal just starts a new line.
@Loveck Great! As I mentioned above, most shared hosting environments may restrict certain commands or features in the terminal. I highly recommend that you contact your hosting provider to ensure that you have the necessary permissions to run artisan commands.
@enoch91 I contacted them and yes, I do have the necessary permissions to artisan commands. I input this code into my artisan file
ini_set('display_errors',1);
error_reporting(-1);
Then I got an error after running the artisan command again in my terminal saying: ../App/Helper/helpers.php: Failed to open stream: no such file or directory in ../vendor/composer/autoload_real.php. How do I resolve this issue as I need my helper function throughout my project?
@gych I just tried this and it says that there is no such file or directory. My php version is 8.2 on there and I am sure my path is right because I used pwd to identify it in the terminal and then attached ea-php82 artisan key:generate to the path it returned.
@Loveck When you run this you have to be in the directory of your laravel project and run the full command from there, don't navigate to the php folder. You have to call it while your terminal is inside of the laravel application folder.
If it still doesn't work you could also try one of these commands, it can depend on which os cpanel is running
@gych The third command did not return any error nor did it generate a new key. It just moved to the next line just like directly typing php artisan key:generate does
@gych I just did what you have suggested and after running the artisan command again, there seems to be an issue with a Helper function I created in my project. This is what the error reads: ../App/Helper/helpers.php: Failed to open stream: no such file or directory in ../vendor/composer/autoload_real.php
Now that I think about it, when I ran composer install, the helpers.php file had an error displayed. I need that file in my project though so how do I resolve this issue?
@gych So, I have tried the path you specified above and the error still persists but between my last comment and now, a lot has happened and although the error still persists, there is a new error at the top of the error message in yellow which says that Class App\Helper\Helpers located in .app/Helper/helpers.php does not comply with psr-4 autoloading standard. Skipping.
Part of the 'lot' that happened involved me introducing a namespace into helpers.php and converting the content of my helpers.php from a set of regular functions to a class of static functions and then recalling the functions in over a 100 files with the right path prefixes instead of again, just the regular function names.
@Snapey Wow, I changed the name of my helpers file from helpers.php to Helpers.php, removed it from composer.json's autoload method completely, run my artisan commands which run flawlessly and reloaded the website and now, everything is working perfectly :)
Wow, I changed the name of my helpers file from helpers.php to Helpers.php, removed it from composer.json's autoload method completely, run my artisan commands which run flawlessly and reloaded the website and now, everything is working perfectly :)