centOS7_x64 + Httpd 2.4.27 + Mysql 5.7.18 + Php 7.1.9
一、首先,部署apache
0x01 关于centOS7的安装就不细说了,依然是最小化安装,只勾选必要的系统库及常用工具,务必记得先禁用selinux和系统防火墙,此次部署环境软件包如下:1
2
3
4
5
6
7apr-1.6.2.tar.gz
apr-util-1.6.0.tar.gz
cronolog-1.6.2.tar.gz
httpd-2.4.27.tar.gz
libiconv-1.14.tar.gz
mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
php-7.1.9.tar.gz
要实现的架构大致如下:1
centOS7_x64 + httpd 2.4.27 + mysql 5.7.18 + php 7.1.9
0x02 开始编译安装httpd 2.4.27,跟之前一样,依然是先装好各种依赖库,步骤如下:1
2
3
4
5
6
7
8
9# yum install zlib zlib-devel pcre pcre-devel openssl openssl-devel libtool libtool-ltdl-devel -y
# tar xf apr-1.6.2.tar.gz
# cd apr-1.6.2 && ./configure --prefix=/usr/local/apr && make && make install
# yum install expat-devel -y
# tar xf apr-util-1.6.0.tar.gz && cd apr-util-1.6.0
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/ && make && make install
# useradd web -s /sbin/nologin -M
# tar xf httpd-2.4.27.tar.gz
# cd httpd-2.4.27
1 | # ./configure --prefix=/usr/local/httpd-2.4.27 \ |
0x03 编辑配置apache主配置文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95# vi httpd.conf
ServerRoot "/usr/local/httpd-2.4.27"
ServerName localhost:80
Listen 80
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authn_core_module modules/mod_authn_core.so
LoadModule authz_host_module modules/mod_authz_host.so
LoadModule authz_groupfile_module modules/mod_authz_groupfile.so
LoadModule authz_user_module modules/mod_authz_user.so
LoadModule authz_core_module modules/mod_authz_core.so
LoadModule access_compat_module modules/mod_access_compat.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule filter_module modules/mod_filter.so
LoadModule mime_module modules/mod_mime.so
LoadModule log_config_module modules/mod_log_config.so
LoadModule env_module modules/mod_env.so
LoadModule headers_module modules/mod_headers.so
LoadModule setenvif_module modules/mod_setenvif.so
LoadModule version_module modules/mod_version.so
LoadModule unixd_module modules/mod_unixd.so
LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
<IfModule !mpm_prefork_module>
</IfModule>
<IfModule mpm_prefork_module>
</IfModule>
LoadModule dir_module modules/mod_dir.so
LoadModule alias_module modules/mod_alias.so
<IfModule unixd_module>
User web
Group web
</IfModule>
ServerAdmin sec@secheight.com
<Directory />
AllowOverride none
Allow from all
</Directory>
DocumentRoot "/usr/local/httpd-2.4.27/htdocs"
<Directory "/usr/local/httpd-2.4.27/htdocs">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<IfModule dir_module>
DirectoryIndex index.html
</IfModule>
<Files ".ht*">
Require all denied
</Files>
ErrorLog "logs/error_log"
LogLevel warn
<IfModule log_config_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
<IfModule logio_module>
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %I %O" combinedio
</IfModule>
CustomLog "logs/access_log" common
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ "/usr/local/httpd-2.4.27/cgi-bin/"
</IfModule>
<IfModule cgid_module>
</IfModule>
<Directory "/usr/local/httpd-2.4.27/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
<IfModule headers_module>
RequestHeader unset Proxy early
</IfModule>
<IfModule mime_module>
TypesConfig conf/mime.types
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
</IfModule>
<IfModule proxy_html_module>
Include conf/extra/proxy-html.conf
</IfModule>
<IfModule ssl_module>
SSLRandomSeed startup builtin
SSLRandomSeed connect builtin
</IfModule>
Include conf/extra/httpd-vhosts.conf
Include conf/extra/httpd-mpm.conf
Include conf/extra/httpd-default.conf
<Directory "/var/html">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
0x04 编辑配置各种扩展功能
添加虚拟机主机1
2
3
4
5
6
7
8
9
10# vi /usr/local/httpd/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerAdmin bwapp@bwapp.com
DocumentRoot "/var/html/bwapp"
ServerName bwapp.com
ServerAlias www.bwapp.com
ErrorLog "logs/bwapp.com-error_log"
CustomLog "logs/bwapp.com-access_log" common
</VirtualHost>
0x05 让访问日志自动轮询1
2
3
4
5
6
7
8
9
10
11# tar xf cronolog-1.6.2.tar.gz
# cd cronolog-1.6.2
# ./configure && make && make install
<VirtualHost *:80>
ServerAdmin bwapp@bwapp.com
DocumentRoot "/var/html/bwapp"
ServerName bwapp.com
ServerAlias www.bwapp.com
ErrorLog "logs/bwapp.com-error_log"
CustomLog "|/usr/local/sbin/cronolog /usr/local/httpd/logs/bwapp.com-access_%Y%m%d.log" combined
</VirtualHost>
0x06 简单优化apache
调节apache默认并发1
2
3
4
5
6
7
8
9# vi /usr/local/httpd/conf/extra/httpd-mpm.conf
<IfModule mpm_worker_module>
StartServers 3
MinSpareThreads 75
MaxSpareThreads 250
ThreadsPerChild 25
MaxRequestWorkers 400
MaxConnectionsPerChild 0
</IfModule>
配置文件级别隐藏apache敏感版本信息1
2
3
4
5
6
7
8
9
10
11
12
13
14# vi /usr/local/httpd/conf/extra/httpd-default.conf
Timeout 60
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UseCanonicalName Off
AccessFileName .htaccess
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
<IfModule reqtimeout_module>
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500
</IfModule>
1 | # /usr/local/httpd/bin/apachectl -t |
二、部署mysql [ 为了节省时间,此次会用二进制包的方式进行部署 ]
0x01 安装前的一些准备工作1
# yum -y install gcc glibc libaio libstdc++
0x02 编写mysql主配置文件,my.cnf1
2
3
4
5
6
7
8
9
10
11
12
13# cp /etc/my.cnf /etc/my.cnf.bak
# > /etc/my.cnf
# vi /etc/my.cnf
[mysqld]
user=mysql
port = 3306
server_id = 1
socket=/tmp/mysql.sock
basedir =/usr/local/mysql
datadir =/usr/local/mysql/data
pid-file=/usr/local/mysql/data/mysqld.pid
log-error=/usr/local/mysql/log/mysql-error.log
0x03 安装初始化mysql1
2
3
4
5
6
7
8
9
10
11
12
13
14# tar xf mysql-5.7.18-linux-glibc2.5-x86_64.tar.gz
# mv mysql-5.7.18-linux-glibc2.5-x86_64 /usr/local/
# cd /usr/local/
# ln -s mysql-5.7.18-linux-glibc2.5-x86_64/ mysql
# echo "export PATH=$PATH:/usr/local/mysql/bin/" >> /etc/profile
# source /etc/profile
# groupadd mysql
# useradd -r -g mysql -s /bin/false mysql
# cd mysql
# mkdir log
# chown -R mysql:mysql . && ll
# mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql --explicit_defaults_for_timestamp
# cat /usr/local/mysql/log/mysql-error.log
root@localhost: (aAEs.S5csf:
1 | # cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld |
三、部署php
0x01 仍旧是先安装好所需的各种依赖库,为了方便大家复制,所以这里就分开写了1
2
3
4
5
6
7# yum install -y zlib zlib-devel libxml2-devel libxslt-devel
# yum install -y libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
# yum install -y gd gd-devel curl curl-devel bison-devel
# yum install -y libedit-devel readline-devel sqlite-devel libzip
# yum install -y epel-release
# yum install -y libmcrypt libmcrypt-devel mcrypt mhash mhash-devel openssl openssl-devel
# yum install -y bzip2-devel jemalloc jemalloc-devel
1 | # ln -s /usr/lib64/libjpeg.so /usr/lib/libjpeg.so |
0x02 开始编译安装php 7.1.9,注意,php7已经废弃mysql_connect1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59# tar xf php-7.1.9.tar.gz
# cd php-7.1.9
# ./configure \
--prefix=/usr/local/php-7.1.9 \
--exec-prefix=/usr/local/php-7.1.9 \
--bindir=/usr/local/php-7.1.9/bin \
--sbindir=/usr/local/php-7.1.9/sbin \
--includedir=/usr/local/php-7.1.9/include \
--libdir=/usr/local/php-7.1.9/lib/php \
--mandir=/usr/local/php-7.1.9/php/man \
--with-config-file-path=/usr/local/php-7.1.9/etc \
--with-iconv-dir=/usr/local/libiconv \
--with-apxs2=/usr/local/httpd/bin/apxs \
--with-mysqli=/usr/local/mysql/bin/mysql_config \
--with-mcrypt \
--with-mhash \
--with-openssl \
--with-mysqli=shared,mysqlnd \
--with-pdo-mysql=shared,mysqlnd \
--with-gd \
--with-zlib \
--enable-zip \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-xml \
--enable-bcmath \
--enable-shmop \
--enable-sysvsem \
--enable-mbregex \
--enable-mbstring \
--enable-ftp \
--enable-gd-native-ttf \
--enable-pcntl \
--enable-sockets \
--with-xmlrpc \
--enable-soap \
--without-pear \
--with-gettext \
--enable-session \
--with-curl \
--with-jpeg-dir \
--enable-short-tags \
--enable-static \
--with-png-dir \
--with-freetype-dir \
--with-fpm-user=web \
--with-fpm-group=web \
--enable-opcache \
--enable-fpm \
--without-gdbm \
--with-xsl \
--disable-fileinfo
# make && make install
# ll /usr/local/php-7.1.9/
# ln -s /usr/local/php-7.1.9/ /usr/local/php
# cp php.ini-production /usr/local/php/etc/php.ini
0x03 安装各种php扩展库1
2
3
4
5
6
7# cd ext/mysqli/
# /usr/local/php/bin/phpize
# ./configure --prefix=/usr/local/mysqli \
--with-php-config=/usr/local/php/bin/php-config \
--with-mysqli=/usr/local/mysql/bin/mysql_config
# make && make install
1 | # vi /usr/local/php/etc/php.ini |
1 | # vi /usr/local/httpd/conf/httpd.conf |
1 | # /usr/local/httpd/bin/apachectl -t |
四、安装各类开源程序对环境进行全面可用性检测1
2
3
4
5
6
7安装bwapp 漏洞演练程序
安装dvwa 漏洞演练程序
安装 Discuz X3.2
安装drupal 7.56
安装 wordpress 4.8.1
安装 joomla 3.6.5
...
End
写脚本,写脚本,写脚本,重要的事情说三遍,或者更暴力一点,配好了以后直接打成rpm包,以后如果是完全相同的系统,直接全程yum即可,不然得烦死,另外,此环境仅作为自己学习之用,所以基本没做过任何加固处理,严禁直接参考用于实际生产环境中,否则,一切后果自负