Teach you step by step the detailed steps of setting up a web server on CentOS

PHPz
Release: 2023-08-07 15:25:06
Original
2097 people have browsed it

Teach you the detailed steps of setting up a Web server on CentOS step by step

  1. Introduction
    Web server is a software that supports HTTP protocol and is used to provide web pages and Web services. You can use common software such as Apache and Nginx to build a web server on CentOS. This article will use Apache as an example to introduce the detailed steps of building a web server on CentOS.
  2. Install Apache

First, open the terminal and enter the following command to install Apache:

sudo yum install httpd
Copy after login

After the installation is complete, start the Apache service:

sudo systemctl start httpd
Copy after login

In order to ensure that the Apache service starts automatically when the system starts, enter the following command:

sudo systemctl enable httpd
Copy after login
  1. Configure the firewall

In order to allow Apache to access normally, you need to configure firewall rules. Enter the following command to start the HTTP service:

sudo firewall-cmd --permanent --zone=public --add-service=http
Copy after login

Then reload the firewall configuration:

sudo firewall-cmd --reload
Copy after login
  1. Test Apache

Enter the server's address in the browser address bar IP address, if you see Apache's welcome page, the installation is successful. You can view the IP address of the server through the following command:

hostname -I
Copy after login
  1. Configure the website directory

By default, Apache’s website directory is /var/www/html . Can be modified as needed.

First, back up the default website directory and enter the following command:

sudo mv /var/www/html /var/www/html_backup
Copy after login

Then create a new website directory and enter the following command:

sudo mkdir /var/www/mywebsite
Copy after login

Set directory permissions and enter the following Command:

sudo chown -R apache:apache /var/www/mywebsite
Copy after login

Next, open the Apache configuration file and enter the following command:

sudo nano /etc/httpd/conf/httpd.conf
Copy after login

Find the following line:

DocumentRoot "/var/www/html"
Copy after login

Change it to the path of the new website directory :

DocumentRoot "/var/www/mywebsite"
Copy after login

Save the file and exit.

  1. Create a test page

In the new website directory /var/www/mywebsite, create a page named index.html file, enter the following:

<!DOCTYPE html>
<html>
<head>
  <title>My Website</title>
</head>
<body>
  <h1>Welcome to My Website!</h1>
</body>
</html>
Copy after login

Save the file and exit.

  1. Restart Apache

Enter the following command to restart the Apache service:

sudo systemctl restart httpd
Copy after login
  1. Test website

is browsing Enter the server's IP address into the server and you should see the welcome message displayed on the test page.

At this point, the steps to build a web server on CentOS have been completed.

Summary:
This article takes Apache as an example and details the steps to build a web server on CentOS, including installing Apache, configuring the firewall, testing Apache, configuring the website directory, creating a test page and restarting Apache. By following the above steps, you can successfully set up a web server on CentOS and start publishing your own website.

The above is the detailed content of Teach you step by step the detailed steps of setting up a web server on CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template