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

ACH's avatar
Level 1

Livewire configuration issue in production environment

I have started creating a Laravel app with Livewire. To make sure the app will work in the production environment I have done a test deploy in a very early stage of the app. Unfortunately the profile edit part of the app is not working (but working in the development environment). The content (the user info) is not displayed on the page. When I look at the html source code the information seem to be present in the code though (in the <div wire:id="foo" wire:initial-data="...">-section), just not displayed. I am using deploy.php for deployment to the production (shared) environment. It is basically the default setup but with the following modifications:

  • I have overridden the deploy:writeable task (not needed as I figure the files needed to be writeable are so already which I have checked).
  • I have added a deploy:uploadEnv task to upload .env file (to avoid having credentials on GitHub).
  • I have added a deploy:setAccess task to tailor the rights to my production environment.
  • I have added a deploy:shorcutLink to make a shortcut to the app (avoiding having to use the full webapp/public URL).

Installation and running composer is part of the deployment. I have checked that the installed packages are the same on production as when deployed to my development environment. I have also done a raw copy without running composer installation.

My .gitignore looks like this:

/node_modules
# /public/build
/public/hot
/public/storage
/storage/*.key
/vendor
.env
.env-prod
.env.backup
.env.example
.phpunit.result.cache
Homestead.json
Homestead.yaml
auth.json
npm-debug.log
yarn-error.log
/.idea
/.vscode

I have tried using deploy both through GitHub-repo and directly using deployer rsync add on with the same result. I have tried a raw copy from my development environment. I have done deployment to my development environment and the web app works fine there. I have cleared up the prod environment config with:

php artisan cache:clear 
php artisan config:clear
php artisan optimize:clear

My developer environment is running MacOS and the production is running Ubuntu.

What I notice when I compare the html source code of the problem page in the development and production environment is the following:

  • Seemingly trivial missing comments in production: <!-- Livewire Styles --> and <!-- Livewire Scripts -->
  • In the development environment there are checks for loaded Livewire and Alpine which I don't find in production.
  • The check for Alpine loaded in development is replace with this in prodction:
window.deferLoadingAlpine = function (callback) {
window.addEventListener('livewire:load', function () {callback();}); 
};
let started = false;
window.addEventListener('alpine:initializing', function () {
if (! started) {
    window.livewire.start();started = true;}
});
document.addEventListener("DOMContentLoaded", function () {
if (! started) {window.livewire.start();started = true;}
});

Why doesn't my web app work in production and how come I have these differences?

0 likes
4 replies
Snapey's avatar

are you running composer install as part of your deployment?

ACH's avatar
Level 1

Yes, composer install is part of the default deployed configuration and I have not changed that. I have checked that the installed packages are the same in production as when deployed locally on my developer lap top. As I said I have also tried a raw copy, without composer install. I am not running npm build on the server but on the development environment (and can not do that as Node.js is not available in the produktion environment).

ACH's avatar
Level 1

I found this LiveWire installation guide scenario issue: Configuring the asset base url:

Your app is hosted on a non-root path on your domain.

My app is not hosted on root but deployed to the folder /fooapp/current where current is linked to the latest release. So it could point to /fooapp/releases/4. The solution described in this guide is to generate/publish a livewire configuration file with an artisan command:

php artisan livewire:publish --config

I did so and set up the asset_url to be:

 'asset_url' => '/fooapp/current'

When I did this in my development environment I was able to reproduce the issue where the profile information is not displayed. Configuring asset_ur to 'asset_url' => null made it work again. This to me is a strong indication that this is why it works in my development environment but not my production environment. The question now is how to set this up correctly to work.

In production I also tried php artisan livewire:publish --assets and to copy livewire.js to my (relative) root folder (/fooapp/current). Non of it solves the problem. The profile information is still not displayed and html source code on this page still indicates to me that livewire is not running.

In my latest configuration attempt I have set 'asset_url' => null and 'app_url' => 'https://bar.com/fooapp/current'.

The differences in the html source file between my development environment and production seem to be the same.

On the script-block at the bottom Safari debugger displays the follow error message:

Can't find variable: Livewire

Any advice, @snapey , what is the correct livewire.php configuration for me in production?

1 like
ACH's avatar
ACH
OP
Best Answer
Level 1

This livewire.php configuration workes:

...
'asset_url' => '/fooapp/current/public',
...
 'app_url' => 'https://bar.com/loppeadm/current',

Here you replace fooapp with the folder name of your non-root app and bar.com with your domain name.

Please or to participate in this conversation.