CakePHP in sub-url (not sub-directory) - php

I can find dozens of articles on installing CakePHP in a sub-directory and getting it to appear in the root url. That is NOT what I am asking for. I rarely down-vote, but if you give that answer, I will down vote you.
I have CakePHP in my root directory on my hosting server. It's a clean Apache server instance... I think. I'm really not a server guy. I created a new account through WHM on Hostgator and have CakePHP sitting in the public_html.
However, there is no domain name associated with this server yet. The URL is like this:
http://123.456.0.0/~example/
And CakePHP gives me the following errors:
Error: ~exampleController could not be found.
Error: Create the class ~exampleController below in file:
app/Controller/~exampleController.php
I imagine there's some .htaccess configuration that makes it ignore that /~example in the URL. Can someone point me in the right direction, even if it's just the right page in the CakePHP docs?

By partially following the advice at http://bakery.cakephp.org/articles/syl-via/2011/09/19/rewritebase_config_for_cake_installation_with_userdir_and_mod_rewrite I was able to make this work by adding the following to the .htaccess file in the root of the Cake install:
RewriteBase /~example
I put this after RewriteEngine on for it to work.
In other words, if your Cake install is at /home/example/ then it's the /home/example/.htaccess file that you'd change.
I didn't edit app/.htaccess or app/webroot/.htaccess because it seems to work without these files needing to be edited.
Please note that I tested this with the latest version of Cake (2.3.5) -- I don't know if it will work the same way in older versions.

Related

Creating new app with laravel/installer shows just file structure not website

I just decide to start learning Laravel. By following Getting Started most easy solution for me seems to be to start using laravel installer.
So what I did was installed installer globally and then simply created new project via laravel new laravelapi.
After cli prepare it I edited .env file with my database info and changed APP_URL to http://localhost/laravelapi/ (I'm using XAMPP and laravelapi is name of my project). Unfortunately when I opened browser on that URL I just see the files, not a rendered website.
Funny thing is that when i open http://localhost/laravelapi/server.php site load correctly (it's just some trivial laravel default page)
I was wondering if htaccess works correctly I tried to check if my apache has mod_rewrite as one of his loaded module but it was there.
I am really new in it and I obviously missed something important, but I fight here with it for couple hours without any result. Does anyone face this issue before? If so what was the solution?
The Document Root for a Laravel project is the public directory. All user requests should be routed to public/index.php unless the file requested exists within the public directory -- e.g: assets.
You can change the document root for an xampp operated project by following the steps provided in this StackOverflow answer.
Its not good practice to access project through "http://localhost/laravelapi/public"
Probably you will face problems for symbolic links or while hosting your project. It's good to have vHost for your PHP projects.
You can create a vhost for xampp and add document root upto the public directory of your project for Laravel, like as "../Project/laravelapi/public".
Also you can use inbuilt development server command as php artisan serve
which will start your server on "http://localhost:8000".
More helpful links
1. Laravel Documentation - here
2. vHost for Xampp - Here
I got the same issue were two reasons behind the error.
one is not a proper .htaccess file placed in the root directory.
other php version is not compatible with your laravel current version (low PHP version).
You can create another .htaccess file in the main directory which will indicate that your project root is the PUBLIC folder. It will solve your problem.
you can try the sample code below.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I had same issue but I solved this problem. When we install Laravel then .htaccess file is in the public folder.
Cut the .htaccess file from the public folder
Paste this file in root folder of project

Symfony framework install 406 Not Acceptable Error w/CPanel & WHM

