Symfony 4 deploy on IIS in a nested directory - symfony

I want to deploy a new Symfony 4 project (the symfony-demo) from local to a IIS web server. The project should stay in its own sub directory. The IIS webroot is two levels higher. When I go to public/index.php of my project (which is releative to the webroot in /sf/symfony-demo/), the templates are not shown correctly, since the server does not find the correct JavaScript directory in build/js/...), see screenshot
I call http://192.168.1.203/sf/symfony-demo/public/index.php, but fails to load from http://192.168.1.203/build/manifest.js.
On the server, I can not set the webroot or create virtual directores. Also, I have no command line. I need to do it via configuration in symfony or a correct write/rewrite rule in web.config file.
How can I set the sf- project root directory relative to the IIS webroot, in my case to /sf/symfony-demo/public ?
Can somebody provide a rewrite rule in web.config in /sf/symfony-demo/ or in /sf/symfony-demo/public? Or do I need to set the directory somewhere (prefix? asset?) in my project configuration files (e.g. \sf\symfony-demo\config\packages\framework.yml)?
Edit
I got it working somehow, there is a similar discussion and a solution for a symfony 2 project:
Symfony 2 project in nested directory
by adding in symfony-demo\config\packages\framework.yaml a line at assets :
base_urls:
- 'http://192.168.1.203/sf/symfony-demo/public/'
But somehow this looks strange for me to set the path this way. Setting here
base_path: '/sf/symfony-demo/public/'
does not work. I would expect to set the (relative) path explicitly somewhere, not a url. But where?
Also, setting extra.symfony-public-dir in composer.json like in
http://symfony.com/doc/current/configuration/override_dir_structure.html
does not work.
Regarding the rewrite rules:
Yes I read the doc, but I found nothing for web.config on iis for symfony on
https://symfony.com/doc/current/setup/web_server_configuration.html.
But I found a iis web.config for silex
[https://silex.symfony.com/doc/2.0/web_servers.html .
It looks like the web.config is not the real problem here.
Thank you for taking the time to read this. d.

Related

.NET Core - same project running under iis express on different drive

I recently bought a new computer. I moved the drives from my old computer to the new one, installed everything I needed to and opened my project. Now I'm trying to run my project in IIS express but it displaying an error specifying an html output as log file.
When I look at the html problem, it's a 500 error message generated by what looks likes an IIS page. It's saying that the config file cannot be found:
HTTP Error 500.19 - Internal Server Error
The requested page cannot be accessed because the related configuration data for the page is invalid
Config File
\\?\F:\Development\MyProject\API\web.config
When I switched to the new machine drive letters were changed, so the code I'm running is no longet on drive F like in the message above - it's now on a different drive. I've looked in my code - I have no reference anywhere to a specific path.
I've tried to do clean and rebuild but it doesn't work.
If I look inside files for the path I see that the DLLs are compiled with PDB file path inside them. Why is that? And what happens later on on production?
Also, how do I fix this problem? why does it keeps looking for old location?
I'm fairly sure the IIS Express metabase still has the old path configured for this site. Please see the following answer for how to locate the metabase file (it's usually here: \Documents\IISExpress\config\applicationhost.config):
Where is the IIS Express configuration / metabase file found?
I'm not sure what the most correct way is to correct the problem, but you should be able to manually edit this file and update the "physicalPath" attribute for your site to the correct path to resolve this problem.
I don't know the exact cause of my problem, but the solution was to delete all bin directories from all project folders and re-compile.
To delete the bin directory from all my project I wrote the following PowerShell script:
Get-ChildItem -Path . -Filter *bin* –Recurse | Remove-Item -Recurse -Confirm

Symfony access assets folder

I have some folders in www/web/ which is the root.
It's the following folder: assets/exports/
And it contains a file export.xsl
When I do in javascript:
window.open('/assets/exports/export.xsl');
I'm going to the following link:
http://mywebsite/assets/exports/export.xsl
But I get a: 404 not found
Is symfony somehow protecting this link?
So, my question is, how can I access this file, so it starts downloading for the visitor?
From Symfony Documentation:
Keep in mind that web/ is a public directory and that anything stored here will be publicly accessible, including all the original asset files (e.g. Sass, LESS and CoffeeScript files).
Make sure you put the files in a proper directory: <symfony_root_dir>/web. See below.
Then accessing the http://mywebsite/assets/exports/export.xsl returns the file's content.
Check also your server configuration, virtual host config and read web server configuration guide from Symfony to see if you configured it properly.

