Change document root on azure php webrole
Asked Answered
T

2

2

I want setup Laravel framework on azure webrole and have to change document root, but so far I can't find way how to do this

My deployment project folder:

├──webrole <- now this is document root
│  ├──app
│  ├──bin
│  ├──bootstrap
│  ├──config
│  ├──database
│  ├──public <- I want make this as document root
│  ├──resources
│  ├──storage
│  ├──tests
│  ├──vendor
│  ├──.env
│  ├──.env.example
│  ├──.gitattributes
│  ├──.gitignore
│  ├──artisan
│  ├──composer.json
│  ├──composer.lock
│  ├──gulpfile.js
│  ├──package.json
│  ├──phpspec.yml
│  ├──phpunit.xml
│  ├──readme.md
│  ├──server.php
│  ├──Web.cloud.config
│  └──Web.config
├──deploymentSettings.json
├──ServiceConfiguration.Cloud.cscfg
├──ServiceConfiguration.Local.cscfg
├──ServiceDefinition.csdef

I found this Change approot path of Windows Azure WebRole but it's quite old question and there isn't approved answer

The only one workaround I've found is using rewrite rules but, I think that is not secure...

Then answered 12/2, 2016 at 8:23 Comment(0)
C
0

As in Azure Cloud Service PHP WebRole directory, where are web.config and web.cloud.config files which is leveraged to configure PHP site application on IIS.

Web can find the content like the following in these files:

<system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="index.php" />
      </files>
    </defaultDocument>
  </system.webServer>

We can modify the setting defaultDocument to change the document root of your laravel application:

<system.webServer>
    <defaultDocument>
      <files>
        <clear />
        <add value="public/index.php" />
      </files>
    </defaultDocument>
  </system.webServer>
Closing answered 15/2, 2016 at 2:33 Comment(7)
That workaround for some php app may work but not for Laravel, Laravel needs rewrite rules to work, anyway one workaround using rewrite rules I've already used, but now I want to change document rootThen
Which laravel version you are using? As I tested with laravel 4, it worked all fine on my side both on local or Azure Cloud Service.Closing
I'm using Laravel 5.1Then
And what have u tested? by that way (without rewrite module) I think routing module won't work...Then
I just followed azure.microsoft.com/en-us/documentation/articles/… to create the PHP cloud service, and create a webrole. I copied a laravel 4 application to the webrole directory, and modify the web.config and web.cloud.config, and publish to azure. browse the cloud service endpoint to check whether it can runClosing
ah ok, so I think that was default route worked, but if u create route something like this app/do/some/thing that won't work without rewrite rule, but anyway I don't want workarounds, one already have using rewrite rules, I want change document root I know that is possible from IIS but I want configure it in webrole configurationThen
for this, you can create another web,config in public folder to configure the rewrite module for laravel application, just like the original .htaccess. you can refer to laracasts.com/discuss/channels/general-discussion/… for the test web.config content, or leverage htaccesstowebconfig.com to convert from your own .htaccess fileClosing
V
0

If someone is still searching for an answer:

You can change the root directory easily by replacing the nginx configuration file by taking these 2 steps:

1- Add the new configuration file to your project root (wwwroot), we call it default.

server {
#proxy_cache cache;
#proxy_cache_valid 200 1s;
listen 8080;
listen [::]:8080;
root /home/site/wwwroot/public; # changed for Laravel
index  index.php index.html index.htm;
server_name  example.com www.example.com;

location / {
    try_files $uri $uri/ /index.php?$args; # changed for Laravel
}

# redirect server error pages to the static page /50x.html
#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /html/;
}

# Disable .git directory
location ~ /\.git {
    deny all;
    access_log off;
    log_not_found off;
}

# Add locations of phpmyadmin here.
location ~ [^/]\.php(/|$) {
    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    fastcgi_pass 127.0.0.1:9000;
    include fastcgi_params;
    fastcgi_param HTTP_PROXY "";
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_intercept_errors on;
    fastcgi_connect_timeout         300;
    fastcgi_send_timeout           3600;
    fastcgi_read_timeout           3600;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
}

}

2- Add a startup command to replace the nginx configuration file with your new file.

  • Enter your azure resource settings -> configuration.

  • General settings tab.

  • Startup Command:

    cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload

This should change the document root each time your instance starts.

Resource: https://learn.microsoft.com/en-us/azure/mysql/flexible-server/tutorial-php-database-app

Verbatim answered 13/2, 2023 at 20:16 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.