cakephp app as part of static site - cakephp

I have kind of an unique situation.
I have developed a cakephp app and need to deploy it to a shared server with content.
I know generally we are supposed to have static content in webroot, but am not allowed to do so, as this application needs to be removed later on.
its a shared hosting and i can't change DocumentRoot or any admin related settings. I can however add .htacces files.
I have my files in the following order:
/webapp
/app
/lib
...
/webroot
I guess you get the point.
I was planning to deploy the entire 'webapp' folder along with the static site and have the login link so the people can come to the site as http://mysite.com/webapp/users/login.
Unfortunately I do not know the correct way to do this. I hope to preserve the directory structure as-is so that someone coming after me can easily modify and delete it.
Any help is appreciated.
UPDATE:
I forgot to mention that locally i used to access the site by http://localhost/webapp, which was based of a DocumentRoot/VirtualHost setting. I might not be able to do that on prod, so how can I translate that using routes?

You need to update the .htaccess files to reference /webapp/app/webroot/ instead of /app/webroot/.
Although I’d be tempted to just install the CakePHP app in the root of your web server’s publicly-accessible directory, use CakePHP’s built-in PagesController to serve the static files, and just remove the controllers as and when you need to.

If you want to serve CakePHP from a subdirectory using Apache, you're looking for the RewriteBase directive. Add the directive to each of your three .htaccess files (in CakePHP root, in app, and in app/webroot). For example, the root one will end up looking like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /webapp
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Now Cake will be happy being served in your webapp subdirectory.

Related

Sonata admin missing css files

Working on a site with php 7.2, Symfony 4 and Sonata admin 3.
In dev, on my machine, everything works fine, the site itself, and the two admins (user and content).
I have put everything on the final server (unfortunately, file by file, no console with S4 ! so, no "composer:install"...).
Still on dev, the site works fine, all functionalities.
But when I try to use the admin page, I only get a non-formatted page. None of the assets (css and js) seems to work!
However the source code are identical, on localhost and the distant site...
Can anyone help me
Edit : I found where the issue comes from : it's linked to .htaccess.
The http address I use ends in /public/index.php. I use .htaccess to shorten it and when using the .htacces redirection I can't get the assets of the admin page, while it works fine without redirection.
Is there something I should change in my .htaccess code ?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/index.php
</IfModule>

How to deploy a create-react-app to a web host (ex. Siteground)?

I'm building a react project using create-react-app and am trying to figure out how to deploy my code to my hosting server on Siteground.
Does anyone know the best way to do this? Do I import my build folder through FTP? Can I automate the process through GitHub?
Thanks in advance!
Per the create-react-app docs, you run npm run build and basically just take the output and FTP it to your web server.
However your question is very broad -- you could automate through GitHub or some other tool, but that's really going to beg opinionated responses on StackOverflow (which isn't the right forum for those kinds of questions).
npm run build or yarn build
Builds the app for production to the build folder.
It correctly bundles React in production mode and optimizes the build for the best performance.
npm run build creates a build directory with a production build of your app. Set up your favorite HTTP server so that a visitor to your site is served index.html, and requests to static paths like /static/js/main.<hash>.js are served with the contents of the /static/js/main.<hash>.js file.
source: create-react-app
I just uploaded my create-react-app to siteground with FileZilla here is the step by step:
Once you have it all production ready npm run build
Open siteGround on your browser and into myAcount section click on go to cPanel scroll down and find FTP Accounts
create a new account pointing to the directory public_html
once created, it will appear down below and all the way to the right click on configure FTP client and under manual setting you've got what you need to connnect
open FileZilla and in file go to siteManager then new site
host(in filezilla) === FTP server (in sitiGround), port set it as siteground port , protocol and encryption leave it as default
Logon Type set as normal , user === FTP user(siteGround) and password the one you've used to create that FTP user
click on connect and paste the content of yourApp/build (from the left side that is your PC) to (the folder at the right hand side) that is your public_html in siteGround
That's it! go to your website and check, the react app should be displayed there
here is the source of this procedure
https://www.siteground.com/tutorials/ftp/
Here they use quick connect for fileZilla though, I have more than one site so siteManager is cleaner and stores your credentials for next time
Usually there are guided strategies from host vendors.
Example:
Heroku Create React App Build
S3 Cloudfront
Otherwise you'll have to manage it by yourself, registering a custom build script that acts with:
npm run build
And then move the build folder. If you use Maven you can manage the entire build with plugins like:
Frontend Maven Plugin
If you are using create-react-app, then you could do:
npm run build or yarn build
Copy everything that is inside of the build folder as a result of the previous point
In order to get the routes working, add .htaccess file with the following content:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule . /index.html [L]
</IfModule>
Export it to the root folder of your server (normally public_html)
Check this great article for more info :)
Hope it helps!
I have problem deploying on siteground as well the simple solution is to have a git repo for your build and setup your public_html folder on siteground to track that git repo.
make sure to also create
.htaccess
with the content something like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.html [QSA,L]
If you don't have that your routing won't work
Also remember to go Tools->Speed->Caching and flush the cache if you have deployed otherwise before

Htaccess doesn't allow requesting resources in sub folder application

