zend framework 2 project in server doesn't work - php

Working with zf2, we have configured the project successfully in local env, we deployed the same code to server, but there..only the IndexController action is working.
like www.project.com/public/ works,
but when I access other modules like
www.project.com/public/country doesn't work.

This means the mod_rewrite rules to rewrite all requests to your index.php file are not being used. Generally this means either:
The .htaccess file was not uploaded (check the public folder on the server to see if it's there)
The .htaccess file is being ignored (check AllowOverride for the vhost on the live server)
Also, really public/ should not appear in your URLs. Unless you are using shared hosting (where this can be tricky), you want to point your vhost's document root at the public folder.

In a proper Zend setup an error should come from Zend. When you get an error like this, returned from Apache, your apache configuration is not working. Your Zend application isn't even considered, i.e. the index.php in your public folder.
It's a save guess that your [public/].htaccess isn't used. Check your apache web configuration. Most likely you're missing the AllowOverride All statement which is usually inside the <Directory> statement.
And as mentioned by Tim you really should not have public/ in your path to begin with.

Related

How to use symfony environments dev and prod

This may seem a dumb question, I need my symfony 3 app to behave different in production than it does in my local machine. I know there is an entry point for each env, app.php and app_dev.php
I don't want to change the application web/.htaccess file because it's followed by git, I was expecting an 'env' var or something similar in app/config.yml but there is also a config.yml and a config_dev.yml, so it has to be another place where I can define if I am working with prod or dev env.
Documentation says that I need to setup my apache server to use either web/app.php or web/app_dev.php, and this is my question. I'm using apache 2.4 and I tried using the following directive:
<VirtualHost *:8000>
<directory>
...
DirectoryIndex app_dev.php
</directory>
</VirtualHost>
I restarted apache, but when I type localhost:8000 in my browser, it keeps using the default app.php, I need my apache server to use app_dev.php, I don't want to use the built-in server because it gets buggy after a while.
Can anyone please help me with the apache configuration to use the dev env?
I think you have the following problems: regardless of which DirectoryIndex you define, the server also picks ups some settings from .htaccess. Could it be possible that you have another reference to app.php in there, like RewriteRule ^(.*)$ app.php [QSA,L]?
Then you could do the following: move that exact setting from .htaccess to your server configuration, both locally and on the production server. Then you can keep all other settings independent from your enviroment.
If this does not help yet, please share the content of .htaccess.
Another way of solving could be to use a recent Symfony version and put everything that might change between environments in the .env file. Don't put it under version control, as this file might contain sensitive information. Then have a look at the current basics: you no longer have a app.php and app_dev.php, as the changes were only little. A common index.php is used, and it reads all current settings from .env

How can the document root be changed in web server behavior?

I'd like to know if there is a way of changing the relative document root for extra security. I'll try to explain myself through the following example:
/root
/app
/public
Say an www.example.com request to the web server would point to the root folder.
I was wondering if there was a configuration, for instance through an .htaccess file located in said root folder, that would make the server point to the public folder instead, therefore having any remote paths always be relative to said public folder.
In this instance, www.example.com/app would request an app folder inside of public, instead of an app folder inside of root, leaving the latter to be inaccessible from a remote url request.
In the same manner, www.example.com/public would request a public folder inside of our root public folder and so forth.
I've read various topics like this one that mention using a custom .htaccess configuration to achieve something similar, but it requires the manual configuration of the request url in said file, while my intention is for it to work without further configuration no matter where you host the application.
Another possible solution I've seen is doing a hard redirect through the .htaccess file, which does not solve anything actually.
Feel free to edit this post as I might have had a hard time trying to get my point across.
You can use this simple .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L]
</IfModule>
Any request on your server will point to the public folder.
Inside the public folder you can add an extra .htaccess file handling your site rules.
Also you can Host multiple sites on One webserver. You can combine making VirtualHosts and Alias using mod_alias mentioned before
In this example is suposed to have your own server (either dedicated or VPS)
By using Virtualhosts you can tell to the webserver when you recieve a request to www.example.com to serve content from a specific folder.
An example Virtualhost of it is:
<Virtualhost *:80>
ServerName ^domain_or_ip^
DocumentRoot ^path of the public folder^
DirectoryIndex index.php home.php index.html index.htm
ErrorLog ^path for a file containing php errors^
CustomLog ^path for logging whitch browser and ip visited your site^ combined
</Virtualhost>
I suggest that you point your server to the public folder anyhow, as it is much more secure, you could see that all frameworks behave the same way, they all have a "public" folder where the server points to.
In the public folder you have one point of entry to your scripts, like
index.php
and from this entry you will communicate with your application.
Of course you can still work the way you requested, and it will work great, but who knows maybe you will miss something and someone could access and view your "inner" files.
You're on Apache web server? If I understand correctly, you're looking for Virtual Directories. Usually, we have to put our web application inside the document root of Apache in order to make the application accessible from the network. However, there is a trick to make the web application still accessible even though we put it outside of Apache's document root. Please read up on that here: http://w3shaman.com/article/creating-virtual-directory-apache
Credits to W3Shaman.com, obviously.

