Apache server Overview - Installation - setting up the environment before setting up the Web site server

Apache server Overview - Installation

Apache server Overview - Installation

WEB server, also known as WWW(WORLD WIDE WEB) server, is mainly used to provide online information browsing
Service.
Common web servers:

httpd(Apache),nginx+PHP
Tomcat:  jsp + html
win:IIS

Client: IE, firefox, chrome, mobile (Browser) Browser
Today's protagonist: Lamp = Linux Apache MySQL Apache (HTTPD) in PHP

Lunix system
Linux+Apache+Mysql/MariaDB+Perl/PHP/Python, a group of open source software commonly used to build dynamic websites or servers, are their own independent programs, but because they are often used together, they have higher and higher compatibility, and together form a powerful Web application platform. With the vigorous development of open source trend, open source LAMP has been combined with J2EE and Net commercial software has formed a tripartite trend, and the investment cost of the software development project is low, so it has attracted the attention of the whole IT community. In terms of website traffic, more than 50% of the traffic is provided by LAMP, which is the most powerful website solution

What is Apache

Apache HTTPD Server, referred to as Apache for short, is an open source web server of the Apache Software Foundation, which can be found in
Running in most computer operating systems, it is one of the most popular Web server-side software because of its multi platform and security
One. It is fast, reliable and can compile interpreters such as Perl/Python into the server through simple API extensions!
Apache HTTP server is a modular server. All functions are plugged in and out with modularity! Currently supports Windows,

Linux, Unix and other platforms!
The Apache Software Foundation (also known as the Apache Software Foundation, referred to as ASF) is dedicated to the operation of a
The open source software project is a non-profit organization supported by the Apache community. This open source software project is the Apache project! that
Our HTTPD is only one of Apache's open source projects!
Main open source projects: HTTP Server, Ant, DB, iBATIS, Jakarta, Logging, Maven,
Struts, Tomcat, Tapestry,Hadoop, etc. But the most famous is HTTP Server, so now we say
Apache is already the code name of HTTPD Server! We also see more official projects such as Tomcat and Hadoop
Website:
http://www.apache.org/ http://httpd.apache.org

What is Mysql

MySQL is a relational database management system, which is developed by MySQL AB company in Sweden. At present, it belongs to Oracle
Division, he is also the most popular relational database management system! Especially in WEB application!
Relational database: it stores and manages data through a data model composed of data, relationships and constraints on data
According to the official website: http://www.mysql.com/

What is PHP

PHP (foreign name: PHP: Hypertext Preprocessor, Chinese Name: "hypertext preprocessor") is a general open source pin
This language. Syntax absorbs the characteristics of C language, Java and Perl, which is conducive to learning and widely used. It is mainly applicable to the field of Web development.
PHP's unique syntax combines C, Java, Perl and PHP's own syntax.
It can execute dynamic web pages faster than CGI or Perl. Dynamic pages made in PHP are compatible with other programming languages
PHP embeds the program into HTML (an application under the standard General Markup Language) document for execution, which is more efficient than complete
The CGI for generating HTML tags is much higher; PHP can also execute compiled code, which can encrypt and optimize code operation,
Make the code run faster. Simply put, PHP is a script interpreter!
After the PHP server is installed, remember not to upgrade blindly! Because it will discard a lot of inefficient grammar! Official website
Station: http://php.net/

Working principle of LAMP

Working mode and port of Web server

The working mode is B/S mode
The work port is:
Normal port: 80/http
SSL port: 443/https
Install server side: httpd

[root@xuegod63 ~]# yum -y install httpd
[root@xuegod63 ~]# cd /mnt/Packages/
[root@xuegod63 Packages]# ls httpd-*
httpd-2.4.6-67.el7.centos.x86_64.rpm: Apache The main package of the service, which must be installed on the server
httpd-devel-2.4.6-67.el7.centos.x86_64.rpm: Apache Development package
httpd-manual-2.4.6-67.el7.centos.noarch.rpm: Apache Manual documentation, including HTML Formatted
Apache Planned Apache User's Guide Instruction guide
httpd-tools-2.4.6-67.el7.centos.x86_64.rpm: Apache Related Toolkit

After installing many dependent software packages, you will encounter such problems when learning source code compilation and installation. You need to
Manually install the dependent packages before they can be compiled.
Install the browser client under the character interface: elinks
Installation:

