0

I have posted a question yesterday here in relation with hosting a laravel project in Cpanel.

I have tried all solutions that have been proposed in several topics in relation with this problem but still having the same error.

I am sorry for republishing this just trying to get another advices & propositions maybe I have published my question in an inappropriate hour.

I can publish the content of any file you want if you think that the problem may come somewhere else.

Z4n3tti
  • 115
  • 3
  • 13
  • just rename your server.php to index.php and take out all file / folder in public to main except index.php – Gaurav Gupta Apr 01 '19 at 11:20
  • @GauravGupta : I move all files in public_html folder into myapp folder? If I do that, I should edit index.php and remove /myapp/ from this 2 lines require __DIR__.'/../myapp/vendor/autoload.php'; $app = require_once __DIR__.'/../myapp/bootstrap/app.php'; ?? I will try this – Z4n3tti Apr 01 '19 at 11:38
  • move all to your myapp(project_name) folder just undo all previous stuff – Gaurav Gupta Apr 01 '19 at 11:41
  • @GauravGupta: This is what I have done: I have move my public_html folder into myapp folder, I have move index.php inside, then, in the ancient public_html folder I have got an error.log file that you can find here: https://ufile.io/l2lmz. I think we are close to the jackpot. – Z4n3tti Apr 01 '19 at 13:19
  • not public_html just public laravel folder i m not taking you out of laravel project folder – Gaurav Gupta Apr 01 '19 at 13:33
  • @GauravGupta: I'm sorry for misunderstanding you, This is what I have done when upload my laravel project file on cpanel: I have create myapp folder which I have upload all my folders/files except public folder, I have put public folder content into public_html folder. Now, I have moved the public_html content into myapp folder. Do you want me to move the content of public folder into myapp folder directly? – Z4n3tti Apr 01 '19 at 13:50
  • Give me 30min after reaching home I'll tell you everything in detail – Gaurav Gupta Apr 01 '19 at 13:53
  • @GauravGupta Take your time Sir, I appreciate your help. – Z4n3tti Apr 01 '19 at 14:02
  • @GauravGupta I missed something ? – Z4n3tti Apr 01 '19 at 21:20
  • After uploading all files into my laravel app project folder, I got 403 error (action is unautorized) – Z4n3tti Apr 02 '19 at 07:50
  • could you upload your code to git or something like that also need to change in .htaccess RewriteCond %{REQUEST_URI} foldername – Gaurav Gupta Apr 02 '19 at 07:59
  • @GauravGupta For sure Sir, I will upload my project in Github when I will back home. – Z4n3tti Apr 02 '19 at 08:47
  • @GauravGupta : This is my folder in cpanel. https://github.com/Razzanati/MyLaravelApp – Z4n3tti Apr 02 '19 at 22:34

1 Answers1

0

check below screen shot rename server.php to index.php and take out all the public folder file i marked the folder and file to which need to take action enter image description here

in public except index.php take out all file/folder enter image description here

after that open .htaccess file it present in your main folder MyLaravelApp if not then just create new one and past below with you app corrections

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>


    RewriteEngine On

    RewriteCond %{SERVER_PORT} 80
    RewriteCond %{REQUEST_URI} MyLaravelApp(folder name)
    RewriteRule ^(.*)$ https://example.com/MyLaravelApp(folder name)/$1 [R,L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule ^ - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    Header set Access-Control-Allow-Origin "*"
    Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
    Header set Access-Control-Max-Age "1000"
    Header set Access-Control-Allow-Headers "access_token, x-requested-with, Content-Type, Accept-Encoding, Accept-Language, Cookie, Referer"
</IfModule>

this work for me hope it work for you too.