.htaccess file won't respond on localhost:63342 in PhpStorm

I'm using the IDE PhpStorm 7.1.4 and trying to make an .htaccess file to stop users from going into a specific directory.
My folder structure is like this:
I want to make it so that users can't go in the /app folder or any folders inside that folder. For this, I've figured out that I can use this piece of code inside .htaccess:
Options -Indexes
I'm using the PHP web server from PHPStorm itself (which goes to localhost:63342/projectname/folderinproject/etc/etc/).
Problems
When directing to the page to the /app folder, I get an 404 error,
saying the index file doesn't exist.
When I have made an index.php file inside the /app folder, and I am redirecting to the /app folder, it just loading up the index.php.
When doing this with just a normal HTML project and opening the index.html via my windows explorer, the same problem occurs
Question
How can I make it so that my project would actually respond on the .htaccess file and wont allow me or other users to go into the /app folder?
EDIT
I figured out that when I copy all my files from my project to the c:\xampp\htdocs\ folder and turn on my Apache server inside of XAMPP, the .htaccess file is working whenever I open it via my regular browser (without selecting index.php in PhpStorm and choosing Open in browser...).
Is there any way I can do this same thing in PhpStorm without moving all the files?
If you are using the default configured web server, you are actually using PHP's new web server feature, which doesn't listen to .htaccess files. Only Apache listens to .htaccess files.
If you are wanting to test this functionality, you can either setup a VM running Linux and test, or setup WAMP on your system and run from there.
EDIT 1
Ok, can you add a little more detail about the exact problem? When you access localhost/app/ it is displaying the index.php file, instead of the 404. Does the application work entirely through the index.php file? If so, is the index.php file in the app or public?
EDIT 2
Ok, here's what you need to do. Place an .htaccess file in the root of your app directory. Clear the contents of this .htaccess and place the line DENY from ALL. You can keep the .htaccess file in the root of the project.
EDIT 3
PHPStorm is going to use the PHP Engine's web server. If you add the XAMPP location as a deployment path, it's fairly quick to deploy to. You can even setup PHPStorm to automatically deploy files to the XAMPP location on save. Here's the walk-through on the JetBrains site JetBrains Config.
The .htaccess plugins are mainly for editing and formating, not for modifying PHP Engine's server environment.
Using mod_alias is even easier:
Redirect 301 /app /new_directory
But if you have rewrite rules in your htaccess file already, then you need to stick with using mod_rewrite:
RewriteRule ^app/(.*)$ /new_directory/$1 [L,R=301]

EzPublish 5 friendly URL's won't work

i have set up a local EzPUblish 5 installation, and it seems to work, with one exception: friendly URLs.
When I go to http://arabia.local/index.php/Frontpage, it works, but if I go to http://arabia.local/Frontpage, it tells me 404 not found.
I did some research already; I copied the .htaccess_root to .htaccess, I set the ForceVirtualHost=true in site.ini, I checked in my httpd.conf that AllowOverride All is set - I am running out of ideas here.
The files and settings you mentioned mostly concern eZ Publish's legacy part and will most likely have no effect on the frontend.
From what you're describing, the first thought that came to me was that the VHost configuration might be not complete. Please compare your configuration with the one eZ Systems officially provides: Virtual host setup and .htaccess example.
Are you perhaps missing the following line?
RewriteRule .* index\.php
Please also keep in mind that your webserver's root must point to the "web" directory, and if you are not using a VHost based configuration, the .htaccess file must reside in the "web" directory (but to be honest, I haven't seen a non-VHost based setup yet, so I'm not sure about the .htaccess method.
Nonetheless there should be no need to change anything in the "ezpublish_legacy" directory, especially not for an initial setup.

ZendFramework - only indexcontroller indexAction is working

I have uploaded ZF on shared hosting but It's only indexcontroller and indexAction is working for rest it's showing "404 Page not Found".
Site is working fine on local server.
What can be the issue? Please help me.
The mod_rewrite rules are not being applied. Mostly likely cause is that your web server is not setup to read .htaccess files (which is where the ZF rewrite rules are specified by default). Compare the setup for the Apache variable AllowOverride between your two environments.
my guess is .htaccess missing, or permissions on it, etc. resulting in a routing issue. check the "non pretty" url to see but I'm guessing you'll reach the pages without a problem.

Categories