CakePHP: trying to install an application in a subdomain - cakephp

I'm trying to install a CakePHP app on a subdomain in my server. I want to make an advanced installation and separate the core and app libs from the webroot directory.
I put the entire project in a folder on home directory and move the content of webroot directory to subdomain's httpdocs directory.
Then, it looks like:
subdomains-httpdocs:
drwxrwxrwx 2 root root 4096 Mar 21 08:34 css
-rwxrwxrwx 1 root root 2760 Mar 21 08:34 css.php
-rwxrwxrwx 1 root root 374 Mar 21 08:34 favicon.ico
drwxrwxrwx 2 root root 4096 Mar 21 08:34 files
drwxrwxrwx 2 root root 4096 Mar 21 08:34 img
-rwxrwxrwx 1 root root 2731 Mar 21 08:43 index.php
drwxrwxrwx 2 root root 4096 Mar 21 08:34 js
-rwxrwxrwx 1 root root 3086 Mar 21 08:34 test.php
I edited the index.php file and change ROOT and APPDIR constants to point cake holder and app folders (at home directory), respectively. Finally, I modified the .htaccess files (3 files) adding RewriteBase parameter pointing to app directory (as cook book says http://book.cakephp.org/view/917/Apache-and-mod_rewrite-and-htaccess).
I checked that mod_rewrite is loaded in apache and AllowOverride All is active, but it doesn't work. It responses HTTP 500 everytime.
If I put the entire project in httpdocs directory (including webroot directory), it works perfectly.
Can you help me with this?
UPDATE
I checked again and it works if all directories are in httpdocs folder (core and app directories). However, they don't work in another location.
It returns
Warning: include(cake/bootstrap.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/mydomain.com/subdomains/subscribers/httpdocs/apptest/webroot/index.php on line 83
Warning: include(cake/bootstrap.php) [function.include]: failed to open stream: No such file or directory in /var/www/vhosts/mydomain.com/subdomains/subscribers/httpdocs/apptest/webroot/index.php on line 83
Warning: include() [function.include]: Failed opening 'cake/bootstrap.php' for inclusion (include_path='/home/systemtest:/home/systemtest/app/:.:') in /var/www/vhosts/mydomain.com/subdomains/subscribers/httpdocs/apptest/webroot/index.php on line 83
Thanks in advance

I found a solution:
After trying different things, I figured out that the problem was with webserver permissions. When the app and cake folder was in httpdocs directory, the application worked perfectly but after moving them to another directory, index.php was returning a HTTP 500 indicating that failed opening files in cake core directory.
The solution was to add a VirtualHost in httpd.include file of the subdomain:
<VirtualHost xx.xx.xx.xxx.xx:80>
ServerName subdomain.mydomain.com
Alias /myapp /home/myapp/app/webroot
DocumentRoot /home/myapp/app/webroot
<Directory /home/myapp/app/webroot>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
I thought that I could separate app, cake and webroot directories and manage installation with .htaccess with no apache specific virtual host.
Thanks to Amy and Leo for their help

This could be done in a different way.
There are some restrictions on which directory-paths can be opened in php.
PHP defines the open_basedir directive which in turn limits the
files that can be included.
On virtual hosting (such as your case) the default directory-tree includes
only your $_SERVER['DOCUMENT_ROOT'] and /tmp directories so there is no way
for you to include the cake core if it located elsewhere.
A clean and simple solution is to append the absolute path of the directory
in which you will store the cake core, in your php.ini
After that you simply define your CAKE_CORE_INCLUDE_PATH to point
at the directory in which cake core is installed.
This way you avoid adding a VirtualHost directive in httpd.conf
for every application you create, that runs on a subdomain or even the domain itself.
Hope that was helpful.

Jose
Leave the ROOT and APPDIR alone ( in your /app/index.php ) and just change the CAKE_CORE_INCLUDE_PATH in /app/webroot/index.php
/**
* The absolute path to the "cake" directory, WITHOUT a trailing DS.
*
*/
if (!defined('CAKE_CORE_INCLUDE_PATH')) {
define(
'CAKE_CORE_INCLUDE_PATH',
DS . 'usr' . DS .'share' . DS . 'cakephp' . DS . '1.3.6'
);
}
That will read the core libs from a shared source. Add the cake core source path into the php include path if cake can't set it.

Related

Forbidden, you don't have permission to access this resource after Ubuntu update

The last time I applied updates to my Ubuntu 22.04.1 LTS it clobbered my /etc/apache2/sites-available/000-default.conf file resetting it to the default. There was a file 000-default.dpkg-old which seemed to have the old contents, so I copied that back to replace 000-default.conf. I restarted the Apache2 server, but now I get "Forbidden, you don't have permission to access this resource". I have not changed anything else
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and por...
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
#ServerName www.example.com
ServerAdmin webmaster#localhost
DocumentRoot /home/jcobban/public_html
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
</VirtualHost>
I have not changed the access to the web site directory.
$ ls -ld public_html
drwxrwxr-x 26 jcobban www-data 12288 Jan 20 18:27 public_html
/etc/apache2/sites-available$ ls -l
total 16
-rw-r--r-- 1 root root 1344 Feb 18 2020 000-default.conf
-rw-r--r-- 1 root root 1286 Jan 17 22:41 000-default.conf.new
-rw-r--r-- 1 root root 6219 Jan 17 22:41 default-ssl.conf
000-default.conf.new is what I renamed the version installed by Ubuntu
Exactly what "resource" is Apache complaining about?

apache2 403 forbidden on parent directory

When I try to access the parent directory, say localhost/parent, it gives me 403 forbidden. However if I access the sub-directory, say localhost/parent/index.html, it goes through.
I believe it's a config issue but could anyone walk me through a bit here?
I tried to change the apache2.conf as many people suggested but it doesn't work.(shown below)
<Directory "your directory here">
Order allow,deny
Allow from all
Require all granted
</Directory>
The following is what error log says:
[Mon Jul 03 11:32:51.028149 2017] [autoindex:error] [pid 4899] [client 127.0.0.1:42462] AH01276: Cannot serve directory /var/www/html/hub/: No matching DirectoryIndex (index.php,index.cgi,index.pl,index.php,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive
It turned out to be a config file issue,
sudo nano /etc/apache2/mods-enabled/dir.conf
Make index.php as the first option and it solved the problem

Laravel 5.2 - Getting 500 error when connecting with CSRF disabled

I am having an issue where I'm getting a 500 internal error when connecting to my Laravel API.
I had my site originally on GoDaddy using example.com as the main site and api.example.com as the api, but then decided to move it to Google Cloud Platform. I went ahead and set up an instance in the Google Compute Engine using Debian 8. I am using ISPConfig 3 to do all my server stuff. I have my site and my api in two separate repos on Github. I went my server directory to /var/www/example.com/web and cloned my main site into it. Since this create a folder within the root directory of my site, I also went into the vhost and set the default directory to point to the new cloned directory.
I then created another site with ISPConfig for my api and went into the DNS and created a A record and pointed it to the same IP as my main site. I then went into /var/www/api.example.com/web and cloned my api's repo into it, just like my main site. I went into the vhost for my api and pointed the default directory to my new cloned directory.
I can go to example.com just fine, but when I try to log in (this is the first point an api call is made), I get a 500 internal error.
I'm not using CORS and I never have because I use my own JSON web tokens, therefore my CORS is turned off.
Any ideas on how to fix the 500 error?
EDIT
Formatting
Edit 2
These are the last two lines in the error log for apache:
[Sat Sep 24 21:17:17.095798 2016] [core:crit] [pid 17588] (13)Permission denied: AH00529: /var/www/api.example.com/web/api/public/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
[Sat Sep 24 21:17:17.095875 2016] [authz_core:error] [pid 17588] AH01630: client denied by server configuration: /var/www/api.example.com/web/error/403.html, referer: http://example.com/login
I'm not sure why it's throwing this .htaccess error. It's the .htaccess that Laravel automatically created.
Errors says what is your problem: Permission denied: AH00529: /var/www/api.example.com/web/api/public/.htaccess pcfg_openfile: unable to check htaccess file, ensure it is readable
Make htaccess readable using chmod command:
chmod 644 /var/www/api.example.com/web/api/public/.htaccess
Also check this answers if this not help

New site conf file for Apache 2.4.6

I had just upgraded to Ubuntu 13.10 earlier today. The version of Apache2 is 2.4.6 now. I removed the old site config file and tried to create a new one. When I was trying to copy default.conf, I found the format had been changed significantly. And here is an example of the new conf file. As lots of people do, I also have the forbidden problem even if I set my folder permission to 777.
1 <VirtualHost *:80>
2 # The ServerName directive sets the request scheme, hostname and port th at
3 # the server uses to identify itself. This is used when creating
4 # redirection URLs. In the context of virtual hosts, the ServerName
5 # specifies what hostname must appear in the request's Host: header to
6 # match this virtual host. For the default virtual host (this file) this
7 # value is not decisive as it is used as a last resort host regardless.
8 # However, you must set it for any further virtual host explicitly.
9 ServerName www.janicezhang.me
10
11 ServerAdmin webmaster#localhost
12 DocumentRoot /home/yifan/www/janice
13
14 # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
15 # error, crit, alert, emerg.
16 # It is also possible to configure the loglevel for particular
17 # modules, e.g.
18 #LogLevel info ssl:warn
19
20 ErrorLog ${APACHE_LOG_DIR}/error.log
21 CustomLog ${APACHE_LOG_DIR}/access.log combined
22
23 # For most configuration files from conf-available/, which are
24 # enabled or disabled at a global level, it is possible to
25 # include a line for only one particular virtual host. For example the
26 # following line enables the CGI configuration for this host only
27 # after it has been globally disabled with "a2disconf".
28 #Include conf-available/serve-cgi-bin.conf
29 </VirtualHost>
I am just wondering if there is some toturial to set up virtual host for apache 2.4.6 in ubuntu 13.10. Thanks.
OK, I solved the problem by myself. Two things need to be done.
First, add lines in your site config file like this:
<Directory "/home/yifan/www/janice">
Options ExecCGI
AllowOverride all
Require all granted
</Directory>
After this, I can browse into the site without the forbidden error. However, the php file is displayed as plain text. I check the folder mods-enabled and find php5 is not here. I have no idea why php5 is lost during upgrading. So just reinstall it by
sudo apt-get install libapache2-mod-php5
Then, the site is recovered.

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 =)

Resources