Gaurav Gupta
  • 1,588
  • 2
  • 14
  • 21
  • Thank you sir for your help, I have done all this modifications but still having 403 forbidden error. This is my laravel application folder: [img]https://i.imgur.com/ClXixvq.png[/img]. I have renamed server.php into index.php and it content: [img]https://i.imgur.com/CsDPdxe.png[/img]. I still have when typing my domain name the 403 forbidden: [img]https://i.imgur.com/2Irw9v8.png[/img]. And finally, this is my .htaccess file: [img]https://i.imgur.com/4JEeGHb.png[/img]. I don't know what I've missed, but in public_html folder, when I put an html file to test the access, it shows content. – Z4n3tti Apr 03 '19 at 21:56
  • first of all change folder permission 644 to all except folder/file that was inside public, storage and resources give them 777 more about this check this https://stackoverflow.com/questions/30639174/how-to-set-up-file-permissions-for-laravel-5-and-others – Gaurav Gupta Apr 04 '19 at 06:40
  • I have changed public and file inside (index.php), storage and resources folders as indicated (777), but still getting the same 403 forbidden access. I have checked the link also, they do not have done nothing more than this. Did I missed something? – Z4n3tti Apr 05 '19 at 09:44
  • where is your robots.txt file ? put that one in public and try – Gaurav Gupta Apr 05 '19 at 09:48
  • Hello Sir, Thank you for your help and your propositions I appreciate that. I have put robots.txt file in public folder but still got 403 error, I have found that robots.txt has 644 permission, so I have changed also to 777 to see if it is related to it but still not working. – Z4n3tti Apr 05 '19 at 21:05
  • Nop, I have created a laravel app from scratch, nothing customised. I have tried now one thing, in my public_html folder, i have put index.php file, so that I can see errors in my error_log file their, What I have seen is that the last error refers to me like the running php version isn't the php 7.0 or more, but I have for sure the version 7.1 selected in my cpanel. This is what I got as errors in my logs: https://imgur.com/pUJu6mF . – Z4n3tti Apr 05 '19 at 21:20
  • How can I test hosting a sample laravel app and compare it with mine? I still can not find the source of my problem. – Z4n3tti Apr 08 '19 at 08:10
  • do one thing create new laravel project as upload it in different directory and flow above step and check with some test routes weather it's working or not , no need to put your actual code or any thing just upload a fresh project – Gaurav Gupta Apr 08 '19 at 08:13
  • Hello Sir, I have not tested it yet, I will do it in the afternoon. (I have got some problems during this couple of days, so I couldn't work on it). I will give you my return here as always. Thank you so much – Z4n3tti Apr 10 '19 at 11:26
  • Hello Sir @Gaurav Gupta, I have created a laravel 5.4 project, I have unziped it into my public_html folder, I renamed server.php to index/php, modifiying my htaccess file to authorize public folder, and I got my laravel view working. https://imgur.com/a/uDb31RC , I really don't know what is different ? The project I am trying to host is a laravel 5.7 project, I have not made any changes on the form or the organisation of folders/ files, my php on server is 7.1. – Z4n3tti Apr 10 '19 at 23:07
  • One other thing, when I have done the same as the laravel testing project, I only modified my htaccess and put him into public folder, and edit content with only RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] , I've got the PHP parse error like the php 7 version isn't working (https://imgur.com/a/a7bGCC9), here is my php extension on cpanel (https://imgur.com/a/R6aqx86) . There is some additionnal things to do when changing the php version on server? it was 5.6 before I begin hosting on server, and I have changed to 7.1 and set as current. – Z4n3tti Apr 11 '19 at 00:12
  • Hello again, omg after creating a file phpinfo.php to check my php version on the server, I found that it is 5.6 not the current 7.1 that I have choose and set as current, https://imgur.com/a/nJyAhZO , so I guess i should restard apache server. But didn't know how to do it – Z4n3tti Apr 11 '19 at 00:51
  • If you want to restart Apache for that you need Shel access – Gaurav Gupta Apr 11 '19 at 01:36
  • Hello Sir, I solved my issue with the php version in server, now I have a problem that is related with JsonSerializable. It said that Interface 'JsonSerializable' not found. This is my composer.json https://imgur.com/a/DzNgvmz, this is phpinfo on server : https://imgur.com/a/pMHD6dZ and this is the error I obtained : https://imgur.com/a/1JOxBsB . do you have an idea ? cause I've seen many posts related with that but I do not have the same issue as them. – Z4n3tti Apr 12 '19 at 15:37
  • That's good to hear your main issue was resolved . I'll let you know as soon as possible regarding second problem – Gaurav Gupta Apr 12 '19 at 15:49
  • check this https://stackoverflow.com/questions/43363108/php-fatal-error-interface-jsonserializable-not-found-my-php-version-is-7-0/43366188 – Gaurav Gupta Apr 13 '19 at 05:01
  • Hello Sir, Thank you so much for your help along this days regarding my problem, my website is finally hosted and worked fine, the problem was from the server (I told the administrator to change my php to 7.2), and I have done all stuffs you told me to do but I have put all of them into my public_html folder and it works now. Thank you so much – Z4n3tti Apr 13 '19 at 10:39
  • happy to able help. – Gaurav Gupta Apr 13 '19 at 10:56
  • It was really because of you. Many thanks for your help and your dedication with my problem. – Z4n3tti Apr 13 '19 at 19:57