javaldx failed! Warning: failed to read path from javaldx

I am getting the error :
javaldx failed!
Warning: failed to read path from javaldx

(process:34129): dconf-CRITICAL **: 08:18:31.604: unable to create directory ‘/var/www/.cache/dconf’: Permission denied. dconf will not work properly.
LibreOffice 7.5 - Fatal Error: The application cannot be started.
User installation could not be completed.
[Wed Mar 13 08:18:31.626422 2024] [wsgi:error] [pid 34037:tid 140694461216448] [remote 103.211.54.213:60854] [ERROR] Internal Server Error: /word_to_pdf

Here is my code :

    if request.method == 'POST' and request.FILES.get('word_file'):
        word_file = request.FILES['word_file']

        try:
            # Create a temporary directory to store the uploaded files
            temp_dir = tempfile.mkdtemp()

            # Construct the file path for the uploaded Word file
            word_file_path = os.path.join(temp_dir, word_file.name)

            # Write the uploaded Word file to the temporary file path
            with open(word_file_path, 'wb') as f:
                for chunk in word_file.chunks():
                    f.write(chunk)

            # Specify the directory for the temporary PDF file
            temporary_pdf_dir = os.path.join(settings.MEDIA_ROOT, 'temporary_pdfs')

            # libreoffice_path = r'C:\\Program Files\\LibreOffice\\program\\soffice.exe'
            # Adjust the path accordingly
            subprocess.run(['libreoffice', "--headless", '--convert-to', 'pdf', '--outdir', temporary_pdf_dir, word_file_path])

            # Get the generated PDF file path
            temp_pdf_file_path = os.path.join(temporary_pdf_dir, word_file.name.split('.')[0] + '.pdf')

            # Save the converted PDF content to the database
            with open(temp_pdf_file_path, 'rb') as f:
                temporary_pdf = TemporaryPDF.objects.create()
                temporary_pdf.pdf_file.save('wordtopdf.pdf', ContentFile(f.read()))

            # Delete temporary files
            os.remove(word_file_path)
            os.remove(temp_pdf_file_path)

            # Render the template to download the PDF
            return render(request, 'pdftools/download_pdfs.html', {'pdf_file': temporary_pdf})

        except Exception as e:
            return HttpResponse(f"Error during conversion: {e}", status=500)
    else:
        return render(request, 'pdftools/word_to_pdf.html') ```

You need to ensure that whatever directory you use for the temporary files is read/write/“executable” by the UID which is running your conversion process. Right now, it appears you’re doing this in the /var/www directory, which probably isn’t the best place for it. I would suggest creating a directory in /tmp that is owned by your Django process and do the work within it.

okay I’ll do that but what about this error , can you help me in this?

That’s precisely what I’m trying to address here.

This is the error needing to be resolved:

This is my first Django project hosted on a web server, so I’m not familiar with best practices. I simply watched a YouTube video and followed the steps to host my website.

No worries, we’re here to help you with situations like this.

ok thanks , can you explain me - how to host a django project on vps using apache from scratch?

I’m sorry, that’s a large topic that goes well beyond what can be covered in a forum post. I suggest you find a blog post (or two) with sufficiently detailed descriptions.

For example, you may want to look at How To Serve Django Applications with Apache and mod_wsgi on Ubuntu 16.04 | DigitalOcean as one such starting point.

(Side note: I stopped using Apache more than 10 years ago. I only do my deployments now on nginx. I’ve found it a lot easier to work with.)