[root@xuegod63 Packages]# yum -y install elinks

browser
apache master profile

[root@xuegod63 Packages]# ll /etc/httpd/conf/httpd.conf
[root@xuegod63 Packages]# cd

Start service

[root@xuegod63 ~]# systemctl start httpd
[root@xuegod63 ~]# systemctl enable httpd

View port

[root@xuegod63 Packages]# netstat -anutp | grep 80
tcp 0 0 :::80 :::* LISTEN 3854/httpd

Access via browser
or

[root@xuegod63 ~]# elinks 192.168.1.63 #Press Q to exit

Introduction to master profile

[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" #The root directory of the httpd service
Listen 80 #The listening port defaults to the local ip. If the ip is specified, write IP:80
Include conf.modules.d / *.conf #Conf.modules.in the current directory All conf files in directory D are effective
Options Indexes FollowSymLinks #Options Indexes directory browsing FollowSymLinks browsing with links
AllowOverride None #Set to none, ignore htaccess
Include conf.d / *.conf #The conf file in conf.d is also a valid configuration file
User apache #Run as
Group apache #Run as which group
ServerAdmin root@localhost #Administrator mailbox
DocumentRoot "/var/www/html" #The default home Directory. If you want to change it in two places, the Directory
<Directory "/var/www/html">
Options Indexes FollowSymLinks AllowOverride None
</Directory>
LogLevel warn #Log level
AddDefaultCharset UTF-8 #Supported languages, default encoding

Set up LAMP environment using yum or up2date

LAMP=Linux((present)+Apache(HTTPD (installed)+Mysql+PHP
#centos7
[root@xuegod67~]# yum -y install httpd mariadb mariadb-server php php-mysql

Test database:

[root@xuegod63 ~]# systemctl start mariadb
[root@xuegod63 ~]# systemctl enable mariadb
[root@xuegod63 ~]# mysql #Login test
mysql> show databases;
mysql>exit;

Test whether apache supports php
Create a file:

[root@xuegod63 ~]# cd /var/www/html/
[root@xuegod63 html]# vim index.php
<?php
phpinfo();
?>
[root@xuegod63 html]# systemctl restart httpd

Access view
Similar to PHP probe:
Extension: probe: a file written in PHP, which can view the server hard disk resources, memory occupation, network card traffic and system negative in real time
Load, server time and other information, and refresh it regularly. And include server IP address, Web server environment monitoring, php and other information
Rest.
It is applicable to host operation and maintenance personnel, personal webmaster, etc.

Configure web server - set up LAMP environment

Example 1: build a test web server
Case:
Set up a WEB server within the Department, with the IP address and port of 192.168.1.63:80, and the home page is
index.html file. The E-mail address of the administrator is cd@xuegod.cn , the coding type of the web page is UTF-8, and all web sites are registered
All sources are stored in / var/www/html directory, and the root directory of Apache configuration file is set to / etc/httpd directory.
To modify a profile:

[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf

Set the root directory of Apache to / etc/httpd
Set httpd listening port 80
Set administrator E-mail address to kill@xuegod.cn
Set the host name and listening port of the WEB server to 192.168.1.63:80
Set the Apache document directory to / var/www/html
Set the home page file to index html
Set the default encoding of the server to UTF-8
Before changing the configuration file, back it up for recovery.

[root@xuegod63 ~]# cp /etc/httpd/conf/httpd.conf{,.bak}

Modify configuration file related parameters:

[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf #We need to master the following parameters
31 ServerRoot "/etc/httpd" #The root directory of the Apache configuration file
32 Timeout 60 #Add this item, timeout
42 Listen 80 #Listening port
 Change: 87 ServerAdmin root@localhost
 For: 87 ServerAdmin MK@xuegod.cn #Set administrator, e-mail address
 Change: 96 #ServerName www.example.com:80
 For: 96 ServerName 192.168.1.63:80 #Server host name
120 DocumentRoot "/var/www/html" #Site page root
145 Options Indexes FollowSymLinks #When a directory does not have a default home page, it is allowed
 Show this directory list
 Change: 165 DirectoryIndex index.html
 For: 165 DirectoryIndex index.html index.php #Specify default home page
317 AddDefaultCharset UTF-8 #Set the default code of the server to UTF8

Cancel Apache default welcome page:

[root@xuegod63 ~]# vim /etc/httpd/conf.d/welcome.conf
# This configuration file enables the default "Welcome"
# page if there is no default index page present for
# the root URL. To disable the Welcome page, comment
# out all the lines below.
#
Change: 8 <LocationMatch "^/+$">
 9 Options -Indexes
 10 ErrorDocument 403 /.noindex.html
 11 </LocationMatch>
Is: 8 #<LocationMatch "^/+$"> #Annotate the red content
 9 # Options -Indexes
 10 # ErrorDocument 403 /.noindex.html
 11 #</LocationMatch>

Restart:

[root@xuegod63 ~]# systemctl restart httpd

Create home page:

[root@xuegod63 ~]# echo 'welcome to www.xuegod.cn!' >
/var/www/html/index.html

Test:

Modify web site root - configure alias - Virtual Directory

LAMP environment, implementation of several different security access mechanisms:

Modify the corresponding parameters and permissions of the website directory:

Modify the default root directory of the website and set the access permission. You can access it only within the scope I allow
Create a directory and create a test home page

[root@xuegod63 ~]# mkdir /var/www/html/bbs
[root@xuegod63 ~]# cp /var/www/html/index.html /var/www/html/bbs/

Modify the default root directory of the web site

[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf

Set the document directory to / var/www/html/bbs

modify DocumentRoot The path is the specified directory
 Change: 120 DocumentRoot "/var/www/html"
Is: 120 DocumentRoot "/var/www/html/bbs"
Allow everyone access/var/www/html/bbs catalogue
 Directory and access control:
Change: 132 <Directory "/var/www/html ">
For: 132 <Directory "/var/www/html/bbs"> #Subdirectories inherit the properties of this directory
 145 Options Indexes FollowSymLinks #Options:Indexes: directory browsing
 152 AllowOverride None #Followsymlinks: you can connect with
 Change: 157 Require all granted #Indicates that all access is supported
 For: 157 # Require all granted
#Add the following:
 158 <RequireALL>
 159 Require ip 192.168.1.63 #Allow native IP access
 160 Require not ip 192.168.1.103 #Disable physical machine IP access
 161 </RequireALL>
161 </Directory>


Explanation:

Apache2.4 Access control for:
Require all granted #Allow all
Require all denied #Reject all
Require method http-method [http-method] ... #Allow specific HTTP methods
Require user userid [ userid ] ... #Allow, specific users
Require group group-name [group-name] ... #Allow, specific user groups
Require valid-user #Allow, valid user
Require ip 10 172.20 192.168.2 #Allow specific IP and network segments
Require not ip 10 172.20 192.168.2 #Specific IP and network segments are not allowed
[root@xuegod63 ~]# systemctl restart httpd

test
Access on physical machine http://192.168.1.63

On a Linux host, access:

[root@xuegod63 ~]# curl 192.168.1.63
welcome to www.xuegod.cn!

Use an alias to refer to a path other than the root directory of the website.

Add the / usr/local/phpdata directory to the website root directory through the virtual directory function. When visiting http://192.168.1.63/
When phpdata /, you can access the contents of the directory / usr/local/phpdata.
Note: the alias of Apache is also called virtual directory
Syntax:
Alias URL PATH physical PATH
Create test data:

[root@xuegod63 ~]# mkdir /usr/local/phpdata
[root@xuegod63 ~]# echo "This Alias PHPdata" > /usr/local/phpdata/index.html

To modify a profile:

[root@xuegod63 ~]# vim /etc/httpd/conf/httpd.conf
163 Alias /phpdata/ "/usr/local/phpdata/"
164 <Directory "/usr/local/phpdata/">
165 Options Indexes FollowSymLinks
166 AllowOverride None
167 Require all granted
168 </Directory>
Note: Alias /phpdata/ "/usr/local/phpdata/"
#/Phpdata / can be started at will. For example, if you change / phpdata / to / php /, you can access the link:
http://192.168.1.63/php/
Test:
[root@xuegod63 ~]# systemctl restart httpd
[root@xuegod63 ~]# curl 192.168.1.63/phpdata/
This Alias PHPdata
 Or:
[root@xuegod63 ~]# curl 192.168.1.63/phpdata/index.html
This Alias PHPdata

By the end of this chapter. If you want to know more about technology, there is a small box below the dry goods.

Keywords: Front-end Linux Apache server

Added by eriksmoen on Wed, 05 Jan 2022 07:50:09 +0200