So you have a Linux box your using as a LAMP server (Linux Apache mySQL PHP). But you are not an experienced admin and the thought of downloading and compiling AMP part is keeping you up at night. So you decided to use a pre-packaged developer suite call XAMPP. You just uncompress the file and run a command and BANG you have your own web application platform. Simply awesome.
But the reality starts to set in. Every time you reboot the box you have to start the service up manually. And sometimes you get nasty mySQL errors because the server stopped right in the middle of a transaction. What to do what to do? Well my friend I’ve been right where you are. And I figured out though much Google search and smart fellow users of XAMPP on Linux how to add the package as a service on RedHat Enterprise Linux based distributions. Namely CentOS for my example. After this is setup you will be able to:
1. Specify which run levels XAMPP will run at.
2. Auto create the start and stop scripts for those run levels.
3. Check on the status of the service using the service command.
4. Modify which runlevels the service runs on using the chkconfig command.
Special Note:
Please be advised that out of the box XAMPP is a developer tool. It is not meant for production deployment of services. mySQL has no root password, Apache SSL is not totally configured, and services like ftp are spawned by default. Please only setup XAMPP in a secure development environment knowing the risks involved.
The Service Command
Most distros of Linux that I have run have the service command. Basically, it is the interface for all the services that the OS starts up and shuts down automatically. Its basic uses are
service --status-all
service “service name” status
service “service name” start|stop
The --status-all option returns a full list of the operational states of all services. Now this list can be a little long so you may want to pipe it though the less or grep command if you looking for something specific. If you know the name of your service you can user the “service name” status option to see its current state. And of course the start|stop options starts or stops the service. Most applications have a script that conform to these commands. Now to setup the the service so we can use this command.
Edit the Start-up File
Most application packages like XAMPP have a start-up files that allows you to start or stop the app. If we assume you installed the package in the default location (/opt) that file should be /opt/lampp/lampp . Now yes the package is called XAMPP but on Linux its called lampp. Annoying but that’s Linux baby. Anyhow first thing you want to do is make a trivial but important edit to the start-up file. Using your favorite editor add the following comment to the file:
# chkconfig: 1-5 95 05
This comment will not effect your scripts operation so don’t worry about that. After the chkconfig: you have the numbers 1-5. These represent the run-levels the service will operate on. All the runlevels should be typed next to each other with no spaces. So run levels 2, 3, 4, 5 would be 2345. The second number is the priority of start scripts. The last number is the priority for kill scripts. For most uses the last two numbers don’t matter but if you are using this tip on a production or secure system you may want to do further research.
Adding and Activating the Service
Now comes the fun part. After you have edited the start-up script you want to create a symbolic link for the script to the /etc/xinit.d directory. The command should look like:
ln -s /opt/lampp/lampp /etc/init.d/lampp
Once that is done you want you activate the service by running the following command:
chkconfig --add lampp
And there you go. Your new service should be be installed. You can run these commands to make sure:
service lampp status
chkconfig --list | grep lampp
And of course to start your service if you haven’t already done so you would run:
service lampp start
Things to Think About
Like I said earlier software applications may start up a number of services you may not want running on your server. So take care to look though the start-up script to see what is there. Most times you can do so simply by invoking the script.
But the reality starts to set in. Every time you reboot the box you have to start the service up manually. And sometimes you get nasty mySQL errors because the server stopped right in the middle of a transaction. What to do what to do? Well my friend I’ve been right where you are. And I figured out though much Google search and smart fellow users of XAMPP on Linux how to add the package as a service on RedHat Enterprise Linux based distributions. Namely CentOS for my example. After this is setup you will be able to:
1. Specify which run levels XAMPP will run at.
2. Auto create the start and stop scripts for those run levels.
3. Check on the status of the service using the service command.
4. Modify which runlevels the service runs on using the chkconfig command.
Special Note:
Please be advised that out of the box XAMPP is a developer tool. It is not meant for production deployment of services. mySQL has no root password, Apache SSL is not totally configured, and services like ftp are spawned by default. Please only setup XAMPP in a secure development environment knowing the risks involved.
The Service Command
Most distros of Linux that I have run have the service command. Basically, it is the interface for all the services that the OS starts up and shuts down automatically. Its basic uses are
service --status-all
service “service name” status
service “service name” start|stop
The --status-all option returns a full list of the operational states of all services. Now this list can be a little long so you may want to pipe it though the less or grep command if you looking for something specific. If you know the name of your service you can user the “service name” status option to see its current state. And of course the start|stop options starts or stops the service. Most applications have a script that conform to these commands. Now to setup the the service so we can use this command.
Edit the Start-up File
Most application packages like XAMPP have a start-up files that allows you to start or stop the app. If we assume you installed the package in the default location (/opt) that file should be /opt/lampp/lampp . Now yes the package is called XAMPP but on Linux its called lampp. Annoying but that’s Linux baby. Anyhow first thing you want to do is make a trivial but important edit to the start-up file. Using your favorite editor add the following comment to the file:
# chkconfig: 1-5 95 05
This comment will not effect your scripts operation so don’t worry about that. After the chkconfig: you have the numbers 1-5. These represent the run-levels the service will operate on. All the runlevels should be typed next to each other with no spaces. So run levels 2, 3, 4, 5 would be 2345. The second number is the priority of start scripts. The last number is the priority for kill scripts. For most uses the last two numbers don’t matter but if you are using this tip on a production or secure system you may want to do further research.
Adding and Activating the Service
Now comes the fun part. After you have edited the start-up script you want to create a symbolic link for the script to the /etc/xinit.d directory. The command should look like:
ln -s /opt/lampp/lampp /etc/init.d/lampp
Once that is done you want you activate the service by running the following command:
chkconfig --add lampp
And there you go. Your new service should be be installed. You can run these commands to make sure:
service lampp status
chkconfig --list | grep lampp
And of course to start your service if you haven’t already done so you would run:
service lampp start
Things to Think About
Like I said earlier software applications may start up a number of services you may not want running on your server. So take care to look though the start-up script to see what is there. Most times you can do so simply by invoking the script.
0 comments:
Post a Comment