Hi, I would like to know to to make a script that will start LAMPP when I double click it the shell file, and stop it when I double click it again. Is this possible?
The terminal prompts which I have to use are:
sudo /opt/lampp/lampp start
sudo /opt/lampp/lampp stop
It really is annoying when I have to type that every time I want to start or stop it and it would be really nice to have a script do that instead.
BTW, I have to run as root to start LAMPP.
I would appreciate it if someone told me how to do this.
Thank You.
How to make a script to start and stop XAMPP(LAMPP)?
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
How to make a script to start and stop XAMPP(LAMPP)?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: How to make a script to start and stop XAMPP(LAMPP)?
Okay, this is a simple script, but should do what you want. If you use LMDE, delete the two notify-send commands as those are not supported on LMDE (these just pop-up a small feedback balloon to you, showing what it is doing). Might also not work on Linux Mint 9, please test. The rest of the script will do what you want without these two lines
Start Gedit (Text Editor) from the Menu, and copy the following text into it:
Save the file as "lampp-toggle" at a location of your choosing (for example to your home folder), then close it. Now right-click the file > Properties > Permissions, and mark "Allow executing file as a program".
You have to start the script with "gksudo ~/lampp-toggle" or "sudo ~/lampp-toggle". To make this easier, you can right-click the Menu > Edit menu and add a menu item for this.
Now, to avoid having to type a password for this each time, you can change that the script can be run with sudo without requiring a password. Run the following command to start editing:
Then add a line at the end:
Where you replace, twice, sagirfahmid3 with your username. And make sure the path at the end then matches the location of where you saved the script. Save the file with Ctrl+O (letter O) and exit with Ctrl+X. Now starting "gksudo ~/lampp-toggle" or "sudo ~/lampp-toggle" will do so without asking for a password.
The only caveat of this script is that if you stop or start LAMPP without this script, and then use the script--it doesn't know what you did, so it might do the other action than you want (trying to start, while you want it to stop and vice versa). Just run it another time to get it to do what you wanted.
Edit: corrected how to edit the /etc/sudoers file.
Start Gedit (Text Editor) from the Menu, and copy the following text into it:
Code: Select all
#!/bin/bash
# check running as root
if [[ $(id -un) != root ]]; then
zenity --error --text="$0 must be run as effective root user." --title=$(basename $0)
exit 1
fi
# toggle LAMPP
if [[ -f /var/run/lampp-toggle ]]; then
notify-send --expire-time=3 $(basename $0) "Stopping LAMPP"
/opt/lampp/lampp stop
rm -f /var/run/lampp-toggle
else
notify-send --expire-time=3 $(basename $0) "Starting LAMPP"
/opt/lampp/lampp start
touch /var/run/lampp-toggle
fi
You have to start the script with "gksudo ~/lampp-toggle" or "sudo ~/lampp-toggle". To make this easier, you can right-click the Menu > Edit menu and add a menu item for this.
Now, to avoid having to type a password for this each time, you can change that the script can be run with sudo without requiring a password. Run the following command to start editing:
Code: Select all
sudo EDITOR=nano visudo
Code: Select all
sagirfahmid3 ALL=NOPASSWD:/home/sagirfahmid3/lampp-toggle
The only caveat of this script is that if you stop or start LAMPP without this script, and then use the script--it doesn't know what you did, so it might do the other action than you want (trying to start, while you want it to stop and vice versa). Just run it another time to get it to do what you wanted.
Edit: corrected how to edit the /etc/sudoers file.
Last edited by xenopeek on Sat Oct 15, 2011 2:37 pm, edited 1 time in total.
Re: How to make a script to start and stop XAMPP(LAMPP)?
Thanks a lot...I followed the instructions....and it broke my sudo. Now I cant do anything....
Gonna have to reinstall Mint.
Gonna have to reinstall Mint.
Re: How to make a script to start and stop XAMPP(LAMPP)?
That was clearly not my intention! I don't know what caused your sudo not to work anymore, but you can remedy this without a re-install. Please share if I can help on this.
Hold shift during boot to show the GRUB boot menu. Select the 2nd entry in the boot menu (recovery mode). You will get a text mode menu, scroll down and select "drop to root console" (or something like that). You are now the root user, and have a terminal where you can run commands as root. Then edit the /etc/sudoers file manually and delete the last line that you added (press Ctrl+O [letter O] to save, and Ctrl+X to exit nano):
Edit: corrected how to edit the /etc/sudoers file.
Hold shift during boot to show the GRUB boot menu. Select the 2nd entry in the boot menu (recovery mode). You will get a text mode menu, scroll down and select "drop to root console" (or something like that). You are now the root user, and have a terminal where you can run commands as root. Then edit the /etc/sudoers file manually and delete the last line that you added (press Ctrl+O [letter O] to save, and Ctrl+X to exit nano):
Code: Select all
EDITOR=nano visudo
Last edited by xenopeek on Sat Oct 15, 2011 2:40 pm, edited 2 times in total.
Re: How to make a script to start and stop XAMPP(LAMPP)?
It says "can't stat /etc/sudoers: No such file or directory".
Why dont you copy your sudoers file and upload it, then i can download it and paste it there
Why dont you copy your sudoers file and upload it, then i can download it and paste it there
Re: How to make a script to start and stop XAMPP(LAMPP)?
I gave the wrong command to edit the /etc/sudoers file. My humble apologies for causing your problem. The correct command to edit the /etc/sudoers file with nano is (from the recovery mode):
The /etc/sudoers file on my system (Linux Mint 10 and 11):
Ignoring the comments, the following four lines need to be in the file to be able to use sudo from your own user account again. I suggest you put those four in, and then restore the complete file after you reboot to normal mode again and can use copy & paste (as you can not just overwrite the /etc/sudoers file, but need to use visudo).
Code: Select all
EDITOR=nano visudo
Code: Select all
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
#includedir /etc/sudoers.d
Code: Select all
Defaults env_reset
root ALL=(ALL:ALL) ALL
%admin ALL=(ALL) ALL
%sudo ALL=(ALL:ALL) ALL
Re: How to make a script to start and stop XAMPP(LAMPP)?
Yeah...Im just gonna reinstall and MAKE A BACKUP JUST IN CASE SOMETHING GOES HORRIBLY WRONG WHEN FOLLOWING PEOPLE'S INSTRUCTIONS