技术流ken

运维拯救世界

DAY14: 课堂记录-Apache和LAMP架构–技术流ken

Apache介绍

 

:80 — 端口 http对应80端口,https对应443端口

 

 

默认发布目录:/var/www/html/

默认发布文件:index.html

默认端口:80

 

200:ok,请求下载成功

304:not modified,标识一个缓存的资源是否发生过更改

 

403:forbidden,表示客户端没有权限访问所请求的资源

404:Not Found,表示客户端所请求的资源不存在

 

500:Internal Server Error,服务器内部错误

502:Bad Gateway,代理服务器从上游服务器获取到的是伪响应

 

编译安装Apache(http)

 

1. 编译安装apr

第一步:上传相关的软件包

[root@ken ~]# ls
apr-1.5.2.tar.gz apr-util-1.5.4.tar.gz httpd-2.4.20.tar.gz

 

第二步:解压

[root@ken ~]# tar xf apr-1.5.2.tar.gz
[root@ken ~]# tar xf apr-util-1.5.4.tar.gz
[root@ken ~]# tar xf httpd-2.4.20.tar.gz

 

第三步:进入安排apr解压目录,进行编译

[root@ken ~]# cd arp- apr-1.5.2

[root@ken apr-1.5.2]# ./configure –prefix=/usr/local/apr

 

第四步:解决依赖

configure: error: no acceptable C compiler found in $PATH   #提示缺少编译器
See `config.log’ for more details
[root@ken apr-1.5.2]# yum install gcc -y

 

第五步:继续编译

[root@ken apr-1.5.2]# ./configure –prefix=/usr/local/apr

 

第六步:安装

[root@ken apr-1.5.2]# make && make install

 

2. 编译安装apr-utils

第一步:进入并开始编译

[root@ken ~]# cd apr-util-1.5.4
[root@ken apr-util-1.5.4]# ls
aprutil.dep buckets config.layout encoding libaprutil.mak NOTICE uri
aprutil.dsp build configure export_vars.sh.in libaprutil.rc NWGNUmakefile xlate
aprutil.dsw buildconf configure.in hooks LICENSE README xml
aprutil.mak build.conf crypto include Makefile.in README.cmake
apr-util.pc.in build-outputs.mk dbd ldap Makefile.win renames_pending
apr-util.spec CHANGES dbm libaprutil.dep memcache strmatch
apu-config.in CMakeLists.txt docs libaprutil.dsp misc test
[root@ken apr-util-1.5.4]# ./configure –with-apr=/usr/local/apr –prefix=/usr/local/apr-util  #需要制定apr位置

 

第二步:编译安装

[root@ken apr-util-1.5.4]# make && make install

 

3. 编译http

第一步:进入解压文件并开始编译

[root@ken httpd-2.4.20]# ./configure –prefix=/usr/local/httpd2.4 –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-cache –enable-deflate –enable-ssl –enable-rewrite –with-mpm=event

 

第二步:解决依赖

 

依赖一:

configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/  #提示缺少pcre
You have new mail in /var/spool/mail/root
[root@ken httpd-2.4.20]# yum install pcre pcre-devel -y

 

依赖二:

checking whether to enable mod_deflate… configure: error: mod_deflate has been requested but can not be built due to prerequisite failures
[root@ken httpd-2.4.20]# yum install openssl openssl-devel -y

 

 

第三步:安装

[root@ken httpd-2.4.20]# make && make install

 

编译安装的apache常用操作

 

在任何路径下执行apachectl:

 

[root@ken bin]# cat /etc/profile.d/httpd.sh
export PATH=/usr/local/httpd2.4/bin:$PATH
[root@ken bin]# export /etc/profile.d/httpd.sh
-bash: export: `/etc/profile.d/httpd.sh’: not a valid identifier
[root@ken bin]# source /etc/profile.d/httpd.sh

 

验证操作:

[root@ken bin]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@ken bin]# cd
[root@ken ~]# pwd
/root
[root@ken ~]# apachectl stop
[root@ken ~]# ss -tnl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:111 *:*
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::111 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*

 

apache配置文件常用参数

 

Listen 80
User apache

Group apache
DocumentRoot “/var/www/html”
DirectoryIndex index.html

 

基于端口创建虚拟主机

 

第一步:修改配置文件

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

<VirtualHost *:81>
DOCUMENTROOT /var/www/ken1
DIRECTORYINDEX index.html
</VirtualHost>

<VirtualHost *:82>
DOCUMENTROOT /var/www/ken2
DIRECTORYINDEX index.html
</VirtualHost>

Listen 80
Listen 81
Listen 82

 

第二步:创建网站根目录

