In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Xiaobian to share with you how to install and configure Apache Web server in CentOS7, I hope you have gained something after reading this article, let's discuss it together!
Learn how to host your own website on Apache in CentOS 7, a reliable, popular and easy to configure Web server.
I have hosted my own website for many years. Since switching from OS/2 to Linux more than 20 years ago, I have used Apache as my server software. Apache is reliable, popular, and easy to configure for basic installation. For more complex settings (such as multiple websites) it is not that difficult.
Apache Web server installation and configuration must be performed as root. Firewall configuration also needs to be performed as root. Viewing the results of the installation configuration using a browser should be done as a non-root user. (I use the user student on my virtual host.)
installation
Note: I used a virtual machine with Fedora 27 installed, Apache version 2.4.29. If you are using a different distribution or version of Fedora, your commands and the location and content of configuration files may vary. However, the configuration lines you need to modify are the same.
Apache Web server is easy to install. On my CentOS 6.x server, it just requires a simple yum command. It installs all necessary dependencies (if needed). I used the following dnf command on my Fedora virtual machine. Except for the name of the command itself, dnf and yum have the same syntax.
dnf -y install httpd
This virtual machine is a very basic desktop environment, and I'm using it as a testbed for writing books. Even on this system, only six dependencies were installed, which took one minute.
All Apache configuration files are located in/etc/httpd/conf and/etc/httpd/conf.d. By default, the site's data is located at/var/www, but you can change it if you wish.
configured
Apache's main configuration file is/etc/httpd/conf/httpd.conf. It contains many configurations that do not need to be changed in the basic installation. In fact, just making a few changes to this file will get a simple website up and running. The file is very large, so I won't confuse this article with a lot of unnecessary stuff, but only show instructions that need to be changed.
First, take a moment to familiarize yourself with the httpd.conf file. One of the things I like about Red Hat is that its configuration file comments are very detailed. The httpd.conf file is no exception because it has good comments. You can use these comments to understand the configuration of the file.
The first thing to change is the Listen configuration entry, which defines the IP address and port on which Apache listens for page requests. For now, you just need to make the site accessible locally, so use the localhost address. When completed, the line should look something like this: 127.0.0.1
Listen127.0.0.1:80
By setting this configuration entry to the IP address of localhost, Apache will only listen for connections from localhost. If you want your Web server to listen for connections from remote hosts, you can use the host's external IP address.
The DocumentRoot configuration item specifies the location of the HTML files that make up the Web site pages. This configuration item does not need to be changed because it already points to the standard location. The line should look like this:
DocumentRoot"/var/www/html"
The Apache installation package creates the/var/www directory. If you want to change the location where your site files are stored, use this configuration item to do so. For example, you might want to use a different name for the www directory to more clearly identify the site. This could be something like this:
DocumentRoot"/var/mywebsite/html"
These are the only Apache configuration items that need to be modified to create a simple website. For this little exercise, only a few modifications were made to the httpd.conf file (Listen configuration item). Other configuration items are not required for a simple Web server at this time.
Another thing that needs to change is opening port 80 in our firewall. I use iptables as my firewall, so I changed the/etc/sysconfig/iptables file to add permission to use the HTTP protocol. The entire file looks like this:
# sample configuration for iptables service# you can edit this manually oruse system-config-firewall# please donot ask us to add additional ports/services to thisdefault configuration*filter:INPUT ACCEPT [0:0]:FORWARD ACCEPT [0:0]:OUTPUT ACCEPT [0:0]-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT-A INPUT -p icmp -j ACCEPT-A INPUT -i lo -j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 22-j ACCEPT-A INPUT -p tcp -m state --state NEW -m tcp --dport 80-j ACCEPT-A INPUT -j REJECT --reject-with icmp-host-prohibited-A FORWARD -j REJECT --reject-with icmp-host-prohibitedCOMMIT
I added a new line on the third last line of the file that allows traffic to be entered on port 80. Now I reload the iptables configuration file.
[root@testvm1 ~]#cd/etc/sysconfig/; iptables-restore iptables
Create index.html file
The index.html file is the default file when you visit a website using a domain name rather than visiting a specific web page. In/var/www/html, create a file named index.html and add the string Hello World to it. You don't need to add any HTML tags to do this. The web server's sole task is to provide a stream of text data, and the server doesn't know what the data is or how to render it. It simply transmits the data stream to the requesting host.
After saving the file, set the ownership to apache.apache.
[root@testvm1 html]#chown apache.apache index.html
start Apache
Apache is easy to start. The current version of Fedora uses systemd. Run the following command to start it and check the status of the server:
[root@testvm1 ~]#systemctl start httpd[root@testvm1 ~]#systemctl status httpd● httpd.service -TheApache HTTP ServerLoaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)Active: active (running) since Thu2018-02-0813:18:54 EST;5s agoDocs:man:httpd.service(8)Main PID:27107(httpd)Status:"Processing requests... "Tasks:213(limit:4915)CGroup:/system.slice/httpd.service├─27107/usr/sbin/httpd -DFOREGROUND├─27108/usr/sbin/httpd -DFOREGROUND├─27109/usr/sbin/httpd -DFOREGROUND├─27110/usr/sbin/httpd -DFOREGROUND└─27111/usr/sbin/httpd -DFOREGROUNDFeb0813:18:54 testvm1 systemd[1]:StartingTheApache HTTP Server... Feb0813:18:54 testvm1 systemd[1]:StartedTheApache HTTP Server.
The commands on your server may be different. On Linux systems that use SystemV startup scripts, the commands are as follows:
[root@testvm1 ~]# service httpd startStarting httpd:[FriFeb0908:18:072018] [ OK ][root@testvm1 ~]# service httpd statushttpd (pid 14649)is running...
If you have a browser like Firefox or Chrome on your host, you can use the URL localhost on the URL line of your browser to display your web page, although it seems simple. You can also use a text-mode web browser like Lynx to view web pages. First, install Lynx (if it is not already installed).
[root@testvm1 ~]# dnf -y install lynx
Then use the following command to display the web page.
[root@testvm1 ~]# lynx localhost
This is what happened in my terminal. I have removed a lot of white space from the page.
HelloWorldCommands:Use arrow keys to move,'? 'for help,'q' to quit,'
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.