In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "CentOS7 how to install and configure Apache Web", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "CentOS7 how to install and configure Apache Web" bar!
The installation and configuration of the Apache Web server must be performed as root. The configuration of the firewall 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 student as a user on my virtual host.)
Installation
Note: the experimental environment I used was a virtual machine with Fedora 27 installed, and the Apache version was 2.4.29. If you are using a different distribution or a different version of Fedora, the location and contents of your commands and configuration files may be different. However, the configuration lines that you need to modify are the same.
The Apache Web server is very easy to install. On my CentOS 6.x server, it only requires a simple yum command. It installs all the necessary dependencies, if necessary. I used the following dnf command on my Fedora virtual machine. The syntax for dnf and yum is the same except for the name of the command itself.
Dnf-y install httpd
This virtual machine is a very basic desktop environment, and I am using it as a test platform for writing books. Even on this system, only six dependencies were installed and it took one minute.
All configuration files for Apache are located in / etc/httpd/conf and / etc/httpd/conf.d. The data of the site is located at / var/www by default, but you can change it if you like.
Configuration
The main configuration file for Apache is / etc/httpd/conf/httpd.conf. It contains many configurations that do not need to be changed in the basic installation. In fact, you only need to make some changes to this file to get a simple Web site 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 reasons I like Red Hat is that its configuration file annotations are very detailed. The httpd.conf file is no exception because it is well annotated. You can use these comments to understand the configuration of the file.
The first thing to modify is the Listen configuration item, which defines the IP address and port on which Apache listens for page requests. Now, you just need to make the site accessible locally, so use the localhost address. When finished, the line should look like this:
Listen127.0.0.1:80
By setting this configuration item to the IP address of localhost, Apache will only listen for connections from the local host. If you want the Web server to listen for connections from remote hosts, you can use the external IP address of the host.
The DocumentRoot configuration item specifies the location of the HTML file that makes up the page of the Web site. This configuration item does not need to be changed because it already points to a standard location. The bank 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 Web 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 Web site. This can go like this:
DocumentRoot "/ var/mywebsite/html"
These are the only Apache configuration items that need to be modified to create a simple Web site. For this little exercise, only a few changes have been made to the httpd.conf file (the Listen configuration item). Other configuration items need not be configured for a simple Web server for the time being.
Another thing that needs to change is to open port 80 in our firewall. I use iptables as my firewall, so I change the / etc/sysconfig/iptables file to add that the HTTP protocol is allowed. The whole 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]-An INPUT-m state-- state RELATED ESTABLISHED-j ACCEPT-An INPUT-p icmp- j ACCEPT-An INPUT-I lo-j ACCEPT-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 22Lauj ACCEPT-An INPUT-p tcp-m state-- state NEW-m tcp-- dport 80Raj ACCEPT-An INPUT-j REJECT-- reject-with icmp-host-prohibited-A FORWARD-j REJECT-- reject-with icmp-host-prohibitedCOMMIT
I added a new line to the penultimate 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
Index.html files are the default files when you use a domain name to visit a website instead of 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 flags to get the job done. The only task of the web server is to provide a data stream of text, and the server does not 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 ownership to apache.apache.
[root@testvm1 html] # chown apache.apache index.html starts Apache
Apache is easy to start. The current version of Fedora uses systemd. Run the following command to start it, and then 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 1854 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 the SystemV startup script, the command is 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 URL localhost on the URL line of the browser to display your web page, even though it looks simple. You can also view web pages using a text-mode web browser like Lynx. First, install Lynx (if it's not already installed).
[root@testvm1 ~] # dnf-y install lynx
Then use the following command to display the web page.
[root@testvm1 ~] # lynx localhost
It turned out to be like this in my terminal. I have deleted a lot of white space on the page.
HelloWorldCommands:Use arrow keys to move,'?'for help,'q' to quit,' to go back.Arrow keys:UpandDown to move.Right to follow a link;Left to go back.H) elp O) ptions P) rint G) o) ain screen Q) uit / = search [delete] = history List```
Next, edit your index.html file and add some HTML tags to make it look like this:
Hello World
Now refresh the browser. For Lynx, use the key combination Ctrl + R. The result looks a little different. If your terminal supports color, the text will be displayed in color, and Lynx will display the title, which is now centered. In a GUI browser, the text is displayed in a large font.
HelloWorldCommands:Use arrow keys to move,'?'for help,'q' to quit,' to go back.Arrow keys:UpandDown to move.Right to follow a link Left to go back.H) elp O) ptions P) rint G) o M) uit / = search [delete] = history list Thank you for reading, above is the content of "how to install and configure Apache Web in CentOS7". After the study of this article, I believe you have a deeper understanding of how to install and configure Apache Web in CentOS7, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.