Setup laravel 5.4 with IIS 10 - laravel

I want to deploy laravel projects on our IIS 10, running on windows server 2016. What is the easiest and still secure way to do that?

This is how I did it; I'm not sure it is the right way.
Install URL Rewrite module (https://www.iis.net/downloads/microsoft/url-rewrite)
Put repo in some folder E:/sites/helloworld
In IIS add a virtual directory called "helloworld" pointing to E:/sites/helloworld/public
Make sure folders bootstrap/cache and storage is open for writing.
Dont forget to make env file.
In your web.php route file put:
Route::get('/', function () {
return view('welcome');
});
Route::get('/also', function () {
return view('welcome');
});
Add the file web.config in public dir and paste the rules:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
You should now be able to access both URLs meaning laravel routing works as intended. If you try another non-existent route you will get a laravel exception.

Related

IIS setup with Vuejs and Laravel

In my Laravel + Vuejs project I have the following structure:
wwwroot/dist folder where the client application is located in /wwwroot/dist.
wwwroot/public folder, entry point of Laravel
The client application consumes a Laravel REST API. There are also other APIs for different utilities.
I have the following web.config file in /wwwroot. The idea is that all requests go to /dist to access the client app, except those coming from the api|src|flyer|admon|user subdomains. This is my web.config:
<configuration>
<system.webServer>
<defaultDocument>
<files>
<clear />
<add value="/public/index.php" />
<add value="/dist/index.html" />
</files>
</defaultDocument>
<handlers accessPolicy="Read, Execute, Script">
</handlers>
<rewrite>
<rules>
<rule name="specific routes" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern=".*(api|src|flyer|admon|user)\.mysite\.com.*" />
</conditions>
<action type="Rewrite" url="/public/index.php" appendQueryString="True" />
</rule>
<rule name="general routes" stopProcessing="true">
<match url="(.*)" />
<action type="Rewrite" url="/dist/" appendQueryString="True"/>
</rule>
</rules>
</rewrite>
</system.webServer>
All requests that work with the first rule (api|src|flyer|admon|user subdomains) work correctly. The issue is that my client app doesn't work, it seems like it doesn't process Javascript files. Note that in the content of the JS files it shows that of index.html:
The problem is not in my Vuejs application, because I have it installed on another Apache/Linux machine and everything works correctly with the same deployment structure.
EDIT
This is my virtual path config in Azure, where my web.config is placed:

Point subdomain to it folder IIS

There's a way to point all my subdomains to the same name folder, using Windows Server | IIS - Rewrite Rule or Proxy?
Example:
subdomain1.domain.com ----> C:\customers\development\subdomain1
subdomain2.domain.com ----> C:\customers\development\subdomain2
subdomain3.domain.com ----> C:\customers\development\subdomain3
Is it possible do automatically?
I've tryied these web.config rules
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/" appendQueryString="true" logRewrittenUrl="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
Thanks in advance!
URL rewrite is mainly used to rewrite URL not physical path. So you have to create a web app with root folder C:\customers\development and bind all subdomains to this IIS site. Then modify your rule to
<rule name="rewrite" enabled="true" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="^(?!www\.)(.*)\.example\.com$" />
</conditions>
<action type="Rewrite" url="/{C:1}/{REQUEST_URI}" appendQueryString="true" logRewrittenUrl="true" />
</rule>
Please modify ^(?!www\.)(.*)\example\.com$ to ^(?!www\.)(.*)\.example\.com$.
Finally, you should be point subdomain to subfolder
Besides, if the application in folder domain1/domain2 and domain3 are three independent projects then you need to use sub-application instead of a folder.

Laravel: Getting a 405 on Azure for DELETE requests via Axios

I've been working on a Laravel project for some time now and unfortunately hit a snag with sending a DELETE request on the production version hosted on Microsoft Azure. I found out the issue was that Azure by default denies DELETE requests to which I was directed to: How do I enable PUT requests in Azure?. However, I've updated the web.config file to the following: (Server PHP version 7.3, 64-bit)
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
<system.webServer>
<handlers>
<remove name="PHP73_via_FastCGI" />
<add name="PHP73_via_FastCGI" path="*.php" verb="GET, PUT, POST, HEAD, OPTIONS, TRACE, PROPFIND, PROPPATCH, MKCOL, COPY, MOVE, LOCK, UNLOCK, DELETE" modules="FastCgiModule" scriptProcessor="D:\Program Files\PHP\v7.3\php-cgi.exe" resourceType="Either" requireAccess="Script" />
</handlers>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
</conditions>
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Imported Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I had previously tried to run this accessing D:\Program Files (x86) but unfortunately that hasn't worked either. I've posted the entire web.config because I'm not sure if some of the other settings that have been added conflict with trying to enable the DELETE.
For reference here's the route that is called:
Route::group(['middleware' => ['auth']], function($router) {
Route::post('likes', 'LikesController#store');
Route::delete('likes/{', 'LikesController#remove');
Route::delete('likes/{like}', 'LikesController#remove');
});
The call to LikesController#remove only runs $like->delete(); and then returns the comment without the like that has been deleted.
Method inside of the view component that calls axios:
axios.post('/api/likes', {comment_id: this.comment.id}).then((response) => {
this.comment = response.data;
}
I have this working fine on my local build so I'm unsure of why the issue is persisting beyond the fix that has been provided. If there's anything else that is needed please let me know and I will edit the post.

mkdir(): File exists when exporting Excel file on laravel on IIS8

I'm trying to Export an Excel file from laravel using the maatwebsite/Excel package, and everything was working fine locally, but when I wanted to put it on the IIS Server, I get this Error:
here's the code responsible for the error in my Controller:
$date = Carbon::now()->format("d-m-y-h-m-s");
$data1= json_decode( json_encode($data), true);
$export = new ExcelExport((array) $data1);
$file= Excel::store($export,storage_path('app')."\jobshistorie".$date.".xlsx", "local");
I gave the permissions of the entire Project Directory to the Server.
I also have the web.config file in public Directory:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
I could use all the help i can get, thanks!
I guess I am late but you can try clearing the cache as:
php artisan config:cache
or
php artisan config:clear
Hope it might help.

Laravel 5 on IIS7 does not work with web.config

I have a simple Laravel 5 app. It was developed on Xampp, and worked perfectly. I copied it onto the production server, and it does not work. Something is wrong with the web.config file, because if I remove it, then the app works perfectly with index.php/path
My webconfig is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Rule 1" stopProcessing="true">
<match url="^(.*)/$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="/{R:1}" />
</rule>
<rule name="Rule 2" stopProcessing="true">
<match url="^" ignoreCase="false" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
<action type="Rewrite" url="index.php" />
</rule>
</rules>
</rewrite>
</system.webServer>
The app is located at a subfolder of the website and I cannot create a new site, but I can restart IIS as needed. I really don't know IIS very well (in fact I hate it), so I don't know where to check, but since the app works without the web.config, I assume it must be the culprit.
IIS Needs to have the URL Rewrite Module for the Laravel web.config to work.
On XAMPP, it will work out of the box as the Apache mod_rewrite module is included and most of the configuration settings are already provided by XAMPP.
Microsoft URL Rewrite.
Download it from here

Resources