Route not found/matched when using symfony 4 inside a subfolder - apache

I have this apache server configured in mydomain.com/applications and inside that folder I have
/project1/ - using silex
/project2/ - using symfony 4
The server uses mod_rewrite and mydomain.com is represented by /var/www/html which is mapped as DocumentRoot in apache configuration.
In my local environment, /project2/ is mapped as project2.test and routes made with annotations works very well.
However, when moving the project to a directory, its routes doesn't work (whether in production or local env).
I'm pretty sure the routes were created correctly, but I guess I'm missing some symfony configuration when using symfony inside a subfolder.
I also tried to use RewriteBase "/application/project2/" in my /project2/.htaccess but didn't work.

I solved the issue by adding an AliasMatch in my site's conf, inside <VirtualHost> as follows:
AliasMatch "^/project2/(.*)" "/path/to/documentroot/project2/public/$1"
Alternatively I could use just Alias as follows (this was my final solution):
Alias "/project2" "path/to/documentroot/project2/public"
The /project1/ didn't need any change, as .htaccess does the work properly there.
A /project2/public/.htaccess was generated using composer require symfony/apache-pack.

Related

Links and assets in grails contains no prefix, grails.app.context not working

I'm trying to deploy a Grails 2.5.3 application on a Tomcat 7 server, running behind Apache (apache running on http://valkyrien.imada.sdu.dk:80). Tomcat is running on port 8080 and Apache virtualhost is setup like this:
ProxyPass /gcp http://127.0.0.1:8080/ nocanon
ProxyPassReverse /gcp http://127.0.0.1:8080/
ProxyPreserveHost on
The war is deployed as ROOT.war to Tomcat's /webapps/ directory.
The index page of my grails application is shown, but the links on the page along with the asset links are wrong. None of them are prefixed with /gcp/.
Example: The javascript asset for jQuery at the html file is:
<script src="/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js" type="text/javascript"></script>
Which will try to access the js file at <APACHE-URL>/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js even though the file is in fact available at <APACHE-URL>/gcp/assets/jquery-8c9c0e26152ea554b3ed6c4390439134.js. The same apply to any link to controllers and actions.
Adding any combination of the following to Config.groovy or application.properties does not change anything (as suggested by answers on StackOverflow):
grails.serverURL="http://valkyrien.imada.sdu.dk/gcp"
grails.app.context = "/gcp"
It seems like Grails ignores the serverURL properties. Any suggestions toward why this is not working?
Running without Apache is not an option.
Thanks!
Deploy your app not as ROOT.war but as gcp.war and updated properties
...or better use mod_jk for apache.

Run cakephp app in apache alias

I'm trying to deploy a cakephp 3.1 app in a apache 2.4 powered server. My boss would like to place the app in a directory different of server's documentroot (DocumentRoot "/var/www/html" in my httpd.conf file), since multiple webapps will be served by this server.
Instead of virtualhosts, he would like to use aliases (host/app1, host/app2 etc). So I'm trying to configure it this way. I put an alias to my cake app (Alias "/scqa" "/opt/scqa/webroot" in my httpd.conf file) and wrote a RewriteBase (RewriteBase /scqa) to both cake's .htaccess files, but every absolute link present in my app is still pointing to apache's documentroot. In this particular case, it means my css and a big pile of not properly built links are 404ing. Is there some way I can fix it in apache configuration?
I know 2 other ways to fix it: Fix the links with cake syntax (will take me a week) or use virtualhosts. But is it possible to fix it and keep using apache alias?
Thanks in advance.
(The production env uses centos 7 64bits, just in case)
If I understood well, you are using aliases in your .htaccess files.
You should put the Alias in your server config file, because it won't work otherwise.
Syntax: Alias [URL-path] file-path|directory-path
Context: server config, virtual host, directory
From https://httpd.apache.org/docs/current/mod/mod_alias.html

Using apache mod_alias in vhost to link assets from external server

This is an outside shot I know. I am supporting a site that has constantly changing assets that are excluded from the repository for obvious reasons. Currently I am having to FTP these assets to my local computer in order to develop and test properly. What I want to do is simply link to the assets on the server. I thought this might be possible using Apache's mod_alias, but I cant get it to work:
Alias /assets http://www.mysite.com/assets
Is this possible? Is there an alternative way of doing this?
Thanks
You can use mod_proxy to make Apache fetch resources from a remote server and then return them under that URL:
ProxyRequests Off
ProxyPass /assets http://www.mysite.com/assets
ProxyPassReverse /assets http://www.mysite.com/assets
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html

rails3 : appending /app1 to apache virtual host url

I just installed a Rails 3 application on a development server, and it can be loaded by using http://server:3000/
In our production setup, all applications are proxied by apache running on another server. All applications are to be accessed by http://prodserver/appX . CSS and javascripts need to be loaded when using apache proxy.
How do I revise routes.rb and change rails.root to use appX, without changing the application?
Use the ProxyPassReverse configuration command in Apache and it will rewrite URL's so you don't have to change anything in routes.rb

Grails URL's with Tomcat/Apache ProxyPass

Grails tends to write out the URL for everything that uses its tags as /appName/whatever. For instance, if I use the tag:
<g:javascript library="jquery"/>
the resulting tag is
<script src="/appName/jquery/jquery.js"></script>
This causes an issue with using ProxyPass with Apache/Tomcat. All of my CSS, JS, Images and links have that /appName prefixed to them.
Is there a way to work around this with ProxyPass or possibly a way for Grails to not prefix the appName to the front of all of my URL's?
If you don't have another application running as default in your tomcat, or you don't care about replacing it, you must rename you war file to ROOT.war before deploying it. (and delete the directory ROOT if it exists)
If you have severals applications and only one tomcat server, you can use virtualhosts. One virtualhost for each application. (http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html)
If you choose the virtualhosts approach, you must use de virtualhost domain when you define ProxyPass sentences and be sure that the apache server, resolves the virtualhost domain correctly. (if not, you may need to edit he os hosts file)
Sorry about my english.
That works for me, are you trying to run the app as domain.com/ rather than domain.com/appName?
If so, then you'll probably need to specify the base or absolute parameter in the tag.