I know that to experienced ZF developers, this may sound silly, but please bear with me. Let's use our imagination for a moment and say that I have a hosting package on a Linux server which does not give me access to the any folders outside of my htdocs folder (or www or public_html folders, whichever).
I know that all of the instructions recommend I install this framework outside of the htdocs folder for security, and set an include path in the PHP config to automatically give me access to this framework in all of the PHP files.
However, given the above constraints, this isn't possible. My questions are:
As far as how the framework goes, can I install this framework inside of my htdocs folder, say, placing it in its own dedicated folder at the same directory level as my application, and forbid public access to it using .htaccess?
How secure is this approach, if I set Apache up to deny all non-local requests to this folder and its contents?
Which core file(s) do I include in my scripts to give me access to the framework?
Sorry for the crash list of questions, but I have almost zero experience with the Zend Framework.
Thank you for you time.
You can upload the whole Zend library to your server. Best to place it outside your htdocs folder.
Then you use this line in your code:
$paths = array( '/path/to/Zend', get_include_path());
set_include_path(implode(PATH_SEPARATOR, $paths));
Then you can use all zend just like normal:
require_once 'Zend/Controller/Front.php';
Zend_Controller_Front::run('../application/controllers');
Related
I saw alot of frameworks like Laravel, Zend, Symfony .... and I noticed that they put php files in the root directory, but when I saw WordPress and vBulletin and alot of famous scripts, and I noticed that they put the php files in the public directory.
I wanna know what is the best place to put my PHP files. Root directory or public_html directory? Which is better? and Why! And what is the difference between them?
Assuming by "root directory" you mean somewhere outside of the web server's document root, and that "public_html" is the web server's document root...
It's best practice to only have scripts that must be directly accessible within your web server's doc root. If something happens where PHP gets disabled, you don't want the whole world downloading copies of your source code. Scripts can include files from wherever they can access on disk, so it's possible to only put a loader in the web server's doc root and keep the whole application out of there. This is common and best practice.
Wordpress likely doesn't do this by default because most folks installing Wordpress don't really know what they're doing. It's easier for them to just extract a tarball to one place and not have to worry about it. The ones that do know what they are doing can customize installation paths if desired.
Is there a way to setup apache virtual host so that it root points to a zend framework module?
The address of this module is only a route and there is no physical folder on the server.
Default module:
www.myintranet.com
Another module address:
www.myintranet.com/mymodule/
"mymodule" is not a physical folder, just a route.
I can see no reason why you would ever WANT to do that? ZF2 uses routes to the particular modules which is one of the strengths. By hiding your files outside of the document_root you also get additional security where people cannot try to exploit your php files directly to gain access to your system. In addition to this if your application has multiple modules and there is an issue on one of the modules you can simply disable that module temporarily without having to deal with apache rewrite rules etc.
The direct answer to your question however is that yes you can point apache at your module directory, however you will need to change and update all of the current rewrite rules to deal with the index.php autoloader and PATH related variables. This would be more work than actually learning routing. Once you figure it out it makes your life a lot easier.
I posted an answer here: ZF2 Routing as in ZF1
ON ZF1 -> ZF2 routing as it seems to confuse many people and that router should hopefully get you on your way as I suspect that is the issue you're having...
I am trying to deploy a PHP Yii app to Orchestra (https://www.engineyard.com/products/orchestra/). The platform, like I think many cloud-based platform, doesn't allow write permissions.
I've managed to get around the 'runtime' directory that Yii requires by putting it in the system's tmp folder. However I'm stuck with the 'assets' folder. Yii requires a writable AND publicly accessible folder.
Is there a way around this?
Yii requires somewhere to put the files from within the core or modules to be publicly accessible.
If this isn't possible you might have to go through and manually grab each js/css file your going to want, place them in the folders required and use scriptMap to map these back or block them and include them yourself.
There's lots of documentation around Client Script which is what handles all this.
It is generally adviced to store module assets inside the module's directory, inside moduleName/public (or whatever you want to name the asset's directory).
Zend Framework 2 unfortunately doesn't support asset publishing for module assets by default. According to MWOP, there was nothing planned ~1 month ago and I guess there still is no real plan (they had probably a lot of work to get the stable version ready). (But, some day, they are going to address this issue.)
As my ZF2 app is growing and growing, I reached the point where I need to have module-specific assets. At the moment, I maintain them inside the module directories and copy them to the application's public directory. You can imagine that this method is error-prone and exhausting.
How do you handle this problem? Is there maybe a simple solution to this issue with little coding effort? My project plan doesn't allow me to create a complex asset handling on my own. Is there a recommendable, lightweight asset framework compatible to ZF2? I've already considered creating symlinks but I don't think this would be the best solution because it would require some additional web server configuration (FollowSymlinks) and additional maintenance work (the app is developed locally and deployed on a remote server).
Thanks in advance.
This has been discussed before in many places and it comes down to three ways to manage this.
Copy and Paste the assets into the public/ directory
Use symlinks
Use an asset loading module like assetic
A simple solution would be to make the copying of assets part of you build process.
Another question was already asked How to merge Zend Framework 2 module public directories for info.
I know this is pretty old, but I wanted to add this information for other readers.
Now there's also a module for this, which has been fully tested and is being used (and even depended on) by many modules.
Check it out here: https://github.com/RWOverdijk/AssetManager
Hope this helps.
There is also fourth option. Use a directory Alias in VirtualHost configuration.
i want to know where can i put the "library" folder in my zend project. Presently i have it in the location of my Zend server. This is my current "library" path:
E:\zend\ZendServer\share\ZendFramework\library
And here is the path to my "app" project:
E:\zend\Apache2\htdocs\app
Inside the "app" project, i have the folders like "public" and "application".
Now how can i integrate the "library" into my "app" project, without referencing it from zendserver?
The easiest way it is to put those library files to the library dir (as in the other answers), but you should consider keeping them separated from the application.
It's easier to have separate git or svn repos for the libraries. Easy to update and maintain for multiple projects at once. Putting them in library will also won't work if you installed the libraries from the bundle, e.g. apt-get install zend-framework-library.
To have the libraries in any directory you want, just add it to the include_path array in the index.php.
Quite often, you'll see a folder called like "lib" or "libraries" in your application (next to public, application, ...).
In that folder, you'll put the frameworks you're using.
For example :
public
application
libs
Zend
Doctrine
...
To get Zend Framework, just download it, and unpack it to the right folder ;-)
Advantage : you'll be using the version of your choice -- and not the one, possibly outdated, provided by your environment.
And, as a reference, you might want to read the Installing The Zend Framework chapter of the e-book Survive the Deep end.
In your app project u should have a library folder and should contain zend folder in that..so just copy library folder and put it in E:\zend\apache2\htdocs\app.
Please don't tell people to deploy 3rd party libraries to their application project folder, it is bad practice. Deploy your libraries to a path that you have access to, which is outside of your project, and reference it in your include path.
During development, it is fine to have the library in your project, for reference sake, but exclude it in your deploy script and instead have your deploy script either set an environment variable, or have it update your include path.