So I am trying to get Symfony working on my server by following these install instructions.
http://symfony.com/doc/current/book/installation.html#book-installation-permissions
I got to the part where I ran this command in console in the directory where I wanted the framework to be installed.
symfony new my_project_name
I then followed these instructions to set my web root directory to /web as I believe I'm supposed to do?
It installed all the files correctly since I can see them in the folder. I made sure to restart apache and I'm positive document root is in the correct location.
http://tecadmin.net/how-to-change-document-root-of-primary-domain-in-cpanel/#
Once I did this I was supposed to be able to test the installation, but nothing seems to happen except that 406 error?
This is the exact error I get.
An appropriate representation of the requested resource /app.php could not be found on this server.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
I'm not sure what else to do.
Please note, that since I'm using CPANEL I can't change the virtual host configurations of apache if that is the issue, so I'm looking for a CPanel specific answer. Thank you!
Okay so I finally figured out what to do, I had 2 problems. Because I installed as the 'root' user I had to run the following command on the symfony installation.
chown -R devdistribution:devdistribution .
In my case, my username is devdistribution but you would just put your own. Make sure to do this on the top level not just the /web folder.
I knew this was one of the errors because the apache log said something along these lines
Mismatch between target UID (520) and UID (501) of file "/home/devdistribution/public_html/distribution_tech/web/app.php"
This fixed the 500 error, but not the 406. To fix the 406 error you need to login into WHM and type modsecurity to find it in the search field.
go to the configuration option for it, you will see this.
Rules Engine SecRuleEngine
This setting controls the behavior of the rules engine.
Process the rules.
Do not process the rules.
Process the rules in verbose mode, but do not execute disruptive actions.
Select 'Do not process the rules'. Then save at the bottom. This fixed the issue for me and I was able to see the opening symfony screen!
However, this I'm sure leaves security vulnerabilities now...so I still need help on the proper way to handle mod security with symfony in this case if anyone knows? I'll make a separate question for this.
Step 1:
Login to your cPanel account and start searching for the file manager icon under the files section.
Step 2:
As always, you need to make sure, you see the public_html directory. Depending on the web hosting you have, you may also see the home directory after opening the file manager.
Step 3:
Find the .htaccess file and right-click to edit.
Step 4:
After choosing an edit option, you see a popup asking to disable encoding if you wish. You have to click on the Edit button to continue.
Step 5:
On a new tab, you can see many rewritten rules. You have to add the code to the .htaccess file.
<IfModule mod_security.c>
SecFilterEngineOff
SecFilterScanPOSTOff
</IfModule>

Installing Silverstripe 3.1 on subdomain

