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

Mokta's avatar
Level 2

Laravel Forge - sudo -S command

Hi all,

Hoping this one might be easy.

I'm using Laravel Forge for my deployments and making use of Spatie's fantastic Browsershot.

I can't seem to use the sudo command as part of the Deploy Script.

I've tried the following sudo -S, but just receive

[sudo] password for forge: 
sudo: no password was provided

My initial assumption is that the password is automatically injected and handled by the forge script.

Do I have to find and inject the password in to the script to run this, even though I can see the script using sudo -S successfully a bit further down?

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

For context I am trying to use the following install instructions found here for Browsershot on Laravel Forge.

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt-get install -y nodejs gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget libgbm-dev
sudo npm install --global --unsafe-perm puppeteer
sudo chmod -R o+rx /usr/lib/node_modules/puppeteer/.local-chromium

Any help on how to use sudo command successfully would be greatly appreciated

0 likes
11 replies
Sinnbeck's avatar

I would imagine only certain commands are allowed to be run as sudo, without using a password

Now you tell us what happens when running sudo -S, but not when running the actual command specified in the docs?

Mokta's avatar
Level 2

Hi @sinnbeck,

I get the following when running with the command as is.

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

And this when running with -S added after the 4 sudo commands

[sudo] password for forge: Sorry, try again.
[sudo] password for forge: Sorry, try again.
[sudo] password for forge: sudo: 3 incorrect password attempts
Sinnbeck's avatar

Can you confirm that is is this line that is triggering in by only running that one line?

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -
Mokta's avatar
Level 2

Hi @sinnbeck,

So with the following command

curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash -

The output is

sudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper

If I change the command to

curl -sL https://deb.nodesource.com/setup_12.x | sudo -SE bash -

I then get the following

[sudo] password for forge: Sorry, try again.
[sudo] password for forge: Sorry, try again.
[sudo] password for forge: sudo: 3 incorrect password attempts
royksoft's avatar

Hey @mokta ,

Did you find a way around this? I have exactly the same issue, for exactly the same reason (browsershot)!

royksoft's avatar

OK, for anyone else trying to get this to work, you can get around this by SSHing directly into your forge server, and running the commands at the root level.

I'd prefer to do this in the deploy script (mainly for documentation, because I'm bound to forget this when I try to install another on another server), but perhaps the best way is directly on the server anyway.

Mokta's avatar
Level 2

Hi @royksoft,

Apologies about not replying!

Yes so looks like there are two different ways to handle this.

As you mentioned, ssh into the server directly and run the scripts as sudo.

The second way looks to be using recipes on Laravel Forge and running them as root. Looking into that now and seeing if that works :)

royksoft's avatar

Hi @mokta,

Thanks for coming back. Glad I'm on the right track. I'll check out forge recipes, but in the end I SSH'd in and ran this directly.

This forum post will serve as my docs when I can't work out what's gone wrong in about a year's time!!

1 like
leemgu's avatar

I had this exact issue, I created a Forge recipe as suggested by Mokta using the cmds from the requirements doco on Spaties website and this worked! Thanks Mokta!

Tvup's avatar

Or you can add the command you want to elevate without password to: /etc/sudoers.d/nginx

In my case i needed setfacl so i added this line:

forge ALL=NOPASSWD: /usr/bin/setfacl *
1 like

Please or to participate in this conversation.