1

I have the following layout of a PHP files

├── classes/
├── migrations/
├── public/
│   ├── images/
│   ├── scripts/
│   ├── styles/
│   └── index.php
├── sample/
└── templates/

I wasn't sure how to put this on my server so I put the files from public into my public_html folder (which is what my cPanel already had).

Also, I put the other directories on the same level as public_html so as to maintain the regular structure of the project.

As such, I end up with this:

├── (some cPanel directory and files)
├── classes/
├── migrations/
├── public_html/
│   ├── images/
│   ├── scripts/
│   ├── styles/
│   └── index.php
├── sample/
├── templates/
└── (other cPanel directory and files)

Now, all other pages returns a HTTP status code 404 except the index page.

What am I doing wrong?

For reference, the project I'm trying to deploy is available at https://github.com/srv-twry/Quizzer.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Jimmy
  • 12,087
  • 28
  • 102
  • 192
  • 1
    Can you change the document root of your website? – René Höhle Jan 04 '20 at 11:42
  • I'm not sure, its cpanel. I will see – Jimmy Jan 04 '20 at 11:44
  • 1
    Target your website at http://example.com/index.php, does that work? Can you access logs? Do any Php files behave as expected when placed in the document root? – Progrock Jan 04 '20 at 11:46
  • Going to the index.php in public_html works fine as my document root, but all other links point to 404. – Jimmy Jan 04 '20 at 11:47
  • 1
    Perhaps you need some redirection with a .htaccess and rewrite rules? Assuming this server is Apache. How do you run your site when developing? – Progrock Jan 04 '20 at 11:49
  • 1
    It is working on index.php (as in it looks to be using your code), it's just that your routing doesn't account for index.php in the URL. All you are missing is some rewrite rules I reckon. – Progrock Jan 04 '20 at 12:01
  • 1
    Try something like this: https://webmasters.stackexchange.com/a/57316/89012 , however it looks like you are running a litespeed server, so configuration may be different. Check the manual and/or your hosting provider. – Progrock Jan 04 '20 at 12:08
  • 1
    @Jimmy: what's you PHP version please? – nyedidikeke Jan 04 '20 at 12:08
  • @Progrock You genius! Thank you it works. If you want to add as an answer i will accept? – Jimmy Jan 04 '20 at 12:12
  • 1
    As a side note, you might give your project more flexibility/reusability by dropping the requires and using an autoloader. See also PSR-4. – Progrock Jan 04 '20 at 12:19

1 Answers1

1

Within your source there is no .htaccess, and it sounds as if redirection is missing.

You'll need to route appropriate URLs through your front controller - index.php.

With Apache style servers you could use modrewrite and a .htaccess file.

As a starting point, create a .htaccess with the rules below - you may need to tweak for your individual needs;

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [NC,L]

Code copied from Webmasters Stackexchange.

nyedidikeke
  • 6,899
  • 7
  • 44
  • 59
Progrock
  • 7,373
  • 1
  • 19
  • 25