Loveck's avatar

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?

0 likes
25 replies
enoch91's avatar

@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

1 like
Loveck's avatar

@enoch91 I think I have SSH access to my server but I will make further enquiries to my hosting provider to confirm. Thanks for your suggestion.

1 like
Loveck's avatar

@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.

1 like
enoch91's avatar

@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.

1 like
Loveck's avatar

@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?

2 likes
gych's avatar

@loveck Like @enoch91 already said, you might be limited on a shared host.

Do other commands work? Do you get output if you run php -v ?

1 like
Loveck's avatar

@gych I do get an output when I run php -v and composer commands run just fine.

1 like
gych's avatar

@Loveck This is what you can try

In your terminal run the command with the path where the php version you're using is installed

/usr/local/bin/ea-php82 artisan key:generate

Make sure to change the php version in the path to the version you're using on cpanel

This ea-php82 is for PHP version 8.2 if you use 8.1 change it to ea-php81

1 like
Loveck's avatar

@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.

1 like
gych's avatar

@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

/opt/cpanel/ea-php82/root/usr/bin/php artisan key:generate

/opt/alt/php82/usr/bin/php -c /opt/alt/default_php_ini/php82.ini artisan key:generate

/opt/alt/php82/usr/bin/php artisan key:generate

/opt/alt/php82/usr/bin/php -c artisan key:generate

1 like
Loveck's avatar

@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

1 like
gych's avatar

@Loveck When deploying your application did you run composer install first and did that work?

1 like
Loveck's avatar

@gych I did run composer install first and it worked perfectly.

1 like
gych's avatar

@Loveck Ok try this: edit the artisan file and add this after the <?php opening tag.

ini_set('display_errors',1);
error_reporting(-1);

Then try again and see if it outputs any errors.

1 like
Loveck's avatar

@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?

1 like
Loveck's avatar

@gych In autoload_real.php line 55:

require(../App/Helper/helpers.php) : Failed to open stream: no such file or directory

1 like
gych's avatar

@Loveck I think your autoload path for the helpers file might be wrong in your composer.json

Try this

"autoload": {
    "files": [
        "./app/Helper/helpers.php"
    ]
}
1 like
Loveck's avatar
Loveck
OP
Best Answer
Level 1

@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.

2 likes
Snapey's avatar

@Loveck make sure the letter case for the folder and the file is perfectly matching with whats in composer.json

1 like
Loveck's avatar

@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 :)

Thank you very much! @enoch91 @gych and @snapey

1 like
Loveck's avatar

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 :)

Thank you very much! @enoch91 @gych and @snapey

2 likes
Snapey's avatar

you should award best answer in this case to the one that put in most effort which was clearly @gych

2 likes

Please or to participate in this conversation.