This tutorial explains how to start the XAMPP automatically in the Ubuntu Linux. Learn how to create a script which starts the XAMPP during the boot process.
XAMPP is the third-party application software. By default, Ubuntu does not start any third-party application. If we want Ubuntu to start any specific third-party application for us at the startup, we must have to instruct Ubuntu about it.
For this tutorial, I assume that XAMPP is already installed. To learn what the XAMPP is and how it is installed in the Ubuntu Linux, see this tutorial.
Before we create a script which starts the XAMPP during the boot time, we need to confirm the version of Ubuntu. A lot of technical stuff changed in the LST version 18.04. These changes also include the way Ubuntu interacts with the startup scripts. To know the version of Ubuntu, open the terminal and run the following command.
This tutorial provides scripts for both earlier and later versions. If your Ubuntu version is 18.04 or higher then use the first script from below section. If your Ubuntu version is lower than 18.04, use the last script.
Creating a script to start XAMPP automatically in Ubuntu 18.04 or later
Run the following command.
$sudo gedit /etc/systemd/system/xampp.service
This command, if already not created, creates a new file named xampp.service in the directory /etc/systemd/system/ and opens it for editing.
In the opened file, add the following lines and save the file.
[Unit] Description=XAMPP [Service] ExecStart=/opt/lampp/lampp start ExecStop=/opt/lampp/lampp stop Type=forking [Install] WantedBy=multi-user.target
You may get the following warning messages at the terminal.
There is a known bug in the gedit text editor which displays these warning messages. More information about this bug is available here.
https://bugs.launchpad.net/ubuntu/+source/gedit/+bug/1575484
You have three choices to deal with these warning messages; update the gedit to fix the bug, use other text editor to create the script file such as the vim and nano or ignore these messages.
Creating a script file from other text editors is not as simple and straightforward as creating it from the gedit. Unless you are an experienced Linux user, I highly recommend you to simply ignore these warning messages.
Once the script file is created, run the following command to instruct Ubuntu to execute it at the startup.
Technically, we created a custom service through the script file and instructed Ubuntu to start this service at the startup. This custom service launches the XAMPP.
Verifying the script
To verify that XAMPP starts automatically at the startup, reboot the system.
After reboot, open the terminal and run the following command.
$sudo systemctl status xampp-service
This command displays the current status of the service xampp.service. If the status of this service is active, then the XAMPP is started.
You can also verify the auto start of XAMPP by accessing the following URL in browser.
Creating script in lower versions
In earlier versions, Ubuntu reads the directory /etc/init.d/ to find out the applications that it needs to start. If we place a script which starts XAMPP in this directory, XAMPP will be started automatically during the boot process.
Let’s understand this process step by step with practical example.
Open terminal and run the following command.
sudo gedit /etc/init.d/lampp
This command, if already not created, creates a new file named lampp in the directory /etc/init.d/ and opens it for editing.
In opened file, add the following lines.
#!/bin/bash ### BEGIN INIT INFO # Provides: lampp # Required-Start: $local_fs $syslog $remote_fs dbus # Required-Stop: $local_fs $syslog $remote_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Start lampp ### END INIT INFO /opt/lampp/lampp start
As long as the file is not saved, all changes remain in memory. Click the Save button to save the changes. Once the save button is clicked, the editor formats the file contents and save the file as the script file.
By default Linux does not make any file executable. It means, unless we manually make this script file executable, Linux will treat it as a regular text file.
Close the opened file and run the following commands to make it executable.
$ls –l /etc/init.d/lampp $sudo chmod +x /etc/init.d/lampp $ls –l /etc/init.d/lampp
First command lists the current file attributes.
Second command adds the execute permission in file attributes.
Third command also lists the current file attributes.
Compare the output of first and third commands to verify that execute permission has been successfully added in the file attributes.
Now run the following command.
$sudo update-rc.d lampp defaults
This command instructs Ubuntu to run our script file in all default runlevels.
Once this setup is done, XAMPP will be started automatically when the system starts.
Testing
To test this setup, reboot the system with the following command.
$reboot
After restart, run the following command
$systemctl list-units --type service
XAMPP uses the service named lampp to control all its operation. This command lists all services started by Ubuntu in the startup. To view to the status of lampp service only, we can filter the output with the grep command.
$systemctl list-units --type service |grep lampp
You can also verify it by accessing the following web page in browser.
http://localhost
Troubleshooting
When instructing Ubuntu to check the script file, you may get the following warning messages.
These warning messages indicate that something is wrong in /etc/init.d/lampp file. Before Ubuntu 16.04, comment section was not required in this file. Only adding the following lines was sufficient.
But this approach no longer works. Starting from Ubuntu 16.04, we have to add all necessary lines including the comment section.
If you get above warning messages or XAMPP does not start automatically when system starts, check the /etc/init.d/lampp file again. Make sure that all necessary lines have been added correctly.
That’s all for this tutorial. If you like this tutorial, please don’t forget to share it through your favorite social platform.