[root@ken ~]# mkdir /var/www/ken{1,2}

 

第三步:创建网页首页文件

[root@ken ~]# echo “111” >> /var/www/ken1/index.html
[root@ken ~]# echo “222” >> /var/www/ken2/index.html

 

第四步:重启apache

[root@ken ~]# systemctl restart httpd

 

第五步:linux中访问

[root@ken ~]# curl 192.168.64.4:81
111
[root@ken ~]# curl 192.168.64.4:82
222

 

基于域名创建虚拟主机

 

第一步:修改配置文件

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

<VirtualHost 192.168.64.4>
DOCUMENTROOT /var/www/ken1
DIRECTORYINDEX index.html
servername www.ken1.com
</VirtualHost>

<VirtualHost 192.168.64.4>
DOCUMENTROOT /var/www/ken2
DIRECTORYINDEX index.html
servername www.ken2.com
</VirtualHost>

 

第二步:创建网站根目录

[root@ken ~]# mkdir /var/www/ken{1,2}

 

第三步:创建网页首页文件

[root@ken ~]# echo “111” >> /var/www/ken1/index.html
[root@ken ~]# echo “222” >> /var/www/ken2/index.html

 

第四步:重启apache

[root@ken ~]# systemctl restart httpd

 

第五步:解析域名

[root@ken www]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.64.4 www.ken1.com www.ken2.com

 

第六步:linux中访问

[root@ken www]# curl www.ken1.com
111
[root@ken www]# curl www.ken2.com
222

 

第七步:window中访问

修改window  hosts文件

 

 

apache上线静态网站

 

第一步:关防火墙

[root@ken www]# systemctl stop firewalld
[root@ken www]# setenforce 0

 

第二步:上传京东静态页面至网站根目录

[root@ken html]# rz

[root@ken html]# ls
jd.zip
[root@ken html]# unzip jd.zip   #需要yum install unzip -y

 

第三步:访问京东网页

 

apache上线动态网站

 

第一步:需要先部署LAMP架构

[root@ken jd]# yum install httpd php php-mysql mariadb-server -y

 

第二步:启动apache和数据库

[root@ken jd]# systemctl restart httpd mariadb

 

第三步:上传安装包并解压

[root@ken html]# ls
wordpress-3.3.1-zh_CN.zip
[root@ken html]# unzip wordpress-3.3.1-zh_CN.zip

 

第四步:复制wordpress文件到本目录下

 

[root@ken html]# cp wordpress/* . -a
[root@ken html]# ls
index.php wordpress-3.3.1-zh_CN.zip wp-blog-header.php wp-cron.php wp-login.php wp-settings.php
license.txt wp-activate.php wp-comments-post.php wp-includes wp-mail.php wp-signup.php
readme.html wp-admin wp-config-sample.php wp-links-opml.php wp-pass.php wp-trackback.php
wordpress wp-app.php wp-content wp-load.php wp-register.php xmlrpc.php

 

第五步:配置数据库文件

[root@ken html]# cp wp-config-sample.php wp-config.php
[root@ken html]# vim wp-config.php

/** WordPress 数据库的名称 */
define(‘DB_NAME’, ‘ken’);

/** MySQL 数据库用户名 */
define(‘DB_USER’, ‘ken’);

/** MySQL 数据库密码 */
define(‘DB_PASSWORD’, ‘123’);

 

第六步:配置数据库

[root@ken html]# mysql -uroot
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]> create database ken;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> grant all on *.* to ken@’localhost’ identified by ‘123’;
Query OK, 0 rows affected (0.01 sec)

MariaDB [(none)]> exit
Bye

 

第七步:访问网站

48 thoughts on “DAY14: 课堂记录-Apache和LAMP架构–技术流ken

  1. Normally I do not read article on blogs, however I would like to say that this write-up
    very pressured me to take a look at and do it!
    Your writing taste has been amazed me. Thank you, quite nice article.

  2. Hello there, just became aware of your blog through
    Google, and found that it is really informative. I’m gonna watch out for brussels.
    I’ll be grateful if you continue this in future. Numerous people will be benefited from your writing.
    Cheers!

  3. I was recommended this blog by my cousin. I am not sure whether
    this post is written by him as no one else know such detailed about my
    problem. You are incredible! Thanks!

  4. This design is incredible! You certainly know how to
    keep a reader amused. Between your wit and your videos,
    I was almost moved to start my own blog (well,
    almost…HaHa!) Excellent job. I really enjoyed what you had to
    say, and more than that, how you presented it. Too cool!
    adreamoftrains web hosting reviews

发表评论

电子邮件地址不会被公开。