Apache in Terminal – Latest Installation Commands and Usage

Apache is a popular open-source web server used to host websites and web applications on Linux. It can be easily installed and managed using simple terminal commands. Apache allows you to start a local web server, create website files, manage configurations, and check server logs.

Features of Apache Command-Line Tool:

  • Start and stop the Apache web server.
  • Host websites on a Linux system.
  • Create and manage virtual hosts.
  • Enable Apache modules.
  • Test Apache configuration files.
  • View website access and error logs.
  • Run websites using the local server.
  • Manage Apache from the terminal.

Apache Installation Command

Below is the simple command to install Apache on a Debian or Ubuntu-based Linux system.

Update the package list.

apt update

Install Apache.

apt install apache2 -y

Apache is now installed and ready to use.

Apache Usage Commands

After installing Apache, you can use different commands to start the server, check its status, test your website, manage modules, and view logs.

Start Apache.

apachectl start

Note: You may see a ServerName warning when starting Apache. You can ignore this warning if Apache is running successfully, and you can still access your website at http://localhost:8080/.

Check if Apache is running.

pgrep httpd

Test the Apache configuration.

apachectl -t

If the configuration is correct, you should see:

Syntax OK

Open the Apache website in your browser:

http://localhost:8080

You can also test the local server from the terminal.

curl http://localhost:8080

Check the HTTP response headers.

curl -I http://localhost:8080

Default Apache website files in are stored in:

$PREFIX/share/apache2/default-site/htdocs

List the website files.

ls $PREFIX/share/apache2/default-site/htdocs

Open the default webpage.

nano $PREFIX/share/apache2/default-site/htdocs/index.html

You can replace the existing content with your own HTML code and then open:

http://localhost:8080

Restart Apache after making configuration changes.

apachectl restart

Stop Apache.

apachectl stop

View the Apache configuration file.

nano $PREFIX/etc/apache2/httpd.conf

View the Apache log directory.

ls $PREFIX/var/log/apache2

View the error log.

cat $PREFIX/var/log/apache2/error_log

Watch the error log in real time.

tail -f $PREFIX/var/log/apache2/error_log

You can also check the Apache process with:

ps -A | grep httpd

You can use these commands to manage Apache, run a local website, check server settings, and view important logs.

Apache Overview

Apache is a simple web server that is easy to install and manage from the terminal. You can use it to run a local website, test web pages, and learn basic web server management on Linux.

SHARE THIS POST: