How do I start, restart, or stop Apache 2.x web server on Ubuntu Linux operating systems using command line options?
You can use any one of the following method to restart / start / stop your Apache (httpd) sever on Ubuntu:
Difficulty | Easy (rss) |
Root privileges | Yes |
Requirements | Shell |
Estimated completion time | 1m |
- /etc/init.d/apache2 - A sys v init style script to start / stop / restart the Apache2 service under Debian or Ubuntu Linux.
- service command - This command work in most Linux distributions including Debian and Ubuntu.
- upstart command - Only works on latest version of Ubuntu.
- apache2ctl command - This method should work on all Linux and Unix like operating systems.
Method #1: /etc/init.d/apache2 command examples
You need to login as root user or use the sudo command to control Apache web-server.
Task: Start Apache 2 Server
# /etc/init.d/apache2 start
or$ sudo /etc/init.d/apache2 start
Task: Restart Apache 2 Server
# /etc/init.d/apache2 restart
or$ sudo /etc/init.d/apache2 restart
Task: Stop Apache 2 Server
# /etc/init.d/apache2 stop
or$ sudo /etc/init.d/apache2 stop
Method #2: service command examples
To restart Apache 2, enter:$ sudo service apache2 restart
To stop Apache 2, enter:$ sudo service apache2 stop
To start Apache 2, enter:$ sudo service apache2 start
To gracefully reload Apache 2, enter:$ sudo service apache2 reload
Method #3: upstart command examples
To start Apache 2 on Ubuntu, run:$ sudo start apache2
To stop Apache 2 on Ubuntu, run:$ sudo stop apache2
To restart Apache 2 on Ubuntu, run:$ sudo restart apache2
To gracefully reload Apache 2 on Ubuntu, run:$ sudo restart apache2
Method #4: apache2ctl command examples
apache2ctl is Apache HTTP server control interface command, which can be used to stop or start web server under any Linux distribution or UNIX.
To start Apache 2 on Ubuntu, type:$ sudo apache2ctl start
To stop Apache 2 on Ubuntu, type:$ sudo apache2ctl stop
To restart Apache 2 on Ubuntu, type:$ sudo apache2ctl restart
To gracefully reload Apache 2 on Ubuntu, type:$ sudo apache2ctl graceful