How to install Apache on Debian 9

Apache HTTP Server is one of the world's most popular Web server. It is an open source HTTP server and cross-platform support for most Internet sites. Apache provides many powerful features, it can be extended by other modules.

In this tutorial, we will introduce the steps to install the Apache server on Debian 9.

prerequisites

Before starting the tutorial, make sure you log in as a user with sudo privileges.

Installing Apache

Apache is available in the default Debian repositories, installation is very simple.

First update the package index, then use the following command to install apache2 package:

sudo apt update
sudo apt install apache2

Is so, install and automatically start Apache, Apache you can check the status of the service using the following command:

sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-08-23 20:04:47 UTC; 13s ago
 Main PID: 11604 (apache2)
   CGroup: /system.slice/apache2.service
           ├─11604 /usr/sbin/apache2 -k start
           ├─11608 /usr/sbin/apache2 -k start
           └─11609 /usr/sbin/apache2 -k start

Adjust the firewall

If the system is connected iptables filter, it is necessary to open the HTTP (80) and HTTPS (443) port.

Open the necessary ports by issuing the following command:

sudo iptables -A INPUT -p tcp --dport 80 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT

Verify Apache installation

To verify that everything is normal, open the browser, type the IP address of the server or doman name http: // YOUR_IP_OR_DOMAIN /, you'll see the default Apache welcome page, as shown below:

This page contains information about the Apache configuration file, some basic information to help script and directory location.

Use Apache systemctl Management Services

Now, on a Debian system installed Apache, you can take a moment to review and be familiar with basic apache service management commands:

To stop the Apache service, run:

sudo systemctl stop apache2

Type the following start it again:

sudo systemctl start apache2

To restart the Apache service:

sudo systemctl restart apache2

Use the following new configuration reload Apache:

sudo systemctl reload apache2

If you want to disable the Apache service randomly from the start:

sudo systemctl disable apache2

And re-enable random from the start:

sudo systemctl enable apache2

Apache configuration file structure and best practices

  • In systems based on Debian, Apache configuration file located in / etc / apache2 directory.
  • The main Apache configuration file is /etc/apache2/apache2.conf.
  • Apache will listen on port specified in /etc/apache2/ports.conf file.
  • Apache virtual hosts file is located in / sites-available directory / etc / apache2. Unless the link to / etc / apache2 / sites-enabled directory, or does not use Apache configuration files in this directory.
  • To activate the virtual host, you can use a2ensite command, change the command creates a symbolic link to profile sites-available directory in the sites-enabled directory. To disable virtual hosts, use the command. a2dissite
  • It is strongly recommended to follow the standard naming convention, for example, if your domain is mydomain.com domain configuration file, it should be named /etc/apache2/sites-available/mydomain.com.conf
  • Apache module for loading various configuration files located in / mods-available directory / etc / apache2. a2enconf command to enable located mods-available directory module, it creates a symbolic link to mods-available modules in the / etc / apache2 / mods-enable directory. Also, disable it using the command a2disconf.
  • Global configuration file store contains fragments in / etc / apache2 / conf-available directory. The configuration fragments conf-available can be started by a2enconf command, he will create a symbolic link in / etc / apache2 / conf-enabled directory. Also, disable it using the command a2disconf.
  • Apache log files (the access.log and the error.log) located at / var / log / apache directory. Recommended for each virtual host uses different access and error log files.
  • You can site document root is set to any desired location. The most common location webroot include:
    • /home/<user_name>/<site_name>
    • /var/www/<site_name>
    • /var/www/html/<site_name>
    • /opt/<site_name>

in conclusion

You have successfully installed the server on Debian 9 of the Apache. You can now deploy the application and Apache as the Web or proxy server.

Guess you like

Origin www.linuxidc.com/Linux/2019-08/160057.htm