I'm having problem with configuration of my .htaccess file. Application is written in AngularJs, while restApi application is written in Codeigniter and it's located in /server folder.
This is my folder structure
My api folder structure
This is my .htaccess file on which i'm working on
RewriteEngine on
RewriteCond $1 !^(index\.php|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
The problem is that when ever i try to access my api resource i'm keep getting 404 page, while this works perfectly on my debian nginx server, that's why i'm guessing that this is the problem in .htaccess file
http://myApp.com/server/api/products/latest/1
I hope you guys can help me. If you need any additional information's please let me know and i will provide. Thank you in advance.
Try in .htaccess
RewriteBase /server/
Also make sure that in config.php
$config['index_page'] = ' ';

Cakephp installation and root directory

I am working through the cakephp installation for production use and I have a problem. I use hostmonster, so this is a shared server using a LAMP stack. The documentation asks you to change the Root Directory as shown:
DocumentRoot /cake_install/app/webroot
To do this, I added the following statements to my .htaccess file:
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /cake_install/app/webroot/$1 [L,R=301]
This resulted in the error below:
Error: The view for AppController::webroot() was not found.
When I navigate to www.example.com I am taken to the proper address, but there are errors. These errors disappear if I add an index.php to either the address or obviously to the rewrite rule.
So, what am I doing wrong here? Is the documentation incorrect in that the rewrite rule should have the additional index.php, should be address work without it, or is there something wrong somewhere else?
Update: The second part of the errors says:
Error: Confirm you have created the file: /home2/cadwolfc/public_html/cake_install/app/View/App/webroot.ctp
The version of cake that I downloaded did not have anything the /app/View folder. When I created the /App/webroot.ctp file it got rid of the errors, but it overrides all other view calls.
If your hosting provider has not enabled mod_rewrite. Then you would need to delete the .htaccess files
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If I am wrong and there is nothing wrong with mod_rewrite then you should edit your htaccess file and do something like
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
My guess is this is what you're looking for: HostMonster - How to host the Primary Domain from a subfolder (.htaccess)
On most shared hosts, you can't change the document root. Since hostmonster has mod_rewrite there are no special steps for installing cake on hostmonster. There are several ways to install cake - all of them are valid on hostmonster.
Use a development install
The simplest way to set up an application is to use a development install i.e. so the following folder structure exists:
/home2/cadwolfc/public_html/app
/home2/cadwolfc/public_html/lib
/home2/cadwolfc/public_html/plugins
/home2/cadwolfc/public_html/vendors
/home2/cadwolfc/public_html/.htaccess
/home2/cadwolfc/public_html/index.php
Don't edit any of the .htaccess files unless a specific problem is encountered, or a specific requirement needs to be met. This can be achieved very easily with the following commands or equivalent:
cd /home2/cadwolfc
mv public_html old_public
git clone https://github.com/cakephp/cakephp.git public_html
Or symlink the document root
Alternatively put your files anywhere on the server, and just symlink the webroot:
/home2/cadwolfc/anywhere/app
/home2/cadwolfc/anywhere/lib
/home2/cadwolfc/anywhere/plugins
/home2/cadwolfc/anywhere/vendors
/home2/cadwolfc/anywhere/.htaccess
/home2/cadwolfc/anywhere/index.php
/home2/cadwolfc/public_html -> ../anywhere/app/webroot
In this way only the webroot is public and only the webroot .htaccess file is relevant.
Or copy/move the webroot
Alternatively put your files anywhere but move the webroot to the document root. Then update the root constant to point at where the source files are:
// app/webroot/index.php
/**
* The full path to the directory which holds "app", WITHOUT a trailing DS.
*
*/
if (!defined('ROOT')) {
define('ROOT', '/home2/cadwolfc/overhere';
}
What does cake_install mean?
In Cake's documentation, cake_install is explained as follows:
For the purposes of this example, we assume you chose to install CakePHP into /cake_install.
It's just an example. However, it's an example used in the "production install" section, a production install doesn't have all or the application files inside the document root. Setting up a "production install" with the source files inside the document root is not a production install, it's a custom development install (bringing with it custom problems).
Therefore the logical choice is (both of which are usable/secure with mod_rewrite):
Use a standard development install
use an actual production install
But not a hybrid of the two =)

Setup subdomain in new app directory with Cpanel cakephp

I have working domain.kz with cakephp (Cpanel hosting)
www/app
www/cake
www/index.php
how can i setup admin.domain.kz to (app2)
www/app
www/app2
www/cake
www/index.php
The way you want it - will be very difficult; you'll have to change several file/folder paths in several places. Instead, why don't you try to create an admin folder where you've the full cakephp application for admin.
So the resulting folder structure would be like this:
(domain.kz)
www/app
www/cake
www/index.php
(admin.domain.kz)
www/admin/app
www/admin/cake
www/admin/index.php
Then you'll have to point your subdomain (admin.domain.kz) to /www/admin.
Now assuming that you've configured your domain and subdomain correctly, if you try to browse your domain, it'll work with no issues but if you try to access your subdomain, it'll give you a 500 error. DON'T WORRY. It is expected.
The primary .htaccess file is forcing all requests served by primary webroot (www/app/webroot) folder. You'll have to change your primary .htaccess file (www/.htaccess) like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin\.domain\.kz$ [NC]
RewriteRule ^ - [L]
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Notice that, I've added two lines which tells that if you're trying to access your subdomain, stop rewriting; otherwise rewrite as usual. Cheers!!!
If the cake apps are totally separate but share a cake library then the following might work:
You could use cPanel's 'Addon Domain' feature, once the DNS has been set up for admin.domain.kz. Instructions can be found here.
Set the document root of the addon domain to the www/app2 folder.
Then just make sure that CAKE_CORE_INCLUDE_PATH in www/app2/webroot/index.php points to ../../../cake

Resources