Saturday, September 23, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  4] [ 0]  / answers: 1 / hits: 4760  / 2 Years ago, sun, february 20, 2022, 5:33:02

I am trying to write a script that will enable xampp start and xampp stop with the same script without having to write in the terminal everytime.

To start xampp, I write in console :

sudo /opt/lampp/lampp start
sudo /opt/lampp/lampp stop

How to make a script executable which allows xampp to start and stop simultaneously when double clicked ? Any idea is always welcomed.

More From » bash


You'll need to do 2 things to get what you want :

1) Create a simple bash script to start lampp

I've written it for you! It starts lampp if it isn't started and stops it if it's already started :

#!/bin/bash                                           ##This is a bash script

if [[ ! -f /tmp/lampp-startstop ]] ; then # if temp file doesn't exist
echo 0 > /tmp/lampp-startstop 2>&1 # create it and write 0 in it

if [ "`cat /tmp/lampp-startstop`" == "0" ] ; then # if temp file contains 0
sudo /opt/lampp/lampp start # start lampp
echo 1 > /tmp/lampp-startstop 2>&1 # write 1 in the temp file
notify-send "Lampp" "Program started." -i xampp # send a notification
exit 0 # and exit

if [ "`cat /tmp/lampp-startstop`" == "1" ] ; then # if temp file contains 1
sudo /opt/lampp/lampp stop # stop lampp
echo 0 > /tmp/lampp-startstop 2>&1 # write 0 in the temp file
notify-send "Lampp" "Program stopped." -i xampp # send a notification
exit 0 # and exit

2) Create a shortcut that will launch that script (on the Desktop for example) :

  • A) Create a .desktop file on the Desktop :

    gedit ~/Desktop/Lampp.desktop 

  • B) Enter the following in it :

    [Desktop Entry]
    Comment=Start/Stop Lampp
    Exec=gksu bash /PATH/TO/THE/SCRIPT

    => Remplace the two /PATH/TO/THE/... by something. Icons are stored in /usr/share/icons/ and a good place for the script would be in your HOME folder, maybe hidden (hide by adding a . at the beginning of his name).

  • C) Make it executable :

    sudo chmod +x ~/Desktop/Lampp.desktop

Note : the script isn't really checking if lampp is working, it is using a temporary file (disapears at reboot) containing 1 if you have used the script once (meaning it's started) and 0 if you haven't used the script (meaning it isn't started).
What does it mean ? That you have to only use this script if you want things to work : do not start lampp without this script and you'll be ok.

Note : you'll have to type your password in order to launch the shortcut. You could bypass that, but that wasn't your question so I will not explain that here.

[#26707] Sunday, February 20, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 459
Total Questions: 112
Total Answers: 109

Location: Equatorial Guinea
Member since Sun, Feb 14, 2021
3 Years ago