Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got Apache installed on my local Linux (sabayon) OS, just for programming testing.

What I want is a script so that the server starts right away when I want it.

This is the code:

# een script dat de apache server start
/etc/init.d/apache2 start

The only problem is that Apache needs root privileges, but I'm a normal user. Now can I run this script from the command line with sudo ./apache_start.sh, but I don't want that. I just want to double click on it and start the Apache server.

So what can I do so the script is run as root instead of the normal user?

I don't care if there is a prompt that asks for the password, I just don't want to open a console, navigate to the file and so on.

share|improve this question

migrated from serverfault.com Sep 2 '12 at 23:59

This question came from our site for system and network administrators.

Have you tried adding sudo to the beginning of the line where you're starting Apache? – qweet Mar 4 '12 at 22:31
yes, when i start the script trough cli, it ask for password, but when i double click, it doesn't do it. And when i check the states of apache, it didnt start – TWCrap Mar 4 '12 at 22:38
How about this- go into a console session and then type sudo visudo. This will open up a sudoers file which you will have the right to edit. Scroll down to near the bottom, and you should see your username with something formatted like username ALL=(ALL). Append PASSWD: /etc/init.d/apache2 to the end of that line, then save the file. Then try doing your script again (with sudo prepended) – qweet Mar 4 '12 at 22:45
didn't work either – TWCrap Mar 4 '12 at 23:12
Hm. Have you tried launching the script from the console to see if it works? – qweet Mar 4 '12 at 23:17

You cannot use the default init script if you want to do what you are doing. Also, you cannot start it without root privileges if you want it to run on port 80, since only root can start listeners on port 80.

You have two options as I see it. Run on a higher port than 1024 and then execute apache from the command line manually. Or use sudo:


Add a line with your username

username ALL=NOPASSWD: /etc/init.d/apache2 start, /etc/init.d/apache2 stop

And your desktop shortcut thing tell it to execute

sudo /etc/init.d/apache2 start
share|improve this answer
i've got the following line added in visudo: marc ALL=NOPASSWD: /etc/init.d/apach2 start, /etc/init.d/apache2 stop and the script is excutable, and with sudo in front, but still asking for password – TWCrap Mar 4 '12 at 22:55
edit, add an e to the word apache, but still not working – TWCrap Mar 4 '12 at 22:58
Use sudo -l to confirm you see the command you're trying to configure after using visudo. sudo -l will tell you what commands you can run using sudo. – Kyle Smith Mar 4 '12 at 23:12
this is the output i get from that command: User marc may run the following commands on this host: (root) NOPASSWD: /etc/init.d/apache2 start, (root) /etc/init.d/apache2 stop (root) ALL – TWCrap Mar 4 '12 at 23:23

You can use gksudo to acquire root privileges visually, which is nice.



if [ "$EUID" = "0" ]; then
    # we're root, so just run it
    service apache2 start
    exit 0

# otherwise, try running it with a visual prompt for superuser
gksudo service apache2 start
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.