Url not resolved on live server, working fine on local - php

My site was working perfectly on localhost everything was going good. When I uploaded it to the live server it works just again except one controller (UserPersonalityController.php)
All the controllers parsed and resolved perfectly except only one controller.
Before you answer let me tell you that
- My controller is uploaded (Not missing)
- I have checked by changing route but it couldn't resolved the UserPersonalityController.
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false,
'rules' => array(
'signup' => 'Credentials/create',
'signup/<id:\d+>' => 'User/create',
'signup/lookingfor/<id:\d+>' => 'lookingfor/create',
'signup/personality/<id:\w+>' => 'UserPersonality/create',
//checked by commenting above line, still problem occurs
'people' => 'credentials/index',
'people/*' => 'Credentials/index',
....
Do you have any idea why this happens?

For Url Management to work, first apache has to pass the url to yii only then yii can run the corresponding controller/action . Normally apache would process these urls as directories, and try to find corresponding files in these locations
You can create .htaccess file like this and place it in your root directory,
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
Note: For this to work you need to have rewrite engine enabled in apache config
You can do so with the following set of commands
In order to use mod_rewrite you can type the following command in the terminal:
a2enmod rewrite
Restart apache2 after
/etc/init.d/apache2 restart
or
service apache2 restart // (Ubuntu/Debian)

I've now answer of my question. As I have came across with the problems for several days. My local is in windows where files and directories are not case sensitive that's why it was working just fine. When I uploaded my site to the server (linux) it treats all file names and directories as case sensitive.
So controller UserPersonalityController was not same as UserpersonalityController because of the configuration of url manager in app.
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'caseSensitive' => false, //
The simple solution to the problem is to keep lower case names of controllers.
UserPersonalityController.php
UserpersonalityController.php
//Both above files are treated as completely different ones on linux while on windows
//they are same files.
Note Never capitalize any letter between controller names. First letter and letter C of controller must be capital. In between never keep any letter capital as you may run into problems. There might be other solutions to the problem. But I've solved by changing file names to lower case.
Further Reading: http://www.yiiframework.com/forum/index.php/topic/651-controller-file-name-case-sensitive/

Related

Module controller do not work in yii2 deployment on shared hosting

I deployed my php/Yii2 project (based on the basic template) to a shared hosting webspace. I want to access the project via an subdomain because an wordpress is running on the main domain. The normal controllers of the base project are working fine. The problem is that the framework can't find any controller that is in a module. The module itsef is registered properly.
The folder structure in the webspace is the following:
/
www
_wp (target folder of the main domain)
_project
web (target folder of the sub domain)
runtime
views
...
modules
testmodule
Module.php
views
models
controllers
The modules are configured like this:
'modules' => [
'testmodule' => [
'class' => 'app\modules\testmodule\Module',
],
],
The UrlManager is configured like this:
[
'showScriptName' => false,
'enablePrettyUrl' => true,
'enableStrictParsing' => false,
'rules' => array(
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>/<id:\d+>' => '<module>/<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>'
),
];
The .htaccess file in the _project\web looks like this:
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php? [L]
In the _project folder I do not have an .htaccess file.
On my local machine everything is working fine. On my webspace the controllers of the project itself are working fine. As soon as I navigate in a module i get an 404 Error of the yii framework. I debugged the project and found out that the module itself is loaded correctly. The problem is that the framework can not find the Controller Class because the function class_exists(controller) returns false. I don’t have an idea what i can do to fix this. Hopefully somesone here can help me, thanks a lot!
thanks to the comment of Michal Hynčica! I wrote my controllers lower case and yii2 is looking for them with CamelCase. This worked on windows. But on my shared hosting based on this did not work because of Case-sensivity!

Enabling pretty URLs / urlManager completely breaks Yii 2 application runnikg as a REST micro-framework

tl;dr My Yii 2 app, running as a micro-framework, works just fine when using standard ("not pretty") URLs. However when the urlManager application component is enabled in the configuration, the entire application breaks completely and every call to it ends with 404.
Following my other question, I am trying to run a minimalist version (micro framework) of Yii 2 app to act as an RESTful endpoint. I've followed the guide and everything seems to be working when I am calling a standard ("not pretty") URLs:
As suggested in the guide, I have enabled routing / pretty URLs in my application:
'urlManager' => [
'enablePrettyUrl' => true,
'enableStrictParsing' => true,
'showScriptName' => false,
'rules' => [
['class' => 'yii\rest\UrlRule', 'controller' => 'post'],
],
]
And suddenly my application stops working at all. It serves neither non-pretty:
nor pretty URLs:
It even fails to serve the default controller and action -- site/index.
What am I missing?
It seems that I have everything that I need. Following the guide I have:
Created the micro-framework application skeleton
Created default controller (site) and default action (index)
Configured db component, run migrations and created database
Created PostController
Enabled routing by adding Yii code to application configuration (see code example above) and by creating corresponding .httaccess file:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
What else must I do in order to make the whole thing work or what am I missing here? Thanks!
Remove this line:
'enableStrictParsing' => true,
This question comes from an misunderstanding. I wasn't aware that when pretty URLs are enabled then yii\rest\UrlRule::$pluralize is set to true by default. Meaning that the request must be:
http://localhost/micro-app/posts
(plural controller name; notice "s" at the end)
Not:
http://localhost/micro-app/post
(singular controller name)
It is also completely normal that when pretty URLs are enabled then regular URLs doesn't work anymore. That's the reason for getting 404 File Not Found on http://localhost/micro-app/index.php?r=post URL when pretty URLs are enabled.

yii2 pretty url - browser does not find file index.php

I am trying to set-up Yii2 to use pretty URL.
In order to do so, I configured Yii2 and used the rewrite module of apache to make sure that we always enter by the entry point which is index.php
I made the following modification in the .htaccess file contained in the yii-application/frontend/web/ folder - folder that contains index.php (advanced yii2 template). For those modifications, I followed instructions found on various forums.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I have also made the following changes in the configuration of yii2 in order to activate pretty URL
$config = [
'components' => [
'urlManager' => [
'showScriptName' => false,
'enablePrettyUrl' => true,
'rules' => array(
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
],
],
];
Note that Yii2 was working well before I made those changes.
Now if I try to connect using one of the following URL (like before modification), I see the landing page. The navigation will not work, I will always see the landing page.
http://localhost/frontend/
http://localhost/frontend/index.php
http://localhost/frontend/index.php?r=site/about-us
http://localhost/frontend/index.php?r=site/faq
If I try to connect using of the URLs below (as I should once pretty URL is configured properly), my brower displays an error message.
http://localhost/frontend/site/faq
http://localhost/frontend/site/account
http://localhost/frontend/site/index
Error message:
Not Found
The requested URL /web/yii-application/frontend/web/index.php was not found on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80
However, it looks like the path is correct. The index.php file is actually in the folder C:\web\yii-application\frontend\web\index.php
How come my browser does not find the file?
Thanks for your help
From all your requests you are missing the web folder.
All your URLs should be
http://localhost/frontend/web/
http://localhost/frontend/web/index.php
http://localhost/frontend/web/index.php?r=site/about-us
http://localhost/frontend/web/index.php?r=site/faq
http://localhost/frontend/web/site/faq
http://localhost/frontend/web/site/account
http://localhost/frontend/web/site/index
Unless you set up a folder redirection but considering how you have things set up I seriously doubt that.

How to rewrite domain with Yii urlManager

I've installed humhub to one of my servers. There's a reverse proxy server at the entrance of my network and the humhub server works behind it. A domain name is given to the humhub server:'vm-humhub'.
I want to rewrite URLs because humhub puts all URLs with the domain name 'vm-humhub', which is not valid when accessing out of my network. I want to replace http://vm-humhub into https://mydomain.com.
I first tried to rewrite URLs by apache, writing in default-ssl.conf like this:
<Location /humhub>
ProxyPass http://vm-humhub/humhub
ProxyPassReverse http://vm-humhub/humhub
RequestHeader set X_Forwarded_proto 'https'
RequestHeader unset Accept-Encoding
ProxyHTMLEnable On
ProxyHTMLURLMap http://vm-humhub/humhub/ https://mydomain.com/humhub/
ProxyHTMLExtended On
ProxyHTMLCharsetOut utf8
</Location>
When I see the HTML, all the URLs were successfully rewrited. However, javascript didn't work well and the page stops loading messages.
Because humhub works on Yii framework, I thought it natural rewriting urls using urlManager of Yii (And official install guide writs so).
However, I know nothing of Yii. After googling a while, I wrote in the conf file:
<?php return array (
'components' =>
array (
'urlManager' => array(
'urlFormat' => 'get',
'showScriptName' => false,
'rules' => array(
'http://vm-humhub' => 'https://mydomain.com',
),
),
....
But nothing happened. Somebody can help me?
I don't believe that you can rewrite the domain in the same way as you can rewrite the URLs since the domain was used to locate your Yii code.
I thing the base problem is that you have an error in your proxy pass configuration.
I've basically the same setup working using these parameters in apache config:
SSLProxyVerify none
SSLProxyCheckPeerCN off
SSLProxyCheckPeerName off
ProxyPreserveHost On
ProxyRequests Off
ProxyPass / http://localhost:8080/
ProxyPassReverse / http://localhost:8080/
Hope that helps - maybe someone else who stumbbles on this post as it's quite old ;-)

Yii - Parameterizing Hostnames not working

I would like to be able to assign dynamic subdomains to every company that signs up on my website. I know this question has been asked many times on Stackoverflow (e.g. Dynamic creation of subdomains), but those solutions are not working for me. I might have something else going wrong somewhere, hence I created a new thread.
I would like to be able to have URLs like this:
http://mycompany.testing.com/office
My site is in a subdirectory like this:
htdocs/office
I have my urlManager setup like this:
'urlManager' => array(
'urlFormat' => 'path',
'showScriptName' => false,
'rules' => array(
'http://<company:\w+>.testing.com/office' => 'office',
'/<action:\w+>' => '/index/<action>',
'<controller:\w+>/<id:\d+>' => '<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
),
)
My apache virtual host entry looks like this:
<VirtualHost *.testing.com>
...
DocumentRoot "C:/xampp/htdocs/office"
ServerName www.testing.com
ServerAlias *.testing.com
<Directory "C:/xampp/htdocs/office">
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
I added 127.0.0.1 *.testing.com in my Windows hosts file. And my htaccess file looks like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
I have tried following the Yii guide (which shows this as a very simple task), but I think I might have messed up something outside the application itself.
Any input will be highly appreciated :-)
Have a good day.
By default Windows hosts file doesn't accept wildcard domains. However, there is an alternative for hosts file.
It that's just your test server, simplest solution is to add a few testing subdomains to your hosts file and that should work (mycompany1.testing.com, mycompany2.testing.com ...).

Categories