Linux website service

1. Concept

foreword

UI Transformation: B/S Architecture

Web Server

Nginx (Tengine) 、 Apache 、 IIS

static element

.html .img  .css  .swf  .mp4

dynamic element

.php .jsp .cgi .asp  SQL

Web middleware

php: PHP-fpm、HHVM
jsp: Tomcat、JBOSS、Resin、IBM WebSphere

common combination

LNMP (Linux + Nginx + MySQL + PHP) //php-fpm process
LAMP (Linux + Apache + MySQL + PHP) //php as Apache's module
Nginx + Tomcat //replace Apache and Tomcat combined, java

Second, the static site

Apache

It is recommended to use version 2.4 and above



Apache Basics

Apache: www.apache.org
package: httpd
service port: 80/tcp(http) 443/tcp(https,http+ssl)
configuration file: /etc/httpd/conf/httpd.conf
/etc/httpd/conf. d/*.conf
/etc/httpd/conf.d/welcome.conf //default test page

Install Apache

[root@apache ~]# yum -y install httpd
[root@apache ~]# systemctl start httpd
[root@apache ~]# systemctl enable httpd

web hosting

Purpose

Virtual Host VirtualHost
role: run multiple websites on one physical server

Types of

based on hostname
based on IP address
based on port number

Configure virtual hosts

Implement the following website:
www.a.org /var/www/html/a.org     
www.b.org /b.org
Note that firewalld and selinux are turned off

www.a.org

# mkdir /var/www/html/a.org
# vim /var/www/html/a.org/index.html

create a.org configuration file
# vim /etc/httpd/conf.d/a.org. conf <VirtualHost * :
80>
   ServerName www.a.org
   DocumentRoot /var/www/html/a.org
</VirtualHost>

Check the configuration file syntax, restart the service
# httpd -t
# systemctl restart httpd

Build DNS, you can also resolve the HOSTs file.
Test: yum install -y elinks
elink www.a.org

www.b.org

# mkdir /b.org
# vim /b.org/index.html

Create b.org configuration file
# vim /etc/httpd/conf.d/b.org.conf
<VirtualHost *:80>
   ServerName www.b. org
   DocumentRoot /b.org
</VirtualHost>

<Directory "/b.org">
   Require all granted
</Directory>
 
Check the configuration file syntax, restart the service
# httpd -t
# systemctl restart httpd

Note: Domain name resolution. www.b.org
test: yum install -y elinks
        elink www.b.org

Three, dynamic site

1, HttpServer: (test LAMP)

First install Apache same as above static site

1.1 Apache Basics

Apache: www.apache.org
package: httpd
service port: 80/tcp(http) 443/tcp(https,http+ssl)
configuration file: /etc/httpd/conf/httpd.conf
/etc/httpd/conf. d/*.conf
/etc/httpd/conf.d/welcome.conf //default test page

1.2 Install Apache

[root@apache ~]# yum -y install httpd
[root@apache ~]# systemctl start httpd
[root@apache ~]# systemctl enable httpd

1.3 Firewall

[root@apache ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@apache ~]# setenforce 0
[root@apache ~]# firewall-cmd --permanent --add-service=http
[root@apache ~]# firewall-cmd --permanent --add-service=https
[root@apache ~]# firewall-cmd --reload

1.5 Create a test page for the main directory of the website

1 Create a static page.
[root@apache ~]# vim /var/www/html/index.html
1702test
Please observe whether the test is successful.

2 Create dynamic pages.
[root@apache ~]# vim /var/www/html/2.php
<?php
phpinfo();
?>
Please observe whether the test is successful, NO (need to install php)

1.6 Install php

The reason why the test was unsuccessful. It's because no one parses dynamic languages.
[root@apache ~]# yum -y install php //php as a module of Apache

Observe the result after installation.
[root@apache ~]# ll /etc/httpd/modules/libphp5.so
-rwxr-xr-x. 1 root root 4588368 Jun 24 2015 /etc/httpd/modules/libphp5.so
[root@apache ~]# ll /etc/httpd/conf.d/php.conf
-rw-r--r--. 1 root root 691 Jun 24 2015 /etc/httpd/conf.d/php.conf
Restart the website program. Mobilize the php module
[root@apache ~]# systemctl restart httpd

Please refresh the page again. See below. The PHP language was parsed successfully.


Please think. Where is the data queried by PHP stored?
Answer: In the database.

1.7 Install the database (mysql/Mariadb)

[root@apache ~]# yum -y install mariadb-server mariadb
[root@apache ~]# systemctl start mariadb.service
[root@apache ~]# systemctl enable mariadb.service to

enhance mysql.
[root@apache ~]# mysql_secure_installation //Improve mariadb security [optional]
Set root password? [Y/n]
New password: 123
Re-enter new password: 123
Manually test the account password.
[root@apache ~]# mysql -uroot -p123 //Log in to mariadb to test
MariaDB [(none)]> \q

[root@apache ~]# rm -rf /var/www/html/*
[root@apache ~] # vim /var/www/html/2.php
<?php
$link=mysql_connect('localhost','root','123');
if ($link)
echo "Successfuly";
else
echo "Faile";
mysql_close ();
?>

Please think. Whether the database can be connected successfully.
Test result: php cannot connect to mysql. Because of the lack of tools for php to connect to mysql

1.8 Configure php-mysql to connect to Mariadb

Configure php to connect to Mariadb
[root@apache ~]# yum -y install php-mysql
[root@apache ~]# php -m //See what extensions php has
[PHP Modules]
mysql
mysqli
[root@apache ~]# systemctl restart httpd

1.9 Apache basic configuration


[root@tianyun ~]# vim /etc/httpd/conf/httpd.conf
ServerRoot "/etc/httpd" //Installation directory
Listen 80 //Listening port
IncludeOptional conf.d/*.conf //Include under conf.d *.conf file
User apache //User
group running Apache Group apache //User group running Apache
DirectoryIndex index.html index.php //Set the default home page, use one.
DocumentRoot //Site default home directory

2.0 MPM optimization (interview questions)

# prefork MPM //Process mode (stable)
<IfModule prefork.c>
StartServers 6 //Number of initial processes
MinSpareServers 6 //Minimum number of idle processes
MaxSpareServers 15 //Maximum number of idle processes
ServerLimit 2000 //Maximum startup The default number of processes is 256
MaxClients 2000 //The maximum number of concurrent connections defaults to 256
MaxRequestsPerChild 4000 //The maximum number of requests each child process is allowed to respond to within its life cycle, 0 does not limit
</IfModule>

# worker MPM //Thread mode (efficient)
<IfModule worker.c>
StartServers 2 //The number of initially created processes
ThreadsPerChild 50 //The number of threads created by each process
MinSpareThreads 100 //The minimum number of idle threads
MaxSpareThreads 200 //The number of threads in the largest space
MaxClients 2000 //The largest Concurrent access (thread)
MaxRequestsPerChild 0 //The maximum number of requests that each child process is allowed to respond to during its life cycle, 0 does not limit
</IfModule>
icon

2. Deploy the online store ecshop

download logo

2.1 Basic Environment

一,基础环境
[root@apache ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@apache ~]# setenforce 0
[root@apache ~]# systemctl stop firewalld.service
[root@apache ~]# systemctl disable firewalld.service

2.2 Install LAMP

二、安装LAMP
[root@apache ~]# yum -y install httpd mariadb-server mariadb php php-mysql gd php-gd
[root@apache ~]# systemctl start httpd mariadb
[root@apache ~]# systemctl enable httpd mariadb
[root@apache ~]# mysqladmin -u root password "123"

2.3 Install Ecshop

2.3.1 Upload site source package

1. Apache configuration virtual host
[root@apache ~]# vim /etc/httpd/conf.d/zhufo.conf

 httpd -t httpd configuration file syntax detection
[root@apache ~]# systemctl restart httpd

2. Import the source code of the ecshop website
[root@apache ~]# mkdir -p /webroot/zhufo
[root@apache ~]# unzip ECShop_V3.0.0_UTF8_release0518.zip
[root@apache ~]# cp -rf ECShop_V3.0.0_UTF8_release0518/* /webroot/zhufo/

3. Install ecshop [any client]
[root@tianyun ~]# vim /etc/hosts //If DNS is not used to resolve
192.168.122.161 www.zhufo.top zhufo.top //161 is the web server IP

2.3.2 Front-end installation source package


[root@apache ~]# chmod -R 777 /webroot/zhufo/



Modify php.ini time zone

[root@apache ~]# vim /etc/php.ini


[root@apache ~]# systemctl restart httpd


3. Deploy the blog system wordpress

Logo

 

3.1 Basic Environment [Completed]

1. Basic environment [completed]
[root@apache ~]# sed -ri '/^SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@apache ~]# setenforce 0
[root@apache ~]# systemctl stop firewalld.service
[root@apache ~]# systemctl disable firewalld.service

3.2 Install LAMP [Completed]

二、安装LAMP[已完成]
[root@apache ~]# yum -y install httpd mariadb-server mariadb php php-mysql gd php-gd
[root@apache ~]# systemctl start httpd mariadb
[root@apache ~]# systemctl enable httpd mariadb
[root@apache ~]# mysql_secure_installation

3.3 Install Ecshop

3.3.1 Apache configuration virtual host

1. Apache configuration virtual host
[root@apache ~]# vim /etc/httpd/conf.d/tianyun.conf

[root@apache ~]# systemctl restart httpd

3.3.2 Import wordpress website source code

2. Import the source code of the wordpress website
[root@apache ~]# mkdir -p /webroot/tianyun
[root@apache ~]# tar xf wordpress-4.5.3-zh_CN.tar.gz
[root@apache ~]# cp -rf wordpress/* /webroot/tianyun/

3.3.3 Prepare the database (create a library)


3.3.4 Install wordpress [any client]

4. Install wordpress [any client]
[root@tianyun ~]# vim /etc/hosts
192.168.122.161 www.zhufo.top zhufo.top www.tianyun.com tianyun.com //161 is the web server IP


chmod -R 777 /webroot/tianyun



4, Apache access control

Prepare the environment
[root@aliyun ~]# rm -rf /var/www/edusoho/web/download/*
[root@aliyun ~]# echo "download....." > /var/www/edusoho/web/ download/index.html
is only for http 2.4+

Case 1: Allow all hosts to access
<Directory "/var/www/edusoho/web/download">
AllowOverride None
Require all granted
</Directory>

AllowOverride All Allow settings in .htaccess in subdirectories to override current settings
AllowOverride None Not allowed Settings in .htaccess in subdirectories override current settings
    Require all denied


Case 2: Only allow network segments 192.168.5.0/24, 192.168.10.0/24 to access
<Directory "/var/www/edusoho/web/download">
AllowOverride None
Require ip 202.106.0.0/24
Require ip 114.248.160.203
</ Directory>

Case 3: Deny access only to certain hosts
<Directory "/var/www/edusoho/web/download">
AllowOverride None
<RequireAll>
Require not ip 114.248.160.203
Require all granted
</RequireAll>
</Directory>

Case 4: For File access control 4
Do not allow execution of .php files in /var/www/edusoho/web/upload directory
<Directory /webroot/baidu/upload>
AllowOverride None
Require all granted

<Files ~ "\.php$" >
Order allow ,deny
Deny from all
</Files>
</Directory>







Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326559590&siteId=291194637