diff --git a/dev/setup/nginx/setup_nginx.py b/dev/setup/nginx/setup_nginx.py index d1c5e71ab24..9f8e856c195 100644 --- a/dev/setup/nginx/setup_nginx.py +++ b/dev/setup/nginx/setup_nginx.py @@ -1,13 +1,30 @@ import os +import subprocess + +# Create symlink from /var/www/html/dolibarrbeta to the actual htdocs folder +symlink_path = '/var/www/html/dolibarrbeta' +target_path = '/home/ubuntu/dolibarrbeta/htdocs' + +try: + if os.path.islink(symlink_path) or os.path.exists(symlink_path): + os.remove(symlink_path) + os.symlink(target_path, symlink_path) + print(f"Created symlink {symlink_path} -> {target_path}") +except Exception as e: + # If standard user cannot do it, let's print message or handle it via subprocess in bash + print(f"Symlink creation message: {e}") filepath = '/etc/nginx/sites-available/default' if os.path.exists(filepath): content = open(filepath).read() - if 'location ^~ /dolibarrbeta' not in content: - idx = content.find('location / {') - if idx != -1: - block = r"""location ^~ /dolibarrbeta { + + # Remove any old alias block if it exists + old_block_marker = 'location ^~ /dolibarrbeta' + if old_block_marker in content: + # We can clean up the configuration file by removing the old block + # To be safe, we will rewrite the file cleanly with the new root block + content = content.replace(r''' location ^~ /dolibarrbeta { alias /home/ubuntu/dolibarrbeta/htdocs; index index.php; try_files $uri $uri/ /dolibarrbeta/index.php?$args; @@ -17,6 +34,22 @@ if os.path.exists(filepath): fastcgi_param SCRIPT_FILENAME $request_filename; fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; } + }''', '') + + # Insert the new correct root-based location block + if 'location /dolibarrbeta' not in content: + idx = content.find('location / {') + if idx != -1: + block = r"""location /dolibarrbeta { + root /var/www/html; + index index.php; + try_files $uri $uri/ /dolibarrbeta/index.php?$args; + + location ~ \.php$ { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass unix:/var/run/php/php8.3-fpm.sock; + } } """