Teach you the detailed steps of setting up a Web server on CentOS step by step
First, open the terminal and enter the following command to install Apache:
sudo yum install httpd
After the installation is complete, start the Apache service:
sudo systemctl start httpd
In order to ensure that the Apache service starts automatically when the system starts, enter the following command:
sudo systemctl enable httpd
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
Then reload the firewall configuration:
sudo firewall-cmd --reload
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
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
Then create a new website directory and enter the following command:
sudo mkdir /var/www/mywebsite
Set directory permissions and enter the following Command:
sudo chown -R apache:apache /var/www/mywebsite
Next, open the Apache configuration file and enter the following command:
sudo nano /etc/httpd/conf/httpd.conf
Find the following line:
DocumentRoot "/var/www/html"
Change it to the path of the new website directory :
DocumentRoot "/var/www/mywebsite"
Save the file and exit.
In the new website directory/var/www/mywebsite
, create a page namedindex.html
file, enter the following:
Save the file and exit.
Enter the following command to restart the Apache service:
sudo systemctl restart httpd
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!