Symfony 2 - What to do before going live?

Until now, I've been writing Symfony 2 applications and never was responsible for launches. So I've only called Smyfony 2 over app_dev.php and only used a development configuration. Now I have to take care of a Symfony 2 launch, what do consider before going live?
Where can I set different configurations (DB connection, etc.) for different environments and how can I invoke them?
How can I make sure the application can't be called via app_dev.php on the live server?
And of cure any other tips on what to keep a eye on while pushing a Symfony 2 application live.
First of all, we have documented this: http://symfony.com/doc/current/cookbook/deployment-tools.html That article just answers the first and third question, the answer on the second question:
How can I make sure the application can't be called via app_dev.php on the live server?
You should point the root directory of you website to the web directory. For instance, if you site lives in:
mysite.com/
public_html/
... your site files/directories
You should make it like this:
mysite.com/
app/
...
src/
...
vendor/
...
public_html/ <--- this is the old web directory
...
app.php
You can read how to change the web directory in public_html into the documentation too: http://symfony.com/doc/current/cookbook/configuration/override_dir_structure.html
The reason to do this is to secure all your application code. The user just can't access all app/., vendor/. and src/. files and so it can't read the configuration and can't read the parameters.
At last, you can change app.php to index.php to get urls like mysite.com/app.php/blog/foobar. But it is better to create a simple HTACCESS mod_rewrite rule to send all requests to app.php, so you can access the page with mysite.com/blog/foobar.
.htaccess in the root:
RewriteEngine On
RewriteBase /
RewriteRule ^(.*?)$ app.php$1
Where can I set different configurations (DB connection, etc.) for different environments and how can I invoke them?
if you haven't changed too much your project, your config files are under app/config
How can I make sure the application can't be called via app_dev.php on the live server?
Same, if you haven't change to much the project, the only thing you need to care about is make sure your web server runs the website from /web (the .htaccess does the rest)
And of cure any other tips on what to keep a eye on while pushing a Symfony 2 application live.
You can keep an eye on the log files in app/logs

Umbraco - Get Directory of Config Files

I'm working with Umbraco 4.7.1 and I've created some extensions that hook into Document.AfterPublish and Document.AfterUnPublish. I need to find the directory of the config files from here, but need to be independent of server installation (i.e. a literal won't work). Is there any way of finding this at that point in time?
I think what you are looking for is the umbraco.IO.SystemDirectories class, specifically the Config property.
This will return "~/config" by default, but can be overridden by adding a umbracoConfigDirectory key to the appSettings section of the web.config file and specifying a different path there.

adding .net code to a classic asp website, can't reference namespaces in .dll file

I have an existing fairly large classic asp website, with virtual directories configured to centralize certain resources. My problem is for some reason I can't access any of my namespaces and classes. I tried adding a reference to another project where I have classes in a namespace "DAL" and even though intellisense sees the classes and the website compiles fine, it errors when I try to access any page that references a class in the "DAL" namespace.
I get the following error message in my browser "CS0103: The name 'CMS' does not exist in the current context". Part of the problem is website project's root is not the same folder/level as the web root in IIS. So my libraries are in the website root "/bin" folder, but iis is looking for these files in the IIS webroot which is at a lower level. So how can I get .net to see my binaries without putting them in the lower IIS website root directory? I tried setting up a virtual directory to my .dll file but it seems to have no effect.
thank you for your help!
======================CLARIFICATION====================
What I'm trying to do is keep the .dll files I want my website to use in a higher level directory then the folder I have set as the web root in IIS. So say the library i want to use it "DAL" it in the projects /bin folder, but under IIS the default site's Local Path is set to "/site/default". The only way I can seem to use the "DAL" library is by putting the /bin folder into "/site/default/bin", which for this project is not an option. Does this help?
Using an NTFS Junction Point to achieve what sounds like the same goal has been working for me.
By way of an example, I have a web site with 20+ child IIS Applications that are largely identical (don't ask!), rather than duplicating the 'bin' folder in each of these (they would be identical) each child application has a 'bin' junction that points to the 'bin' folder in the web site root.
/bin <- this is the actual 'bin' folder
/app1
/app1/bin <- this is a junction point
/app2
/app2/bin <- this is a junction point
/app3
/app3/bin <- this is a junction point
/images
...
...
To create these junction points, if you're using Vista/Win2k8 or later you can use the built-in command 'mklink', for earlier versions of Windows use the SysInternals junction.exe tool - available here.
Maybe make the website route folder a nested application in IIS?

Resources