-2

I developed a simple php project with some simple framework and now I want to host it on server, the server is shared server and I do not have SSH access, so I have uploaded all the files via cPanel. For some reason the project isn't opening up on web browser correctly, can someone advise what should I do in this case?

On local machine the project displays correctly and all the pages can be navigated normally, but on web server I'm getting few errors, one related to autoloader. other error indicates platform incompatibility. I think this is related to Composer, but since this is shared hosting without SSH access how to I run composer update or composer dump-autoload.

On local machine:

I install the project using composer:

composer create-project quantum/project oraks

then installed the demo skeleton:

php qt install:demo

this was generated controllers, models, view files and other resources.

I can run the local server via:

php qt serve

all the pages are fully functional (posts, login, manage posts, etc.)

Now I have zipped all this stuff and uploaded to server (shared hosting) via cPanel, extracted it there, trying to access via browser to the domain and instead of displaying the web page I'm getting error:

Fatal error: Uncaught Error: Failed opening required '/vendor/autoload.php' in ../index.php on line 3

Environments:

  • The framework I use is called: quantumphp
  • My local environment is php 7.4
  • The local server is php dev server (not Apache)
  • The Server php is also 7.4
  • But the web server on hosting is Apache

The .htaccess file (inside the public directory):

<IfModule mod_rewrite.c>
    RewriteEngine On

    # Removing trailing slash
    RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>

Please advise

9
  • 1
    Presumably that folder/file is missing, or uploaded in the wrong place. We can't see your environment Commented Mar 4 at 15:41
  • Hi @ADyson, all the files with exact same structure was zipped and uploaded to the server and then extracted, so I think no files should be missing. This is a simple php framework similar to Laravel and uses same .env file if you are about it Commented Mar 4 at 16:11
  • Please post your .htaccess file Commented Mar 4 at 16:42
  • 4
    As a piece of general advice, if you're new to PHP, I would strongly advise you to seek out a host that offers an up to date version (or configure your host to use a newer version) - PHP 7.4 is now old enough that it no longer gets official security patches, and newer versions have a lot of useful features. If you stay with an older version, you'll increasingly find that up to date tutorials and libraries just don't work, because they rely on those new features. Commented Mar 4 at 17:10
  • 1
    "I'm getting few errors, one related to autoloader. other error indicates platform incompatibility." - You should have shared the error messages, they're telling you what's wrong. In general, you should develop the code locally in the same major+minor version that you'll be using on production. Commented Mar 6 at 8:58

3 Answers 3

1

I haven't used that framework, but for my composer Symfony project I uploaded the files to my home directory, outside of public_html.

For this example, directory is /home/seth - my Symfony project was uploaded and unzipped into /home/seth.

Webserver is configured to host files out of /public_html - I just copied the files from /public to /public_html.

/vender, /config, /src, /bin, /var are the Symfony framework files or my code (/src) - ignore the other folders as they are related to my webhosting panel

Example Symfony project uploaded to web hosting server

Sign up to request clarification or add additional context in comments.

1 Comment

Hi @Seth Bembeneck, never thought to put anything outside of public_html folder, but worth to try
0

You should first verify the include/require path in your index.php is correct. Adding __DIR__ might help:

require_once __DIR__ . '/vendor/autoload.php';

3 Comments

Hi @migli, thanks for the reply. I think there are several factors but I can't figure out yet. The entire project is on public_html folder, the index.php entry point though is in public directory. The server is Apache I think, I need to somehow point the domain to public/index.php. I tried to achieve this via .htaccess then I get that error.
inside inedx.php it's like this: require dirname(__DIR__) . '/vendor/autoload.php';
dirname(__DIR__) returns the parent directory of the directory where the file is located, while __DIR__ returns the current directory. For example, from /var/www/html/index.php, dirname(__DIR__) will return /var/www/, which is not what you need. __DIR__ will return /var/www/html/, the location of your vendor directory.
-1

This is a common issue with shared hosting. It is not dependent on the framework you are using, whether it's Laravel, Symfony, QuantumPHP, or another. Most frameworks follow a similar architecture, where the public folder contains index.php as the entry point, while the rest of the application code is placed one level up to prevent direct access from outside.

How you set up your project on shared hosting depends on your current infrastructure. If there are other projects in your public_html folder and you need to add one more, you might consider organizing them as subdomains. However, if this is your only website, the easiest solution is to place all application-related files outside public_html and move the contents of the public folder into public_html.

Additionally, ensure you upload the entire project, including the vendor folder and the .env file. If the .env file is missing, you can create one from .env.example. For QuantumPHP, you can generate the environment file using:

php qt core:env

Don't forget to generate the application key as well by running:

php qt core:key

This setup should work on shared hosting.

4 Comments

Thanks @Armanist for the answer, this is the only website I'm going to land on this hosting. I'll try the move the files out as you and Set Bembeneck suggest and will update the results
If you plan to deploy multiple projects on the same hosting, the above approach will not work since it is only suitable for a single project. You can organize the folder structure so that each new project is placed within the public_html folder as its own directory. However, you will need a separate .htaccess file to direct requests to the appropriate project directory.
Should I upload the composer.json, composer.lock and the .env files also to server as well?
Since you are uploading your codebase to shared hosting, the composer.json or composer.lock files don’t serve any real purpose in terms of installing or updating dependencies, as there is no terminal access, but I still recommend to put them there with your codebase. On the other hand the file .env MUST be uploaded because the framework gets variables from there.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.