Deploying my project to a shared host

My topic is similar but not the same as others posted here.

I am a hobbyist. My living doesn’t depend on CakePHP but my fun does! I have a shared hosting account and I run several static websites as folders off public_html.

My question is: Can I deploy my CakePHP project by just uploading all the files to a folder below public_html? Is it legal or is it poor programing practice.

Thanks,
Paul

Yes, you can. Read this also: https://book.cakephp.org/3.0/en/installation.html#production

I think this technique will be easy for you

Assumptions:

  1. You have access to cPanel/File Manager
  2. Your root folder is /home/username
  3. Your public (web) folder is /home/username/public_html

Steps:

  1. Copy the contents of your application’s root folder (CakePHP or whatever your application folder is) to /home/username. This will result in Your application’s bin folder going to /home/username/bin and so on
  2. Remove public_html folder and create a new symlink ‘public_html’ pointing to /home/username/webroot

Yes, you can deploy your cakephp site on shared hosting by uploading the files to the folder. However, you must follow a proper process.

First, structure the directory like this:

/home/username/public_html/
    // webroot contents goes here
    css/
    img/
    js/
    .htaccess
    index.php

/home/username/mycakeapp/
    // necessary app directories go here
    /config
    /logs
    /plugins
    /src
    /tmp
    /vendor

Change WWW_ROOT in mycakeapp/config/paths.php on line 52:

define(‘WWW_ROOT’, ‘/home/username/public_html/’ . DS);
Change the path to bootstrap.php defined in the webroot index.php file on line 28 (located at /home/username/public_html/index.php):

require ‘/home/username/mycakeapp/config/bootstrap.php’;

You should also note that shared hosting is not recommended for big websites. It is good enough for personal blogs, but not for business or startup websites. For that you should better go with infrastructures like DigitalOcean or Linode. Both are affordable and provide better performance and security. If you don’t know how to manage the servers yourself, you can go with some managed PHP mysql hosting service. With managed services, the service provider manage the servers for you.

Can I deploy my CakePHP project by just uploading all the files to a folder below public_html?

Yes, a CakePHP app can be run off a sub folder within your webserver’s document root (public_html in your case).

Is it legal

Absolutely.

or is it poor programing practice.

It’s not ideal but we don’t live in a ideal world :slightly_smiling_face:

getting the following error

Fatal error : Uncaught Error: Class ‘Cake\Routing\Router’ not found in /home/username/mycakeapp/vendor/cakephp/cakephp/config/bootstrap.php:26 Stack trace: #0 /home/username/mycakeapp/config/bootstrap.php(32): require() #1 /home/username/public_html/index.php(19): require(’/home/sudhir251…’) #2 {main} thrown in /home/username/mycakeapp/vendor/cakephp/cakephp/config/bootstrap.php on line *26
note : replace username with my username

Looks like your autoloading is not set up correctly.

I am not happy that it is not possible to host my cakephp website on a domain. I tried to host my cakephp website on addon domain by uploading the files and it is not working. There is no way to find how to do it on the web Only way is to put my files on sub folder and redirect the domain to that folder which is not good .,

there is no video on how to transfer cakephp site from local server to hosting server. Can anybody point out the video if available

This is not a Cake-specific thing. There’s no magic that’s required because it’s Cake. And the steps required to deploy a site will vary depending on what access you have to your server, how the web server is configured there, whether you’ve customized your file structure, and more. So there’s no tutorial that will cover everything.

I can tell you that you need to make sure that everything needs to be transferred, including the vendor folder and hidden files like .htaccess, and case sensitivity is important on Linux servers but not on Windows. Those are some of the common mistakes.

If you want more help, you’ll need to provide more details about your dev and production setups, how you transferred your files, etc. “I tried to host my cakephp website on addon domain by uploading the files and it is not working.” is not useful to anyone trying to help. What files did you upload? Where did you upload them to? Why do you think that was a good place to put them? What does “not working” mean?