Starting, Stopping and Restarting Web-servers in Linux

How to control servers such as Apache and Nginx in Linux.

11054 views

Edited: 2019-11-21 05:58

Controlling your web servers can typically be done using simple commands like: start, stop and restart – but XAMPP also have a few additional commands that can be used to control the servers independently.

The part you write in front of the command may look something like: /etc/init.d/apache2, the front part of the command should of course correspond to your installation directory. Keep in mind that in Unix-like systems, such as Ubuntu, things are often located somewhat all over the place.

You may need to run the commands in this article as root, so either run them with sudo in front, or switch to root with the su command before using them. I.e.

sudo /etc/init.d/apache2 start

Apache

The Apache HTTP Server can be controlled from a terminal with the "standard" start, stop and restart commands.

The preferred way is to use the service interface:

service apache2 start
service apache2 stop
service apache2 restart
service apache2 reload

If this does not work for you, this might work instead:

/etc/init.d/apache2 start
/etc/init.d/apache2 stop
/etc/init.d/apache2 restart
/etc/init.d/apache2 reload

Otherwise, look up the documentation for your distribution of Linux.

MySQL

Use the following to control your MySQL server:

service mysql start
service mysql stop
service mysql restart

XAMPP

When using XAMPP, you can use the start, stop and restart commands to control your servers. I.e.

/opt/lampp/lampp start
/opt/lampp/lampp stop
/opt/lampp/lampp restart

In addition to these commands, you can also use commands such as: restartapache, startapache, stopapache and stopmysql, startmysql, restartmysql. I.e.

/opt/lampp/lampp startapache
/opt/lampp/lampp stopapache
/opt/lampp/lampp restartapache

/opt/lampp/lampp startmysql
/opt/lampp/lampp stopmysql
/opt/lampp/lampp restartmysql

Nginx

The Nginx web server can also be controlled with the same start, stop, and restart commands as Apache. I.e.

/etc/init.d/nginx start
/etc/init.d/nginx stop
/etc/init.d/nginx restart

Postfix

Controlling the postfix SMTP server can be done with these commands:

service postfix start
service postfix stop
service postfix restart

Tell us what you think:

  1. Understanding file permissions in Unix / Linux based systems, and how to make files immutable.
  2. In this article I will explain how to enable a swapfile on small instances, and why it might be useful, even if you do have enough physical memory.
  3. How to determine an optimal value for pm.max_children and related php-fpm settings for your server and web applications.
  4. Tutorial showing how to configure a VirtualBox Guest VM with HOST-only and NAT adapter, while using the WWW folder from the HOST OS.
  5. You may have wondered what the /etc/php/8.0/conf.d/ directory is for in Debian and Ubuntu, and whether it is better to edit the conf.d files than editing php.ini directly; find out in this Tutorial.

More in: Linux servers