First time asking a question here but I'm really stuck.
Basically I'm trying to install a Silverstripe 3.1 cms on a subdomain as a development site, on my main domain I already have a Silverstripe 2.4 site running.
The first thing that comes up is this error, "development" is the subdomain folder.
Warning: require_once(framework/dev/install/DatabaseConfigurationHelper.php): failed to open stream: No such file or directory in /home/usr/public_html/subdomain/framework/dev/install/install.php5 on line 39
I check if the file is there and it is, then I check if the filepath is wrong because the file that is calling require_once has a full path from home/ but that can't be it because I've been able to install Silverstripe on my localhost.
I google redirecting (I've had no experience with it before) and find stuff on htaccess related to Silverstripe but none were problems that I was having, i.e. there are .htaccess files in main directory and subdomain. Not too sure if they're conflicting but I have tried RewriteEngine Off on my subdomain. I mostly leave the default Silverstripe .htaccess files as they are.
Even declaring different suPHP_ConfigPath's i.e.
main website: home/usr/public_html/
subdomain: home/usr/public_html/subdomain
At this point I look back at the error and try hacking the require_once filepath, changing it to
$_SERVER["DOCUMENT_ROOT"] . '/framework/dev/install/DatabaseConfigurationHelper.php
It mostly works but the requirements check page is void of css and any fails to GET any images
I am able to check all the requirements though passing everything but the File Permissions check:
"Does the webserver know where files are stored?" failed. Showing me the filepath it tried being the absolute path of a file prepended with the path to the subdomain. Looking at the code my hack was never intended to work.
Did I miss something? I'm not very knowledgeable with servers but I've done everything I can think of, is there anything I can do?
Hey thanks for your suggestion but I think it was meant for addon domains? I only wanted a subdomain for testing purposes.
What I ended up doing was to avoid installing Silverstripe on the server and instead install it on my laptop and then upload that to the server. It worked fine after copying the appropriate database and fixing Silverstripe's BaseURL to '/'

Fresh lithium framework installation returns error 403

I read the docs and installed lithium exactly like they have explained but I keep on getting a 403 forbidden error. I am new to apache and php and I have been spending two full days trying to make lithium work. I am running apache 2.0 on osx lion and here is what I did:
1- I created a new directory called my_app in localhost/~marwan/
2- I extracted the sample lithium app in to that directory.
3- I downloaded the lithium framework and extracted it into /libraries/lithium/
When I access http://localhost/~marwan/my_app/ I get the following 403 error:
You don't have permission to access /~marwan/mj/ on this server.
I have researched and added Options +FollowSymLinks to the .htaccess file and the error changed to:
You don't have permission to access
/Users/marwan/Sites/my_app/app/webroot/webroot/ on this server.
I have tried to add Options +FollowSymLinks to every .htaccess file but nothing changed.
I dont know if this is relevant: websites on localhost/~marwan/ work but localhost also shows a 403 error. I tried to fiddle with different permissions posted in previous answers but with no luck.
Thank you for your help.
httpd.conf file is here http://pastebin.com/jLwHPbuq
Edit:
httpd-userdir.conf is here http://pastebin.com/ZXi51pn7
httpd-vhosts.conf is here http://pastebin.com/3xqRmrzL
Update
The lithium project works when I remove the .htaccess from the main folder but it doesnt work properly because rewriting doesnt work. Here is the .htacces in the project root http://pastebin.com/vt0fVyyL
The path you provide in the error message /~marwan/mj/ and the path you provide that you are trying to reach http://localhost/~marwan/my_app/ do not match. According to the error the web server says you are trying to access a directory called mj while your url does not include mj so unless you are doing some URL rewriting this looks like an issue.
Also, just to be clear, when you say you installed the library in /libraries/litium you mean relative to the web root path, correct?
OK, looking at your conf files you can serve files out of /Library/WebServer/Documents or out of ~/Sites (that tilde represents your user directory so it is the same path as /Users/marwan/Sites)
Do this...
In /Library/WebServer/Documents place a file called index.html and have it output some text.
Make sure there are no .htaccess files in /Library/WebServer/Documents.
Make sure you have not modified your httpd.conf file in any way from its default settings.
Do you see the correct behavior for your index.html (you should)? If not, what happens?
I looked at the error log after restarting apache and found DocumentRoot [/usr/docs/dummy-host.example.com] does not exist so I fixed it by using this answer stackoverflow.com/questions/6671042/… and now it works.

PHP CodeIgniter 404 on deploy

Oooops I did it again.
My site worked perfectly locally
My development machine is a windows WAMP2 setup
My server is a CentOS 5.5 APACHE 2.2 PHP5 seup
I'm getting a 404 on the codeigniter site that I've deployed, and I really can't make out what's wrong, so please help me find the error.
It's the root url. I haven't set up dns so it's just the ip address of the server. It was showing the standard apache page before I uploaded codeigniter. I've looked over the config file, and it looks ok. Could it be a file permissions error? i have set chmod o+rw in the whole /var/www/html dir. the error_log in the httpd shows nothing
I've tried testing if it was the mod_rewrite module, but I created a test directory with a .htaccess file with RewriteEngine ON that didn't give me an error, so that can't be it.
In codeigniter I've set the log_threshold to 4 in the config, but I don't get any log messages, so I can't really make out if it's a pre-> codeigniter error, but I really don't think it is, as it's loading my Error view, still Why isn't there any log being written, what's it about?
Any help would be extremely appreciated as I'm running on fumes to get this working...
Update
Thanks to #jondavidjohn I have discovered that hitting the controller directly IE:
http://addr/index.php/GeoController/markers/
Will provide me with a controller specific error saying:
unable to locate your model "modelname"
SOLVED
Thanks to #jondavidjohn, and #timdream for giving me the clues to solve this one. It was a naming problem, I had filenames that were camelcased, and they can only be small from what I understand now, so the ROUTE was innefective in that it lead to Site, but should've lead to site although I had a Site.php I had to change it and the route to site.php
make sure you have the correct settings in system/application/config/config.php.. pay special attention to
$config['base_url'] = "http://www.example.com";
Make sure you are putting in the root domain of your site, also check your routing config and make sure you have the correct default controller set in system/application/config/routes.php
I recently started using a fresh install of codeignitor 3.0 and had no problems on my dev server (Windows) then when I moved to my live server (Linux) I started getting a 404 error.
The reason for this is that in 3.0 you are meant to capitalise the first letter of your controllers/models and also the file name.
e.g.
class Test_model extends CI_Model {
Test_model.php
Hope this helps some people who end up here!
For reference:
http://www.codeigniter.com/userguide3/installation/upgrade_300.html
$config['uri_protocol'] could also play a part. It's default to AUTO, which looks for environment variable that contains the actual URL automatically.
I had a web app that fails when I switch to php-cgi from mod_php for my server. Changing the config to REQUEST_URI solves the issue. I found the valve by digging phpinfo() outputs, you could try to do that.
My first bet is that you were developing this and modified the .htaccess file.
HOWEVER, if you went from a Windows -> Linux system change (dev on Win, prod on nix) then you have to keep the Controller names in mind, if a file on windows was "Home.php", and you used "home.php" in the config as your default route, then it will fail.. as there is no "home.php" file.
Home.php != home.php
Linux is case sensitive. Check that out, it might be a simple thing but could cause snags.
Again I am just guessing due to lack of details.

Categories