●开放源代码、跨平台应用
● 支持多种网页编程语言
● 模块化设计、运行稳定、良好的安全性
■软件版本
● 1.X
◆ 目前最高版本是1.3,运行稳定
◆ 向下兼容性较好,但缺乏一些较新的功能
●2.X
◆目前最高版本是2.4
◆具有更多的功能特性
◆与1.X相比,配置管理风格存在较大差异
编译安装的优点
● 具有较大的自由度,功能可定制
●可及时获得最新的软件版本
●普遍适用于大多数Linux版本,便于移植使用获得Apache服务器的源码包
参考地址∶http∶/httpd.apache.org/download.cgi
●卸载httpd及相关依赖包
[root@localhos~]# rpm -e httpd-nodeps
[root@localhos~]# yum install-y apr-util-devel pcre-devel
1.3.2.源码编译及安装
[root@localhost~]# tar zxf httpd-2.4.25.tar.gz-C /usr/src
[root@localhos~]# cd /usr/src/httpd-2.4.25/
[root@localhos httpd-2.4.25]#/configure -prefix=/usr/local/httpd --enable-so --enable-rewrite --enable-charset-lite --enable-cgil
[[email protected]]#make && make install
-C指定解压缩位置
enable-so 开启核心功能模块
enable-rewrite 用于做防盗链
enable-charset指定字符集
enable-cgi 开启通用网关接口
[root@localhost~]# ls /usr/local/httpd bin cgi-bin error icons logs manual build conf htdocs include man modules
[root@localhost~]# In -s /usr/local/httpd/bin/* /usr/local/bin
[root@localhost ~]# ls - /usr/local/bin/httpd /usr/local/bin/apachectl Irwxrwxrwx 1 root root 305月10 06∶20 /usr/local/bin/apachectl->/usr/local/httpd/bin/apachectl
Irwxrwxrwx 1 root root 265月10 06∶20/usr/local/bin/httpd->/usr/local/httpd/bin/httpd
● 通过systemctl进行管理系统服务
[root@localhost~]# vim lib/systemd/system/httpd.service [Unit]
Description=The Apache HTTP Server After=network.target [Service]Type=forking
PIDFile=/usr/local/httpd/logs/httpd.pid ExecStart=/usr/local/bin/apachectI $OPTIONS ExecReload=/bin/kill-HUP $MAINPID KilMode=process Restart=on-failure RetartSec=42s [Install]
WantedBy=graphical.target
服务目录∶/usr/local/httpd/
●主配置文件∶/usr/local/httpd/conf/httpd.conf
●网页目录∶/usr/local/httpd/htdocs/
●服务脚本∶/usr/local/httpd/bin/apachectl
●执行程序∶/usr/local/httpd/bin/httpd 用于验证启动文件语法
●访问日志∶/usr/local/httpd/log/access_log
●错误日志∶/usr/local/httpd/log/error log
1确定网站名字、IP地址
2.配置并启动httpd服务
root@localhost~]#vim /usr/local/httpd/conf/httpd.conf ServerName www.kgc.com
[root@localhost~]#/usr/local/httpd/bin/apachectl-t Syntax OK
[root@localhost~]#systemctl restart httpd
决定httpd服务器的全局运行参数
ServerRoot "/usr/local/
httpd"Listen 80
User daemon Group daemon
ServerAdmin [email protected]
ServerName www.kgc.com
DocumentRoot "/usr/locaW/httpd/htdocs"
DirectorylIndex index.html index.php ErrorLog logs/error_log
LogLevel warn
CustomLog logs/access log common PidFile logs/httpd.pid
CharsetDefault UTF-8
Include conf/extra/httpd-default.conf ···
●ServerRoot∶服务目录
●Listen∶监听的IP地址、端口号User∶运行服务的用户身份
●Group∶运行服务的组身份
●ServerAdmin∶管理员邮箱
●ServerName∶网站服务器的域名
●DocumentRoot∶网页文档的根目录
●DirectorylIndex∶默认的索引页文件
●ErrorLog:设置错误日志文件的路径
●Loglevel∶记录日志的级别,默认为warn
● CustomLog∶访问日志文件的位置
●PidFile∶保存httpd进程PID号的文件
●AddDefaultCharset∶设置站点中网页默认的字符集编码
●Timeout∶网络连接超时,默认为300秒
● KeepAlive∶是否保持连接,可选On或Off
●MaxKeepAliveRequests∶每次连接最多请求文件数
●KeepAlive Timeout∶保持连接状态时的超时时间
● Include∶需要包含进来的其他配置文件
ServerRoot"/Jusrlocal/httpd"
Listen 80
User daemon Group daemon
ServerAdmin [email protected]
ServerName www.kgc.com
DocumentRoot"/usr/local/httpd/htdocs"
Directorylndex index.html index.php
ErrorLOg logS/eTOT log
LoglLevel warn
CustomLog logs/access log common
PidFile logs/httpd.pid
CharsetDefault UTF-8 支持中文简体
Include conf/extra/httpd-default.conf ··..·
●使用一对组合标记,限定了配置项的作用范围
Options FollowSymLinks AllowOverride none
Require all denied 可以设置黑白名单,账写验证
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
[root@localhost ~]# cd /opt
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# rz -E
rz waiting to receive.
[root@localhost opt]# mkdir apache mysql php 创建apache mysql php目录
[root@localhost opt]# ls
apache apr-util-1.6.0.tar.gz mysql rh
apr-1.6.2.tar.gz httpd-2.4.29.tar.bz2 php wangwu
[root@localhost opt]# tar zxvf apr-util-1.6.0.tar.gz -C apache/
[root@localhost opt]# tar zxvf apr-1.6.2.tar.gz -C apache/
[root@localhost opt]# tar jxvf httpd-2.4.29.tar.bz2 -C apache/
[root@localhost apache]# ls 查看
apr-1.6.2 apr-util-1.6.0 httpd-2.4.29
[root@localhost apache]# mv apr-util-1.6.0 httpd-2.4.29/srclib/apr-util
[root@localhost apache]# mv apr-1.6.2 httpd-2.4.29/srclib/apr
[root@localhost srclib]# ls
apr apr-util Makefile.in
[root@localhost apache]# yum -y install\
> gcc\
> gcc-c++\
> make\
> pcre-devel\
> expat-devel\
> perl
[root@localhost apache]# ls
expat-devel gcc gcc-c++ httpd-2.4.29 make pcre-devel perl
[root@localhost httpd-2.4.29]# ./configure \
–prefix=/usr/local/httpd
–enable-so
–enable-rewrite
–enable-charset-lite
–enable-cgi
[root@localhost httpd-2.4.29]#make && make install
[root@localhost httpd-2.4.29]# cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd //把启动脚本放在/etc/init.d下重命名为httpd
[root@localhost httpd-2.4.29]# cd /etc/init.d/
[root@localhost init.d]# ls 查看
functions httpd netconsole network README
[root@localhost init.d]# vim httpd
\#!/bin/sh '//在行首插入下两行内容
chkconfig: 35 85 21 '//35级别自动运行 第85个启动 第21个关闭'
description: Apache is a World Wide Web server
……省略内容
[root@localhost init.d]# chkconfig --add httpd //将httpd加入到SERVICE管理器
创建http.conf配置文件的软连接到/etc下面 就可以直接边界配置文件,比较方
[root@localhost init.d]# ln -s /usr/local/httpd/conf/httpd.conf /etc/httpd.conf
[root@localhost init.d]# ln -s /usr/local/httpd/bin/* /usr/local/bin/
[root@localhost init.d]# ls /usr/local/httpd/bin/
ab apxs envvars-std htdigest logresolve
apachectl checkgid fcgistarter htpasswd rotatelogs
apr-1-config dbmmanage htcacheclean httpd
apu-1-config envvars htdbm httxt2dbm
[root@localhost ~]# httpd -t 验证语法格式
Syntax OK
[root@localhost ~]# service httpd start
[root@localhost ~]# netstat -ntap |grep 80
tcp 0 0 14.0.0.14:80 0.0.0.0:* LISTEN 61275/httpd
//切换到opt/mysql
[root@localhost ~]# cd /opt/mysql/
//把软件包复制到目录底下
[root@localhost mysql]# rz -E
rz waiting to receive.
//查看软件包
[root@localhost mysql]# ls
mysql-5.6.26.tar.gz
//ncurses-devel是字符终端下的基本库
//autoconf生成可以自动配置软件源代码
//cmake跨平台编译安装工具
[root@localhost mysql]# yum install ncurses-devel autoconf cmake -y
//解压缩
[root@localhost mysql]# tar zxvf mysql-5.6.26.tar.gz
[root@localhost mysql]# ls
mysql-5.6.26 mysql-5.6.26.tar.gz
[root@localhost mysql]# cd mysql-5.6.26/
[root@localhost mysql-5.6.26]# ls
BUILD Doxyfile-perfschema mysys strings
BUILD-CMAKE extra mysys_ssl support-files
client include packaging tests
cmake INSTALL-SOURCE plugin unittest
CMakeLists.txt INSTALL-WIN-SOURCE README VERSION
cmd-line-utils libevent regex vio
config.h.cmake libmysql scripts win
configure.cmake libmysqld sql zlib
COPYING libservices sql-bench
dbug man sql-common
Docs mysql-test storage
//cmake已经有了
[root@localhost mysql-5.6.26]# cmake \ > -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ '//指定路径' > -DDEFAULT_CHARSET=utf8 \ '//指定字符集' > -DDEFAULT_COLLATION=utf8_general_ci \ '//指定字符集' > -DEXTRA_CHARSETS=all \ '//指定字符集' > -DSYSCONFIDIR=/etc \ '//指定配置文件目录' > -DMYSQL_DATADIR=/home/mysql/ \ '//指定数据文件目录,由mysql用户管理' > -DMYSQL_UNIX_ADDR=/home/mysql/mysql.sock '//指定通信文件,连接数据库的必要文件' > ...省略内容3.3编译安装
[root@localhost mysql-5.6.26]# make && make install
[root@localhost mysql-5.6.26]# cp support-files/my-default.cnf /etc/my.cnf cp: overwrite ‘/etc/my.cnf’? y [root@localhost mysql-5.6.26]# cp support-files/mysql.server /etc/init.d/mysqld
[root@localhost mysql-5.6.26]# cd /etc/init.d/
[root@localhost init.d]# ls
functions httpd mysqld netconsole network README
[root@localhost init.d]# ls -l
total 56 '//发现mysqld文件没有执行权限'
[root@localhost init.d]# chmod +x mysqld
[root@localhost init.d]# ls -l
总用量 56
-rw-r--r--. 1 root root 18281 8月 24 2018 functions
-rwxr-xr-x. 1 root root 3498 8月 3 20:03 httpd
-rwxr-xr-x. 1 root root 10870 8月 4 01:52 mysqld
-rwxr-xr-x. 1 root root 4569 8月 24 2018 netconsole
-rwxr-xr-x. 1 root root 7923 8月 24 2018 network
-rw-r--r--. 1 root root 1160 10月 31 2018 README
[root@localhost init.d]# chkconfig --add /etc/init.d/mysqld '//将mysqld添加到service服务器中'
[root@localhost init.d]# chkconfig --level 35 mysqld on '//设置mysqld在运行级别3和5都是开启的'
[root@localhost init.d]# echo "PATH=$PATH:/usr/local/mysql/bin">> /etc/profile '//设置mysql命令到/etc/profile中寻找'
[root@localhost init.d]# source /etc/profile '//使命令不需重启立即生效'
[root@localhost init.d]# echo $PATH '//查看环境'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/mysql/bin
echo “PATH=$PATH:/usr/local/mysql/bin”>> /etc/profile 与vim /etc/profile 在配置文件末尾添加如下功能一样
[root@localhost init.d]# useradd -s /sbin/nologin mysql ‘//添加用户,指定shell,禁止用户登录系统’
[root@localhost init.d]# id mysql
uid=1001(mysql) gid=1001(mysql) groups=1001(mysql)
[root@localhost init.d]# chown -R mysql.mysql /usr/local/mysql ‘//设置属主和数组’
[root@localhost local]# cd /usr/local/mysql/
[root@localhost init.d]# /usr/local/mysql/scripts/mysql_install_db \
> --user=mysql \
> --ldata=/var/lib/mysql \
> --basedir=/usr/local/mysql \
> --datadir=/home/mysql
[root@localhost mysql]# vim /etc/init.d/mysqld
'//搜索basedir'
...省略内容
'//修改这两段内容'
basedir=/usr/local/mysql '//添加工作路径'
datadir=/home/mysql '//添加数据路径'
...省略内容
[root@localhost init.d]# service mysqld start
Starting MySQL.. SUCCESS!
[root@localhost init.d]# netstat -ntap|grep 3306
tcp6 0 0 :::3306 :::* LISTEN 87565/mysqld
[root@localhost init.d]# mysqladmin -u root -p password "abc123" '//给root用户设置密码'
'//mysqladmin -u用户名 -p旧密码 password 新密码'
Enter password: '//原本密码为空,直接回车即可'
Warning: Using a password on the command line interface can be insecure.
[[email protected]]# mysql -u root -p
Enter password: '//输入刚设置的密码abc123'
...省略内容
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> exit
Bye
[root@localhost ~]# yum -y install gd libpng libpng-devel pcre prce-devel libxml2-devel libjpeg-devel
[root@localhost scripts]# cd /opt
[root@localhost opt]# ls
apache mysql php rh
[root@localhost opt]# cd php/
[root@localhost php]# ls
[root@localhost php]# rz -E #把压缩包复制过来
rz waiting to receive.
[root@localhost php]# ls #已经有了
php-5.6.11.tar.bz2
[root@localhost php]# tar jxvf php-5.6.11.tar.bz2 解压
[root@localhost php]# ls
php-5.6.11 php-5.6.11.tar.bz2
查看是否有configure
[root@localhost php-5.6.11]# ls
acinclude.m4 php.ini-production
aclocal.m4 README.EXT_SKEL
build README.GIT-RULES
buildconf README.input_filter
buildconf.bat README.MAILINGLIST_RULES
CODING_STANDARDS README.md
config.guess README.namespaces
config.sub README.NEW-OUTPUT-API
configure README.PARAMETER_PARSING_API
configure.in README.REDIST.BINS
…………
[root@localhost php-5.6.11]# ./configure \
> --prefix=/usr/local/php5 \ #PHP的安装目录
> --with-gd \ #GD库
> --with-zlib \ #压缩函数库
> --with-apxs2=/usr/local/httpd/bin/apxs \ #设置Apache服务提供的apxs模块支持程序的文件位置
> --with-mysql=/usr/local/mysql \ #设置MySQL数据库服务程序的安装位置
> --with-config-file-path=/usr/local/php5 \ #PHP配置文件的位置
> --enable-mbstring #启用对字节字符串功能,便于支持中文等代码
[root@localhost php-5.6.11]# make && make install
//移动启动脚本到安装目录下
[root@localhost php-5.6.11]# cp php.ini-development /usr/local/php5/php.ini
//创建软链接让bin里面一些命令让系统所识别
[root@localhost php-5.6.11]# ln -s /usr/local/php5/bin/* /usr/local/bin/
//让apache支持PHP
[root@localhost php-5.6.11]# vim /etc/httpd.conf
[root@localhost php-5.6.11]# service httpd stop
[root@localhost php-5.6.11]# service httpd start
[root@localhost php-5.6.11]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
index.html
[root@localhost htdocs]# vim index.html
[root@localhost htdocs]# mv index.html index.php
[root@localhost htdocs]# ls
index.php
[root@localhost htdocs]# vim index.html
~
[root@localhost mysql]# cd /opt
[root@localhost opt]# ls
apache mysql php rh
[root@localhost opt]# rz -E //论坛安装包直接复制过来
rz waiting to receive.
[root@localhost opt]# ls //查看一下
apache Discuz_X2.5_SC_UTF8.zip mysql php rh
[root@localhost opt]# unzip Discuz_X2.5_SC_UTF8.zip //解压缩
t@localhost opt]# ls
apache mysql readme upload
Discuz_X2.5_SC_UTF8.zip php rh utility
[root@localhost opt]# cp -r upload/ /usr/local/httpd/htdocs/bbs //把upload复制到apache工作目录站点
[root@localhost opt]# cd /usr/local/httpd/htdocs/
[root@localhost htdocs]# ls
bbs index.php
[root@localhost htdocs]# ls bbs/ //查看bbs目录
admin.php crossdomain.xml install source
api data member.php static
api.php favicon.ico misc.php template
archiver forum.php plugin.php uc_client
config group.php portal.php uc_server
connect.php home.php robots.txt userapp.php
cp.php index.php search.php
[root@localhost bbs]# ll
总用量 76
-rw-r--r--. 1 root root 2603 8月 4 08:46 admin.php
drwxr-xr-x. 11 root root 163 8月 4 08:46 api
-rw-r--r--. 1 root root 727 8月 4 08:46 api.php
drwxr-xr-x. 2 root root 23 8月 4 08:46 archiver
drwxr-xr-x. 2 root root 90 8月 4 08:46 config
-rw-r--r--. 1 root root 922 8月 4 08:46 connect.php
-rw-r--r--. 1 root root 253 8月 4 08:46 cp.php
-rw-r--r--. 1 root root 106 8月 4 08:46 crossdomain.xml
drwxr-xr-x. 13 root root 216 8月 4 08:46 data
-rw-r--r--. 1 root root 5558 8月 4 08:46 favicon.ico
-rw-r--r--. 1 root root 2110 8月 4 08:46 forum.php
-rw-r--r--. 1 root root 823 8月 4 08:46 group.php
-rw-r--r--. 1 root root 1223 8月 4 08:46 home.php
-rw-r--r--. 1 root root 5448 8月 4 08:46 index.php
drwxr-xr-x. 5 root root 64 8月 4 08:46 install
-rw-r--r--. 1 root root 1040 8月 4 08:46 member.php
-rw-r--r--. 1 root root 1381 8月 4 08:46 misc.php
-rw-r--r--. 1 root root 1757 8月 4 08:46 plugin.php
-rw-r--r--. 1 root root 985 8月 4 08:46 portal.php
-rw-r--r--. 1 root root 582 8月 4 08:46 robots.txt
-rw-r--r--. 1 root root 1158 8月 4 08:46 search.php
drwxr-xr-x. 10 root root 168 8月 4 08:46 source
drwxr-xr-x. 6 root root 72 8月 4 08:46 static
drwxr-xr-x. 3 root root 38 8月 4 08:46 template
drwxr-xr-x. 6 root root 92 8月 4 08:46 uc_client
drwxr-xr-x. 13 root root 241 8月 4 08:46 uc_server
-rw-r--r--. 1 root root 1691 8月 4 08:46 userapp.php
[root@localhost bbs]# chown -R daemon ./config/
[root@localhost bbs]# chown -R daemon ./data/
[root@localhost bbs]# chown -R daemon ./uc_client/
[root@localhost bbs]# chown -R daemon ./uc_server/
[root@localhost bbs]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.26 Source distribution
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
mysql> create database bbs;创建bbs数据库
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| test |
+--------------------+
5 rows in set (0.01 sec)
mysql> grant all on bbs.* to 'bbsuser'@'%' identified by 'admin123';授权密码
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;刷新
Query OK, 0 rows affected (0.00 sec)
网页安装
1)
2)
hema |
| test |
±-------------------+
4 rows in set (0.00 sec)
mysql> create database bbs;创建bbs数据库
Query OK, 1 row affected (0.00 sec)
mysql> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| bbs |
| mysql |
| performance_schema |
| test |
±-------------------+
5 rows in set (0.01 sec)
mysql> grant all on bbs.* to ‘bbsuser’@’%’ identified by ‘admin123’;授权密码
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;刷新
Query OK, 0 rows affected (0.00 sec)
网页安装
1)
[外链图片转存中...(img-nHCUfLNL-1596514875176)]
2)
[外链图片转存中...(img-zWHk0j5O-1596514875176)]
3)[外链图片转存中...(img-1t7r2VE1-1596514875178)]
[外链图片转存中...(img-rpTFB1r2-1596514875178)]