Home > Article > Computer Tutorials > Linux system Apache service configuration tutorial.
The tutorial for configuring the Apache service on a Linux system is as follows:
Step 1: Install Apache
First, log in to your Linux system as root or a user with sudo privileges.
Use the following command to install the Apache service:
sudo apt updatesudo apt install apache2
Step 2: Start Apache
After the installation is completed, the Apache service will start automatically. If it does not start, please use the following command to start it manually:
sudo systemctl start apache2
To make the Apache service start automatically when the system starts, use the following command:
sudo systemctl enable apache2
Step 3: Configure Apache
The main configuration file of Apache is located in the /etc/apache2
directory.
Open the main configuration file using the following command:
sudo nano /etc/apache2/apache2.conf
In this file, you can perform various configurations, such as modifying the default port, setting up a virtual host, etc.
Step 4: Configure virtual host (optional)
If you plan to host multiple websites on Apache, you can configure virtual host.
In the /etc/apache2/sites-available
directory, you can create a new virtual host configuration file. For example, use the following command to create a virtual host configuration file named mywebsite.conf
:
sudo nano /etc/apache2/sites-available/mywebsite.conf
In this file, you can configure the relevant information of the virtual host, such as domain name, website root directory, etc.
After completing the configuration, use the following command to enable the virtual host:
sudo a2ensite mywebsite.conf
Then reload the Apache configuration:
sudo systemctl reload apache2
Step 5: Firewall Settings (Optional)
If your Linux system has a firewall enabled, you need to allow HTTP (port 80) and HTTPS (port 443) traffic through the firewall.
Allow HTTP traffic using the following command:
sudo ufw allow 80
Allow HTTPS traffic using the following command:
sudo ufw allow 443
Step 6: Visit the website
Now you can access your website through your browser. Enter the server's IP address or domain name in the browser to access the default website or configured virtual host.
The above is a tutorial for configuring the Apache service on a Linux system. Please make the necessary configuration and modifications according to your needs.
The above is the detailed content of Linux system Apache service configuration tutorial.. For more information, please follow other related articles on the PHP Chinese website!