Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

bmcconn's avatar

Vite config for HTTPS

I am trying to run vite with homestead over https, and have attempted to set the key and certificate in the vite config file. My vite config looks like this:

import { defineConfig } from 'vite'
import laravel from 'laravel-vite-plugin'
import vue from '@vitejs/plugin-vue'
import defineOptions from 'unplugin-vue-define-options/vite'
 import fs from 'fs'
 const host = 'demo.local'

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        vue({
            template: {
                transformAssetsUrls: {
                    base: null,
                    includeAbsolute: false
                }
            }
        }),
        defineOptions(),
    ],
    server: {
        hmr: {
            host: "192.168.10.10"
        },
        host: "192.168.10.10",
        watch: {
            usePolling: true,
        },
        https: {
            key: fs.readFileSync(`/etc/ssl/certs/${host}.key`),
            cert: fs.readFileSync(`/etc/ssl/certs/${host}.crt`),
        }
    }

However, when I run npm run dev, I receive the following error:

Error: EACCESS: permission denied, open '/etc/ssl/certs/demo.local.key'

I don't know what the issue with my permissions would be, I have ssh'd into homestead with the homestead user as normal. Do I need to edit my config to make this work?

Thanks!

0 likes
2 replies
tonyclemmey's avatar

Hi,

I came across a similar scenario so just sharing in case it helps someone.

Cert and key files in the /etc/ssl/certs/ directory on the Homestead VM are owned by the user:group "root:root" so permission will be denied if running npm run serve as the vagrant user. A few options that can be tested; 1) Run npm run serve as root. 2) Change permissions on the Cert and Key files. 3) Copy over the Cert and Key files to a shared folder and check files are owned by user:group "vagrant:vagrant"

1 like

Please or to participate in this conversation.