下载二进制64位包:
[root@aming01 ~]# cd /usr/local/src/ //下载mysql
[root@aming01 src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
正在保存至: “mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz”
100%[================================================================================================>] 328,740,156 3.22MB/s 用时 61s
2019-03-23 05:57:45 (5.17 MB/s) - 已保存 “mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz” [328740156/328740156])
[root@aming01 src]# ls
mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
[root@aming01 src]# tar zxvf mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz //解压mysql
[root@aming01 src]# ls
mysql-5.6.43-linux-glibc2.12-x86_64 mysql-5.6.43-linux-glibc2.12-x86_64.tar.gz
[root@aming01 src]# mv mysql-5.6.43-linux-glibc2.12-x86_64 /usr/local/mysql/ //把mysql挪动,并改名字为/usr/local/mysql/
[root@aming01 src]# cd /usr/local/mysql/
[root@aming01 mysql]# ls //查看一下mysql文件下的内容
bin COPYING data docs include lib man mysql-test README scripts share sql-bench support-files
[root@aming01 mysql]# useradd mysql // 创建mysql用户
[root@aming01 mysql]# mkdir /data/ //创建data 目录
[root@aming01 mysql]# ls /data/
[root@aming01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql //开始安装Mysql
FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db:
Data::Dumper
[root@aming01 mysql]# yum list|grep perl |grep -i dumper
perl-Data-Dumper.x86_64 2.145-3.el7 base
perl-XML-Dumper.noarch 0.81-17.el7 base
[root@aming01 mysql]# yum install -y perl-Data-Dumper
[root@aming01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
Installing MySQL system tables..../bin/mysqld: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
[root@aming01 mysql]# yum install libaio* -y
[root@aming01 mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql/
然后 复制配置文件和启动服务的文件
[root@aming01 mysql]# vim /etc/my.cnf //编辑这个配置文件,修改如下:
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
[root@aming01 mysql]# vim /etc/init.d/mysqld //启动的脚步修改basedir和datadir
# overwritten by settings in the MySQL configuration files.
basedir=/usr/local/mysql
datadir=/data/mysql
登录mysql
[root@aming01 mysql]# /usr/local/mysql/bin/mysql -uroot //登录数据库
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.39 MySQL Community Server (GPL)
Copyright (c) 2000, 2018, 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.01 sec)
mysql>
MariaDB安装
利用wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
cd /usr/local/src
wget https://downloads.mariadb.com/MariaDB/mariadb-10.2.6/bintar-linux-glibc_214-x86_64/mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
tar zxvf mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
mv mariadb-10.2.6-linux-glibc_214-x86_64 /usr/local/mariadb
cd /usr/local/mariadb
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mariadb/ --datadir=/data/mariadb
cp support-files/my-small.cnf /usr/local/mariadb/my.cnf
vi /usr/local/mariadb/my.cnf //定义basedir和datadir
cp support-files/mysql.server /etc/init.d/mariadb
vim /etc/init.d/mariadb //定义basedir、datadir、conf以及启动参数
/etc/init.d/mariadb start
Apache的安装:
首先利用wget命令下载安装包
下载地址为:https://mirrors.cnnic.cn/apache/
apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
tar zxvf httpd-2.4.27.tar.gz
tar zxvf apr-util-1.5.4.tar.gz
tar zxvf apr-1.5.2.tar.gz
cd /usr/local/src/apr-1.5.2
./configure --prefix=/usr/local/apr
make && make install
cd /usr/local/src/apr-util-1.5.4
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
cd /usr/local/src/httpd-2.4.27
./configure \ //这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=/usr/local/apache2.4 \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--enable-so \
--enable-mods-shared=most
make && make install
ls /usr/local/apache2.4/modules
/usr/local/apache2.4/bin/httpd -M //查看加载的模块
安装apr-util:
,然后make && make install 即可。
安装apache2.4
在这个中间会有报错,需要安装yum install -y pcre-devel这个包。
最后执行make && make install
安装PHP5:
PHP官网www.php.net
当前主流版本为5.6/7.1
安装php5 所需要依赖的安装包
[root@aming01 ~]# yum install -y epel-release freetype-devel libpng-devel libjpeg-devel bzip2-devel libxml2-devel openssl-devel
[root@aming01 php-5.6.30]# yum install -y libmcrypt-devel
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
tar zxf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
[root@aming01 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini //复制配置文件
[root@aming01 php-5.6.30]# vim /usr/local/php/etc/php.ini //编辑配置文件
安装php7
cd /usr/local/src/
wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
tar zxf php-7.1.6.tar.bz2
cd php-7.1.6
./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
make && make install
ls /usr/local/apache2.4/modules/libphp7.so
cp php.ini-production /usr/local/php7/etc/php.ini
Apache和php的结合:
一.:配置httpd支持php
httpd主配置文件/usr/local/apache2.4/conf/httpd.conf
vim /usr/local/apache2.4/conf/httpd.conf //修改以下4个地方
ServerName
Require all denied
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
/usr/local/apache2.4/bin/apachectl -t //测试语法
/usr/local/apache2.4/bin/apachectl start //启动服务
netstat -lntp
curl localhost
vim /usr/local/apache2.4/htodcs/1.php //增加如下内容
<?php
phpinfo();
?>
curl ip地址/1.php或者浏览器输入 ip地址/1.php即可看到测试效果
vim /usr/local/apache2.4/conf/httpd.conf 对配置文件做如下修改:
<Directory "/usr/local/apache2.4/cgi-bin">
AllowOverride None
Options None
Require all granted
</Directory>
Require all denied //如下实验完forbidden后,这里的denied要修改会granted
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -t //检查配置文件的语法是否正确
Syntax OK
如果出错,请检查上面vim /usr/local/apache2.4/conf/httpd.conf 以下4个地方
ServerName
Require all denied
AddType application/x-httpd-php .php
DirectoryIndex index.html index.php
2.httpd的默认虚拟主机:
一台服务器可以访问多个网站,每个网站都是一个虚拟主机
概念:域名(主机名)、DNS、解析域名、hosts
任何一个域名解析到这台机器,都可以访问的虚拟主机就是默认虚拟主机
vim /usr/local/apache2/conf/httpd.conf //搜索httpd-vhost,去掉#
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf //改为如下
<VirtualHost *:80>
ServerAdmin admin@aminglinux.com
DocumentRoot "/data/wwwroot/aming.com"
ServerName aming.com
ServerAlias www.aming.com
ErrorLog "logs/aming.com-error_log"
CustomLog "logs/aming.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
</VirtualHost>
/usr/local/apache2/bin/apachectl –t
/usr/local/apache2/bin/apachectl graceful
[root@aming01 ~]# vim /usr/local/apache2.4/conf/httpd.conf //编辑apache的主配置文件
# Virtual hosts
Include conf/extra/httpd-vhosts.conf //把这个前面的注释去掉,打开二级配置文件设置
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //编辑这个二级虚拟主机配置文件,修改如下:
<VirtualHost *:80> //这个在最前面就是默认虚拟主机,如果没有对应的虚拟主机,就会由默认虚拟主机来处理
DocumentRoot "/data/wwwroot/abc.com" // 定义站点的目录在哪里
ServerName abc.com //站点名字(仅有一个)
ServerAlias www.abc.com www.123.com //对站点进行别名
ErrorLog "logs/abc.com-error_log" //错误日志的地址
CustomLog "logs/abc.com-access_log" common // 日志记录的地址
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
ServerAlias www.example.com
ErrorLog "logs/111.com-error_log"
CustomLog "logs/111.com-access_log" common
</VirtualHost>
创建定义的虚拟主机的相关目录:
[root@aming01 ~]# vim /usr/local/apache2.4/conf/httpd.conf
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@aming01 ~]# mkdir /data/wwwroot/
[root@aming01 ~]# mkdir /data/wwwroot/abc.com //创建站点的根目录
[root@aming01 ~]# mkdir /data/wwwroot/111.com
[root@aming01 ~]# vim /data/wwwroot/abc.com/index.php //创建站点的测试文件或者网页文件(内容看这2个目录下的index.php)
[root@aming01 ~]# cat /data/wwwroot/abc.com/index.php
<?php
echo "test abc.com";
[root@aming01 ~]# vim /data/wwwroot/111.com/index.php
[root@aming01 ~]# cat /data/wwwroot/111.com/index.php
<?php
echo "test 111.com";
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl graceful
测试虚拟主机:
[root@aming01 ~]# curl -x192.168.88.128:80 abc.com
test abc.com[root@aming01 ~]# curl -x192.168.88.128:80 www.abc.com
test abc.com[root@aming01 ~]# curl -x192.168.88.128:80 www.abcdef.com //这个VirtualHost里面没有定义,就访问到了默认虚拟主机
test abc.com[root@aming01 ~]# curl -x192.168.88.128:80 www.example.com
test 111.com[root@aming01 ~]# curl -x192.168.88.128:80 111.com
test 111.com[root@aming01 ~]#
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf 如果打开了这个,后面访问的都会访问到这个虚拟主机的配置文件来。
总之,任何一个域名指向这台服务器,只要没有对应的虚拟主机,就会由默认虚拟主机来处理
Apache的用户认证:
vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //把123.com那个虚拟主机编辑成如下内容
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
<Directory /data/wwwroot/www.123.com> //指定认证的目录
AllowOverride AuthConfig //这个相当于打开认证的开关
AuthName "123.com user auth" //自定义认证的名字,作用不大
AuthType Basic //认证的类型,一般为Basic,其他类型阿铭没用过
AuthUserFile /data/.htpasswd //指定密码文件所在位置
require valid-user //指定需要认证的用户为全部可用用户
</Directory>
</VirtualHost>
/usr/local/apache2.4/bin/htpasswd -cm /data/.htpasswd aming
重新加载配置-t , graceful
绑定hosts,浏览器测试
curl -x127.0.0.1:80 www.123.com //状态码为401
curl -x127.0.0.1:80 -uaming:passwd www.123.com //状态码为200
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //对文件做验证<FilesMatch></FilesMatch>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/abc.com"
ServerName abc.com
ServerAlias www.abc.com www.123.com
ErrorLog "logs/abc.com-error_log"
CustomLog "logs/abc.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
ServerAlias www.example.com
#<Directory /data/wwwroot/111.com> //对目录进行验证
<FilesMatch 123.php>
AllowOverride AuthConfig
AuthName "111.com user auth"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</FilesMatch>
#</Directory>
ErrorLog "logs/111.com-error_log"
CustomLog "logs/111.com-access_log" common
</VirtualHost>
还可以针对单个文件进行认证
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
<FilesMatch admin.php>
AllowOverride AuthConfig
AuthName "123.com user auth"
AuthType Basic
AuthUserFile /data/.htpasswd
require valid-user
</FilesMatch>
</VirtualHost>
域名跳转:
需求,把123.com域名跳转到www.123.com,配置如下:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
ServerAlias 123.com
<IfModule mod_rewrite.c> //需要mod_rewrite模块支持
RewriteEngine on //打开rewrite功能
RewriteCond %{HTTP_HOST} !^www.123.com$ //定义rewrite的条件,主机名(域名)不是www.123.com满足条件
RewriteRule ^/(.*)$ http://www.123.com/$1 [R=301,L] //定义rewrite规则,当满足上面的条件时,这条规则才会执行
</IfModule>
</VirtualHost>
/usr/local/apache2/bin/apachectl -M|grep -i rewrite //若无该模块,需要编辑配置文件httpd.conf,删除rewrite_module (shared) 前面的#
curl -x127.0.0.1:80 -I 123.com //状态码为301
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^111.com$
RewriteRule ^/(.*)$ http:www.123.com/$1 [R=301,L]
# RewriteRule ^/(.*)/([1-9]+)$ http:www.123.com/$1/$2 [R=301,L] //如果有多个参数,用$1/$2/$.../$n
</IfModule>
[root@aming01 ~]# vim /usr/local/apache2.4/conf/httpd.conf //打开这个LoadModule rewrite_module modules/mod_rewrite.so
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -M |grep rewrite //查看已经加载rewrite模块
rewrite_module (shared)
[root@aming01 ~]# cat /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
# Virtual Hosts
#
# Required modules: mod_log_config
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
# <URL:http://httpd.apache.org/docs/2.4/vhosts/>
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration.
#
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any <VirtualHost> block.
#
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/abc.com"
ServerName abc.com
ServerAlias www.abc.com www.123.com
ErrorLog "logs/abc.com-error_log"
CustomLog "logs/abc.com-access_log" common
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/111.com"
ServerName 111.com
ServerAlias www.example.com 2111.com.cn
#<Directory /data/wwwroot/111.com>
#<FilesMatch 123.php>
# AllowOverride AuthConfig
# AuthName "111.com user auth"
# AuthType Basic
# AuthUserFile /data/.htpasswd
# require valid-user
# </FilesMatch>
#</Directory>
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^111.com$
RewriteRule ^/(.*)$ http:www.123.com/$1 [R=301,L]
# RewriteRule ^/(.*)/([1-9]+)$ http:www.123.com/$1/$2 [R=301,L]
</IfModule>
ErrorLog "logs/111.com-error_log"
CustomLog "logs/111.com-access_log" common
</VirtualHost>
下面开始测试效果:
[root@aming01 ~]# curl -x127.0.0.1:80 2111.com.cn -I
HTTP/1.1 301 Moved Permanently
Date: Sun, 31 Mar 2019 14:12:38 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Location: http://2111.com.cn/http:www.123.com/
Content-Type: text/html; charset=iso-8859-1
[root@aming01 ~]# curl -x192.168.88.128:80 2111.com.cn -I
HTTP/1.1 301 Moved Permanently //状态码301表示永久重定向
Date: Sun, 31 Mar 2019 14:12:58 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Location: http://2111.com.cn/http:www.123.com/
Content-Type: text/html; charset=iso-8859-1
[root@aming01 ~]# curl -x192.168.88.128:80 2111.com.cn/aaahshshhs -I
HTTP/1.1 301 Moved Permanently
Date: Sun, 31 Mar 2019 14:17:35 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Location: http://111.com/aaahshshhs
Content-Type: text/html; charset=iso-8859-1
Apache 访问日志问题:
访问日志记录用户的每一个请求
vim /usr/local/apache2.4/conf/httpd.conf //搜索LogFormat
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %b" common
把虚拟主机配置文件改成如下:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
ServerAlias 123.com
CustomLog "logs/123.com-access_log" combined
</VirtualHost>
重新加载配置文件 -t,graceful
curl -x127.0.0.1:80 -I 123.com
tail /usr/local/apache2.4/logs/123.com-access_log
Apache访问日志不记录静态文件:
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf //编辑配置文件做如下修改
ErrorLog "logs/111.com-error_log"
SetEnvIf Request_URI ".*\.gif$" img
SetEnvIf Request_URI ".*\.jpg$" img
SetEnvIf Request_URI ".*\.png$" img
SetEnvIf Request_URI ".*\.bmp$" img
SetEnvIf Request_URI ".*\.swf$" img
SetEnvIf Request_URI ".*\.js$" img
SetEnvIf Request_URI ".*\.css$" img
CustomLog "logs/111.com-access_log" combined env=!img //把所有img标记的都会记录到日志里面
Apache日志切割:
日志一直记录总有一天会把整个磁盘占满,所以有必要让它自动切割,并删除老的日志文件
把虚拟主机配置文件改成如下:
<VirtualHost *:80>
DocumentRoot "/data/wwwroot/www.123.com"
ServerName www.123.com
ServerAlias 123.com
SetEnvIf Request_URI ".*\.gif$" img
SetEnvIf Request_URI ".*\.jpg$" img
SetEnvIf Request_URI ".*\.png$" img
SetEnvIf Request_URI ".*\.bmp$" img
SetEnvIf Request_URI ".*\.swf$" img
SetEnvIf Request_URI ".*\.js$" img
SetEnvIf Request_URI ".*\.css$" img
CustomLog "|/usr/local/apache2.4/bin/rotatelogs -l logs/123.com-access_%Y%m%d.log 86400" combined env=!img //每天对日志文件进行切割
</VirtualHost>
重新加载配置文件 -t, graceful
ls /usr/local/apache2.4/logs
静态元素的过期时间:
浏览器访问网站的图片时会把静态的文件缓存在本地电脑里,这样下次再访问时就不用去远程下载了
增加配置
<IfModule mod_expires.c>
ExpiresActive on //打开该功能的开关
ExpiresByType image/gif "access plus 1 days"
ExpiresByType image/jpeg "access plus 24 hours"
ExpiresByType image/png "access plus 24 hours"
ExpiresByType text/css "now plus 2 hour"
ExpiresByType application/x-javascript "now plus 2 hours"
ExpiresByType application/javascript "now plus 2 hours"
ExpiresByType application/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0 min"
</IfModule>
需要expires_module
curl测试,看cache-control: max-age
vim /usr/local/apache2.4/conf/httpd.conf //编辑配置文件。打开如下模块
LoadModule expires_module modules/mod_expires.so
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -M |grep expire
expires_module (shared)
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 ~]# curl -x127.0.0.1:80 111.com/123.png -I
HTTP/1.1 200 OK
Date: Sun, 31 Mar 2019 16:07:58 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Last-Modified: Sun, 31 Mar 2019 15:13:03 GMT
ETag: "60b3-585655718fdc0"
Accept-Ranges: bytes
Content-Length: 24755
Cache-Control: max-age=86400
Expires: Mon, 01 Apr 2019 16:07:58 GMT //提示过期时间
Content-Type: image/png
[root@aming01 ~]#
Apache配置防盗链:
通过限制referer来实现防盗链的功能
配置文件增加如下内容
<Directory /data/wwwroot/www.123.com>
SetEnvIfNoCase Referer "http://www.123.com" local_ref
SetEnvIfNoCase Referer "http://123.com" local_ref
SetEnvIfNoCase Referer "^$" local_ref //这个是空referer
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png)">
Order Allow,Deny
Allow from env=local_ref
</filesmatch>
</Directory>
curl -e "http://www.aminglinux.com/123.html" 自定义referer
Apache访问控制Directory
核心配置文件内容
<Directory /data/wwwroot/111.com/admin/>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Directory>
curl测试状态码为403则被限制访问了
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@aming01 ~]# cd /data/wwwroot/111.com/admin/
[root@aming01 admin]# cat index.php
<?php
echo "test admin";
[root@aming01 admin]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 admin]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 admin]# curl -x127.0.0.1:80 111.com/admin/index.php -I
HTTP/1.1 200 OK
Date: Mon, 01 Apr 2019 12:55:49 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
X-Powered-By: PHP/5.6.39
Content-Type: text/html; charset=UTF-8
[root@aming01 admin]# curl -x192.168.88.128:80 111.com/admin/index.php -I
HTTP/1.1 403 Forbidden
Date: Mon, 01 Apr 2019 12:56:21 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Content-Type: text/html; charset=iso-8859-1
[root@aming01 admin]#
Apache访问控制FilesMatch
核心配置文件内容
<Directory /data/wwwroot/111.com>
<FilesMatch "admin.php(.*)">
Order deny,allow
Deny from all
Allow from 127.0.0.1
</FilesMatch>
</Directory>
限制某个目录解释php:
核心配置文件内容
<Directory /data/wwwroot/www.123.com/upload>
php_admin_flag engine off
</Directory>
curl测试时直接返回了php源代码,并未解析
[root@aming01 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@aming01 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 111.com]# curl -x127.0.0.1:80 http://111.com/upload/123.php
<?php
echo "123.php";
[root@aming01 ~]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 ~]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 ~]# cd /data/wwwroot/111.com/
[root@aming01 111.com]# mkdir upload
[root@aming01 111.com]# ls
123.php 123.png 456.png admin index.php upload
[root@aming01 111.com]# cp 123.php upload/
[root@aming01 111.com]# curl -x127.0.0.1:80 http://111.com/upload/123.php -I
HTTP/1.1 403 Forbidden
Date: Mon, 01 Apr 2019 14:40:28 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Content-Type: text/html; charset=iso-8859-1
Apache访问控制user_agent
user_agent可以理解为浏览器标识
核心配置文件内容
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} .*curl.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} .*baidu.com.* [NC]
RewriteRule .* - [F] ##F表示foribbiden
</IfModule>
curl -A "123123" 指定user_agent
[root@aming01 111.com]# vim /usr/local/apache2.4/conf/extra/httpd-vhosts.conf
[root@aming01 111.com]# /usr/local/apache2.4/bin/apachectl -t
Syntax OK
[root@aming01 111.com]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 111.com]# curl -x127.0.0.1:80 http://111.com/upload/123.php
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>403 Forbidden</title>
</head><body>
<h1>Forbidden</h1>
<p>You don't have permission to access /upload/123.php
on this server.<br />
</p>
</body></html>
[root@aming01 111.com]# curl -x127.0.0.1:80 http://111.com/upload/123.php -I
HTTP/1.1 403 Forbidden
Date: Mon, 01 Apr 2019 15:25:01 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Content-Type: text/html; charset=iso-8859-1
[root@aming01 111.com]# curl -A "aming aming" -x127.0.0.1:80 http://111.com/upload/123.php -I //-A指定user-agent
HTTP/1.1 200 OK
Date: Mon, 01 Apr 2019 15:28:11 GMT
Server: Apache/2.4.37 (Unix) PHP/5.6.39
Last-Modified: Mon, 01 Apr 2019 14:39:13 GMT
ETag: "16-58578fbfa028f"
Accept-Ranges: bytes
Content-Length: 22
Content-Type: application/x-httpd-php
curl命令的常用选项用法:
-A :--user-agent 设置用户代理发送给服务器
-e :--referer<URL>来源网址,跳转过来的网址
[root@aming01 ]# curl -A "aming aming" -x127.0.0.1:80 http://111.com/upload/123.php -I(大写的i)
[root@aming01 ]# curl -e "http://"
-x --proxy <host:port> :在给定的端口上使用HTTP代理
-I (大写的i):--head 只显示响应报文首部信息
[root@aming01 111.com]# curl -x127.0.0.1:80 http://111.com/upload/123.php -I
php的常用配置:
查看php配置文件位置
/usr/local/php/bin/php -i|grep -i "loaded configuration file"
date.timezone //定义date.timezone =Asia/Shanghai
display_errors = Off //错误也没不显示任何信息。
log_errors = On // 开启错误日志
error_log = /tmp/php_errors.log //定义错误日志的路径
error_reporting = Show all errors, except for notices
disable_functions //禁掉的函数
eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo
error_log, log_errors, display_errors, error_reporting
open_basedir // 防止网站被黑
php_admin_value open_basedir "/data/wwwroot/111.com:/tmp/"
[root@aming01 ~]# cd /data/wwwroot/111.com/
[root@aming01 111.com]# vi index.php
[root@aming01 111.com]# cd /usr/local/src/php-7.1.25/
[root@aming01 php-7.1.25]# cp php.ini-
php.ini-development php.ini-production
[root@aming01 php-7.1.25]# cp php.ini-development /usr/local/php7/etc/php.ini
[root@aming01 php-7.1.25]# /usr/local/apache2.4/bin/apachectl graceful
[root@aming01 php-7.1.25]# vim /usr/local/php7/etc/php.ini
[root@aming01 php-7.1.25]# /usr/local/apache2.4/bin/apachectl graceful
php动态模块的安装:
/usr/local/php/bin/php -m //查看模块
下面安装一个redis的模块
cd /usr/local/src/
wget https://codeload.github.com/phpredis/phpredis/zip/develop
mv develop phpredis-develop.zip
unzip phpredis-develop.zip
cd phpredis-develop
/usr/local/php/bin/phpize //生成configure文件
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
/usr/local/php/bin/php -i |grep extension_dir //查看扩展模块存放目录,我们可以在php.ini中去自定义该路径
vim /usr/local/php/etc/php.ini //增加一行配置(可以放到文件最后一行)
extension = redis.so
[root@aming01 src]# du -sh develop
252K develop
[root@aming01 src]# mv develop phpredis-develop.zip
[root@aming01 src]# unzip phpredis-develop.zip
[root@aming01 src]# cd phpredis-develop/
[root@aming01 phpredis-develop]#
[root@aming01 phpredis-develop]# /usr/local/php7/bin/phpize //生成./configgure的配置文件
Configuring for:
PHP Api Version: 20160303
Zend Module Api No: 20160303
Zend Extension Api No: 320160303
[root@aming01 phpredis-develop]# ./configure --with-php-config=/usr/local/php7/bin/php-config
[root@aming01 phpredis-develop]# make && make install
[root@aming01 phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
[root@aming01 phpredis-develop]#
[root@aming01 phpredis-develop]# /usr/local/php7/bin/php -i |grep -i extension_dir
extension_dir => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303 => /usr/local/php7/lib/php/extensions/no-debug-zts-20160303
sqlite3.extension_dir => no value => no value
[root@aming01 phpredis-develop]# ls /usr/local/php7/lib/php/extensions/no-debug-zts-20160303/
opcache.so redis.so
[root@aming01 phpredis-develop]# vim /usr/local/php7/etc/php.ini
[root@aming01 phpredis-develop]# /usr/local/php7/bin/php -m |grep redis
redis
[root@aming01 phpredis-develop]#
扩展
mysql5.5源码编译安装 http://www.aminglinux.com/bbs/thread-1059-1-1.html
mysql5.7二进制包安装(变化较大) http://www.apelearn.com/bbs/thread-10105-1-1.html
apache dso(动态共享目标) https://yq.aliyun.com/articles/6298
apache apxs https://wizardforcel.gitbooks.io/apache-doc/content/51.html
apache工作模式 http://www.cnblogs.com/fnng/archive/2012/11/20/2779977.html
php中mysql,mysqli,mysqlnd,pdo到底是什么 http://blog.csdn.net/u013785951/article/details/60876816
查看编译参数 http://ask.apelearn.com/question/1295
几种限制ip的方法http://ask.apelearn.com/question/6519
apache 配置https 支持sslhttp://ask.apelearn.com/question/1029
apache rewrite教程http://coffeelet.blog.163.com/blog/static/13515745320115842755199/ http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html
apache rewrite 出现死循环http://ask.apelearn.com/question/1043
php错误日志级别参考 http://ask.apelearn.com/question/6973