Apache Virtual Host pointing to Zend Framework Module - php

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...

Related

Folder structure for modular development with PHP and vuejs (or angular)

Essentially, I'm looking to have a PHP development workflow that needs to be modular, but using a Single Page Application technology.
I understand it is recommended to separate the back-end from the front-end. Develop them separately. But is there a way to group all related code into one module (or folder), meaning all backend code with its own views presentation inside the same folder?
It's like MVC, but the "V" contains fragments of vuejs (or angular) files, which extends from a master file somewhere in your project.
For example
Assume we are building a modular CMS, where you can upload "plugins" (really, PHP modules), extending the CMS' functionality:
-project[root-folder]
----core[folder] # contains all infrastracture code, api routes, master view file, magic, etc.
----modules[folder] # uploadable modules goes here
--------User[folder] # sample module; follows the MVC pattern
------------Controllers[folder] # contains files, e.g. UserController.php
------------Models[folder] # contains User.php
------------views[folder] # where vue components is housed
----------------users/index.php # contains vue code
----------------users/create.php # etc...
----------------users/js/user.js
----------------users/css/user.css
--------Blog[folder] # another module
----index.php # the master view or just the bootstrap file
----gulpfile.js
Then inside the core/ folder, there is a master layout that binds all views together.
Will a folder structure like this be viable?
Obvious problem there is you can't use .vue files (as that would mean, every time you upload a new module, you need to run gulp or re-compile).
Hoping for your feedback. Thanks.
This question will strike a lot of folk as bizarre and twisted. That's the reaction I got when I asked it in the context of .net mvc. I'm with you 100%.
I'm too new to js frontend development (and too ignorant of PHP) to have much advice. It's going to be tricky. Ajax calls to PHP code will need to go to paths below the src directory. But then you want to stop your frontend resources being served from these same paths. Both PHP and gulp will want to use file paths for urls, but at least for Gulp this can be controlled.
I'll follow this with interest. My ambition is to keep in the same folder things you're likely to want to delete together, and for those things to be able to call each other with short, relative paths. The ideal would be to be able to specify the module route independently of the path on disk, and to have this route work for both frontend bundled resources and services. Good luck !
I came across this question whilst searching for an approach for exactly the same problem. I'm building a "platform" rather than an application with a plugin system along the lines of Wordpress. I have the additional issue of the platform itself being a 'multitenancy' environment, too - so any plugins cannot interfere with the core "Dashboard" that holds these things together.
So; posting for a few reasons, two years on...
Did you get anywhere and would you care to share any thoughts?
I came across a quite extensive article for PHP Phalcon that has certainly given me a few ideas. Sharing incase it helps you/others:
https://blog.antsand.com/singlepost/index/5619/How-to-integrate-php-(Phalcon)-and-Vue.js-components
There's a line buried in the series that says "As a rule of thumb. Structure your code, based on the application and NOT on the programming language and frameworks." I'm not sure how wise or not this is, but it certainly gave me something to crack on with.
So right now, I have a module folder a bit like:
/mymodule
/Controller
/Model/
/Template
thing.vue
/Assets
/js
/css
MyModule.php
Assets are handled via a framework route (i.e, /assets/{path:.*} )
Templates are handled via the (PHP) module install script to make sure webpack knows where they live.
Still at proof-of-concept stage but rightly or wrongly, it seems to work well enough!

Run Silex from subdirectory nginx, no config access

I have an older PHP project on a customer server, with no access to the config files, the server is runner nginx, and PHP 5.4 ...
Is there a way to use Silex Framework or another modern PHP framework from a subfolder? .. e-g. example.com/silexproject/ without access the .config file for the webserver?
is there an nginx alternativ to .htaccess ?
A quick google serach, shows that no, there is not an .htaccess like file for nginx. Quoting the official wiki:
Stop using .htaccess. It's horrible for performance. Nginx is designed
to be efficient. Adding something like this would destroy that.
Keep in mind that you can still use Silex (I imagine that you can use any modern PHP framework as well) you just need to remember to call the front controller every time (so your URLs won't be that pretty).
For example if your project is on http://example.com/projectdir/ your front controller most likely will be http://example.com/projectdir/index.php and if you need to access some resource under that path, you'll need to type http://example.com/projectdir/index.php/path/to/resource (notice the name of the front controller in the URL)
My advice is that you'll try to contact whomever has access to nginx config file and ask if they can change the nginx config.

Laravel multisite with domain mapping

I'm attempting to create a multisite in Laravel, so one codebase but with several sites operating from it. Each site will have similar functionality, so can reuse code, but each site will use a different theme - which I imagine would be as simple as having different themes in the views folder and mapping them depending on the domain that the customer has come through.
I want to be able to access Site X from www.sitex.com, Site Y from www.sitey.com etc, while having only one laravel install and not resorting to any vhosts tomfoolery.
Would any of you be so kind as to advise me on a solution, or to point me in the right direction? I've had next to no luck finding anything so far!
Thanks
If your routing is not going to be too complex you could potentially get away with having numerous public folders
laravel
app
bootstrap
sitex.com
sitey.com
vendor
Then each of your site will be it's own virtualhost with no funky alias rules like so (for security, make sure there is no access to the laravel root dir):
DocumentRoot "/var/www/laravel/sitex.com"
Lastly, you would put a variable in bootstrap/paths.php where the public path will be
'public' => __DIR__.'/../'.preg_match('/\w+.com/',$_SERVER['SERVER_NAME']),
This should work for the majority of deployments even with subdomain routing because bootstrap gets initiated from the index.php file in each of the public folders. If you want to use artisan to load up the built in php server, you will need to provide --host or it will not work. There will be a few limitations on this set up that I have encountered so if someone else knows of a better way I would love to learn how myself.

Modular Way of Reading/Writing Configurations using Zend2

I want to have a bunch of settings in my module, and they should be writable from the App. Since they're application settings, I thought a table for it would be not very efficient (it would only have one row).
I found the Zend module Zend\Config, which seems to be able to to write config files, which can in turn be used by Zend.
It is advisable to write into the module.config.php? Or into a different file? Can I still load it into the standard module config?
I am pretty new to Zend and this fully modular approach, so I'd like some clarification on that.
You should never write into the module directory itself. Instead, have a data directory, e.g. at the root of your application, and put written configuration files in there.

Publishing assets from modules in Zend Framework 2

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.

Categories