LAMP架构
LAMP是指一组通常一起使用来运行动态网站或者服务器的自由软件名称首字母缩写: LAMP=Linux+Apache(httpd)+MySQL+PHP
工作模式:
MySQl安装
MySQL是一个关系型数据库: MySQL的几个常用安装包:rpm、源码、二进制免编译 MySQL所使用的 SQL 语言是用于访问数据库的最常用标准化语言。MySQL 软件采用了双授权政策,分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择 MySQL 作为网站数据库。
安装:
1
. cd
/usr
/local
/src
2
. Window下载通过xftp上传 mysql
-5
.6
.43
-linux
-glibc2
.12
-x86_64
.tar
.gz
3
. tar
-zxf mysql
-5
.6
.43
-linux
-glibc2
.12
-x86_64
.tar
.gz
4
. mv mysql
-5
.6
.43
-linux
-glibc2
.12
-x86_64
/usr
/local
/mysql
5
. cd
/usr
/local
/mysql
6
. useradd mysql
7
. mkdir
/data/
8
. ./scripts
/mysql_install_db
--user=mysql
--datadir=
/data/mysql
(
//
--user表示定义数据库的以哪个用户的身份运
//
--datadir表示定义数据库的安装目录)
9
. cp support
-files
/my
-default
.cnf
/etc
/my
.cnf
10
. vi my
.cnf
Basedir=
/usr
/local
/mysql
//basedir表示MySQL包所在路径
Datadir=
/data/mysql
/datadir
//表示定义存放数据的位置
Port=3306
//port表示定义MySQL服务监听的端口号
Server_id=128
//表示该MySQL服务的ID号
socket =
/tmp
/mysql
.sock
11
. cp support
-files
/mysql
.server
/etc
/init
.d
/mysqld
12
. vi
/etc
/init
.d
/mysqld
(配置文件
)
a
) 定义basedir和datadir
13
.
14
.
15
.
16
.
17
.
18
.
问题:
安装包地址失效,由Windows上传运行安装mysql 报错 [root@localhost mysql-mult]# ./scripts/mysql_install_db --defaults-file=conf/3306my.cnf FATAL ERROR: please install the following Perl modules before executing ./scripts/mysql_install_db: Data::Dumper
安装autoconf yum
-y install autoconf
补充知识:yum -y install perl-Module-Install Yum list | grep perl 列出perl列表 Echo $? 0 测试进程是否成功
根据提示 查看错误信息
继续查看错误日志tail
-f
/var/log
/mysqld
.log
Service mysql restart
ERROR! MySQL server PID file could not be found! Starting MySQL.Logging to ‘/data/mysql/datadir/coco.err’. ERROR! The server quit without updating PID file (/data/mysql/datadir/coco.pid).
修改配置文件
vi
/etc
/init
.d
/mysql
Mkdir
/data/mysql
/datadir
/mysql
.pid
更改所有者 chown
-R mysql mysql
.pid
Apache安装
Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。它快速、可靠并且可通过简单的API扩充,将Perl/Python等解释器编译到服务器中。Apache是一个基金会的名字,httpd才是我们要安装的软件包,早期它的名字就叫apache Apache官网www.apache.org
安装
```powershell
1
. Cd
/usr
/local
/src
2
. wget http:
//archive
.apache
.org
/dist
/httpd
/httpd
-2
.4
.27
.tar
.gz
3
. wget http:
//archive
.apache
.org
/dist
/apr
/apr
-1
.5
.2
.tar
.gz
4
. wget http:
//archive
.apache
.org
/dist
/apr
/apr
-util
-1
.5
.4
.tar
.gz
i
. apr和apr
-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便地移植(从linux移植到windows)
5
. tar
-zxvf httpd
-2
.4
.27
.tar
.gz
6
. tar
-zxvf apr
-util
-1
.5
.4
.tar
.gz
7
. tar
-zxvf apr
-1
.5
.2
.tar
.gz
8
. cd
/usr
/local
/src
/apr
-1
.5
.2
9
. ./configure
--prefix=
/usr
/local
/apr
10
. make && make install
11
. cd
/usr
/local
/src
/apr
-util
-1
.5
.4
12
. ./configure
--prefix=
/usr
/local
/apr
-util
--with
-apr=
/usr
/local
/apr
13
. make
- j4 && make install (加速)
14
. cd
/usr
/local
/src
/httpd
-2
.4
.27
15
. ./configure \
//这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=
/usr
/local
/apache2
.4 \
--with
-apr=
/usr
/local
/apr \
--with
-apr
-util=
/usr
/local
/apr
-util \
--enable
-so \
--enable
-mods
-shared=most
16
. make && make install
17
. ls /usr
/local
/apache2
.4
/modules
18
. /usr
/local
/apache2
.4
/bin
/httpd
-M
//查看加载的模块
(成功
)
问题:
误删、root目录,目前没有发现什么影响rm: cannot remove `libtoolT’: No such file or directory
提示编辑configure这个文件,将
$RM “
$cfgfile” 那行注释掉 ,然后重新编译即可。
Yum install
-y libtool
*
扩展知识:
Vim查询文件内容关键词:
/内容 回车 n下一个 shift
+n上一个
./configure 进入软件包内进行初始化配置
Yum
-y install 包名
-devel
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
安装
pcre
-8
.32
.tar
.gz https:
//sourceforge
.net
/projects
/pcre
/files
/pcre
/
collect2: error: ld returned 1 exit status Cd srclib(查看是否有Makefile) Cp -r apr-1.5.2 /httpd-2.4.27/srclib/apr Cp -r apr-util-1.5.4 /httpd-2.4.27/srclib/apr-util
Make clean
./configure \
//这里的反斜杠是脱义字符,加上它我们可以把一行命令写成多行
--prefix=
/usr
/local
/apache2
.4 \
--with
-included
-apr
--enable
-moudles=most
--enable
-so \
--enable
-mods
-shared=all
-with
-npm=prefork
Make
-j4 && make install
安装PHP5
2004年7月,PHP5正式版本的发布,标志着一个全新的PHP时代的到来。它的核心是第二代Zend引擎,并引入了对全新的PECL模块的支持。 官网www.php.net 当前主流版本为5.6/7.1PHP5
安装
1
. cd
/usr
/local
/src
/
2
. wget http:
//tw1
.php
.net
/get
/php
-5
.6
.30
.tar
.gz
/from/this
/mirror
3
. tar
-zxvf php
-5
.6
.30
.tar
.gz
4
. cd php
-5
.6
.30
5
. ./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
6
. make && make install
7
. cp php
.ini
-production
/usr
/local
/php
/etc
/php
.ini
问题:
tar:Error is not recoverable: exiting now
mv mirror php
-5
.6
.30
.tar
.gz
configure: error: Cannot find OpenSSL’s <evp.h>
yum install libxml2
-devel libpng libpng
-devel openssl openssl
-devel freetype freetype
-devel opel
-release
-y
configure: error: Please reinstall the BZip2 distribution
yum install bzip2 bzip2
-devel
configure: error: jpeglib.h not found.
yum
-y install libjpeg
-devel
yum
-y install libmcrypt
-devel
configure: error: xml2-config not found. Please check your libxml2 installation
yum install libxml2
* -y
yum
-y install libxml2
安装PHP7
PHP(外文名:PHP Hypertext Preprocessor,中文名:“超文本预处理器”)是一种通用开源脚本语言。 PHP语法吸收了C语言、Java和Perl的特点,易于学习,使用广泛,主要适用于Web开发领域。PHP 独特的语法混合了C、Java、Perl以及PHP自创的语法。它可以比CGI或者Perl更快速地执行动态网页。用PHP做出的动态页面与其他的编程语言相比,PHP是将程序嵌入到HTML(标准通用标记语言下的一个应用)文档中去执行,执行效率比完全生成HTML标记的CGI要高许多;PHP还可以执行编译后代码,编译可以达到加密和优化代码运行,使代码运行更快的效果。
PHP 7.0.0 Alpha 1 [1] 使用新版的ZendEngine引擎,带来了许多新的特性,以下是不完全列表: 性能提升:PHP7比PHP5.6性能提升了两倍。 Improved performance: PHP 7 is up to twice as fast as PHP 5.6 全面一致的64位支持。 Consistent 64-bit support 以前的许多致命错误,改成抛出异常。Many fatal errors are now Exceptions 移除了一些老的不在支持的SAPI(服务器端应用编程端口)和扩展。Removal of old and unsupported SAPIs and extensions 新增了空接合操作符。The null coalescing operator (??) 新增加了结合比较运算符。Combined comparison Operator (<=>) 新增加了函数的返回类型声明。Return Type Declarations 新增加了标量类型声明。Scalar Type Declarations 新增加匿名类。Anonymous Classes
安装
1
. cd
/usr
/local
/src
/
2
. wget http:
//cn2
.php
.net
/distributions
/php
-7
.1
.6
.tar
.bz2
3
. tar zxf php
-7
.1
.6
.tar
.bz2
4
. cd php
-7
.1
.6
5
. ./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
6
. make && make install
7
. ls /usr
/local
/apache2
.4
/modules
/libphp7
.so
8
. cp php
.ini
-production
/usr
/local
/php7
/etc
/php
.ini
问题:
gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now
tar
-xvf php
-7
.1
.6
.tar
.bz2
配置httpd支持php
httpd是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。
1
. httpd主配置文件
/usr
/local
/apache2
.4
/conf
/httpd
.conf
2
. vim
/usr
/local
/apache2
.4
/conf
/httpd
.conf
//修改以下4个地方
搜索ServerName,
把ServerName www
.example
.com:80前
AllowOverride none
Require all denied
改成:
AllowOverride none
Require all granted
搜索AddType application
/x
-gzip
.gz
.tgz,
在下面添加一行 AddType application
/x
-httpd
-php
.php
DirectoryIndex index
.html
DirectoryIndex index
.html index
.php
2
. /usr
/local
/apache2
.4
/bin
/apachectl
-t
//测试语法
3
. /usr
/local
/apache2
.4
/bin
/apachectl
start //启动服务
4
. netstat
-lntp
5
. curl localhost
6
. vim
/usr
/local
/apache2
.4
/htdocs
/test
.php
//增加如下内容
<?php
echo 123
;
?>
7
. curl localhost
/test
.php
问题:
/usr/local/apache2.4/bin/apachectl: line 79: 34406 Segmentation fault $HTTPD -k $ARGV
将
/usr
/local
/apache2
/conf
/httpd
.conf中的
LoadModule php5_module modules
/libphp5
.so注释掉
并添加LoadModule php7_module modules
/libphp7
.so
2-bash: netstat: command not found
yum install net
-tools
httpd的默认虚拟主机
虚拟主机(共享主机,又称虚拟服务器)是一种在单一主机或主机群上,实现多网域服务的方法,可以运行多个网站或服务的技术。虚拟主机之间完全独立,并可由用户自行管理,虚拟并非指不存在,而是指空间是由实体的服务器延伸而来,其硬件系统可以是基于服务器群,或者单个服务器。 一台服务器可以访问多个网站,每个网站都是一个虚拟主机 概念:域名(主机名)、DNS、解析域名、hosts 任何一个域名解析到这台机器,都可以访问的虚拟主机就是默认虚拟主机
扩展知识:
//ServerAdmin指定管理员邮箱,
//DocumentRoot为该虚拟主机站点的根目录,
//ServaerName为网站的域名
//ServerAlias为网站的第二域名
//ErrorLog为站点的错误日志
//CustomLog为站点的访问日志
httpd的用户认证
介绍用户认证用来对某些目录中的网页进行访问控制,当用户访问些 页面的时候需要输入用户名和密码进行认证。
1
. vim
/usr
/local
/apache2
.4
/conf
/extra
/httpd
-vhosts
.conf
//把123
.com那个虚拟主机编辑成如下内容
2
. <VirtualHost
*:80>
ServerAdmin admin@ytlinux
.com
DocumentRoot
"/data/wwwroot/ytl.com"
ServerName ytl
.com
ServerAlias www
.ytl
.com
ErrorLog
"logs/ytl.com-error_log"
CustomLog
"logs/ytl.com-access_log" common
<Directory
/data/wwwroot
/ytl
.com>
AllowOverride AuthConfig
AuthName
"ytl.com user auth"
AuthType Basic
AuthUserFile
/data/.htpasswd
require valid
-user
<
/Directory>
<
/VirtualHost>
<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 ytl 设置密码
/usr
/local
/apache2
.4
/bin
/apachectl –t
/usr
/local
/apache2
.4
/bin
/apachectl graceful
3
. curl localhost,浏览器测试
4
. curl
-x127
.0
.0
.1:80 ytl
.com
//状态码为401
curl
-x127
.0
.0
.1:80
-uytl:passwd ytl
.com
//状态码为200
curl
-xlocalhost:80 ytl
.com
-I
还可以针对单个文件进行认证
<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>
问题:
httpd: Syntax error on line 490 of /usr/local/apache2.4/conf/httpd.conf: Syntax error on line 41 of /usr/local/apache2.4/conf/extra/httpd-vhosts.conf: Expected but saw
配置文件拼写有误require valid
-user
域名跳转
当我们变更网站域名或者申多个域名指向一个网站的时候,这个时候我们就会用到域名跳转。
需求,把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
.4
/bin
/apachectl
-M
|grep
-i rewrite
//若无该模块,需要编辑配置文件httpd
.conf,删除rewrite_module
(shared
) 前面的
curl
-x127
.0
.0
.1:80
-I 123
.com
//状态码为301
访问日志
访问日志记录用户的每一个请求
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
vim
/usr
/local
/apache2
.4
/conf
/extra
/httpd
-vhosts
.conf
把虚拟主机配置文件改成如下:
<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
访问日志不记录指定类型的文件
网站大多元素为静态文件,如图片、css、js等,这些元素可以不用记录
把虚拟主机配置文件改成如下:
<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
"logs/123.com-access_log" combined env=
!img
<
/VirtualHost>
重新加载配置文件
-t
, graceful
mkdir
/data/wwwroot
/www
.123
.com
/images
//创建目录,并在这目录下上传一个图片
curl
-x127
.0
.0
.1:80
-I 123
.com
/images
/123
.jpg
tail
/usr
/local
/apache2
.4
/logs
/123
.com
-access_log 查看日志
访日志切割
日志一直记录总有一天会把整个磁盘占满,所以有必要让它自动切割,并删除老的日志文件 把虚拟主机配置文件改成如下:
<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=0
curl
-x127
.0
.0
.1:80
-I www
.123
.com
配置防盗链
防盗链,就是不让别人盗用你网站上的资源,这个资源,通常指的是图片、视频、歌曲、文档等。
通过限制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
<filesmatch
"\.(txt|doc|mp3|zip|rar|jpg|gif)">
Order Allow
,Deny
Allow
from env=local_ref
<
/filesmatch>
<
/Directory>
curl
-e
"http://www.ytlinux.com/123.html" 自定义referer
问题及扩展知识:
httpd: Syntax error on line 490 of /usr/local/apache2.4/conf/httpd.conf: Syntax error on line 89 of /usr/local/apache2.4/conf/extra/httpd-vhosts.conf: without matching section
将配置静态元素过期时间的部分注释掉
2.扩展知识:
1
. 批量注释:
首先打开要注释的文件,将光标调到要注释的那一行,使用Ctrl
+v的方法进入块选择模式;
然后按住光标上下移动,选择要注释的行;
按shift
+ i进入行首输入模式
;
输入
//进行注释(Linux下c编程)或者输入
按两次ESC进行退出;
注释成功。
注意:以下两种需要注释的话,只有示例二可以成功,示例一需要在上面第二步的时候光标需要往左选择,需要到行首
2
. 消除注释:
先将光标调到要取消注释行的行头;
按住Ctrl
+v进入块选模式;
通过按j来调整光标,将所有的注释符号圈中;
取消注释成功。
访问控制 – Directory
核心配置文件内容
<Directory
/data/wwwroot
/www
.123
.com
/admin
/>
Order deny
,allow
Deny
from all
Allow
from 127
.0
.0
.1
<
/Directory>
curl测试状态码为403则被限制访问了
curl
-x127
.0
.0
.1:80
-I www
.123
.com
问题:
httpd not running, trying to start
services httpd
start
访问控制 – FilesMatch
核心配置文件内容
<Directory
/data/wwwroot
/www
.123
.com>
<FilesMatch
"admin.php(.*)">
Order deny
,allow
Deny
from all
Allow
from 127
.0
.0
.1
<
/FilesMatch>
<
/Directory>
touch
/data/wwwroot
/testdomain
.com
/admin
/admin
.php
访问控制 – 禁止php解析
核心配置文件内容
<Directory
/data/wwwroot
/www
.123
.com
/upload>
php_admin_flag engine off
<
/Directory>
/usr
/local
/apache2
.4
/bin
/apachectl
-t
Syntax OK
/usr
/local
/apache2
.4
/bin
/apachectl graceful(不可缺少!!!)
curl测试时直接返回了php源代码,并未解析
访问控制 – 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]
<
/IfModule>
curl
-A
"123123" 指定user_agent
PHP相关配置
/usr
/local
/php
/bin
/php
-i
|grep
-i
"loaded configuration file"
vim
/usr
/local
/php
/etc
/php
.ini搜索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
查看php配置文件位置
配置error_log, log_errors, display_errors, error_reporting
1
.
2
. 搜索log_errors
, 改成如下log_errors=On/
/记录错误日志目录位置:
3
. 搜索error_log
,改为error_log =
/var/log
/php
/php_errors
.log/
/记录错误日志级别:
4
. 搜索error_reporting 改为error_reporting = E ALL & ~E_ NOTICE/
/再搜索display_errors
,改为display_errors = Off
5
. 配置完php
.ini,可以额外配置:
6
.
7
.
8
.
open_basedir
1
. 先在php
.ini中设置open_basedir:
2
. //搜索open_basedir
,改成如下
open_ basedir =
/tmp:
/data/wwwroot
/www
.123
.com
3
. curl
-x127
.0
.0
.1:80
-I www
.123
.com
/test
.php 状态码500
4
.
<VirtualHost
*:80>
DocumentRoot
"/data/wwwroot/testdomain.com"
ServerName www
.testdomain
.com
ServerAlias testdomain
.com
CustomLog
"|/usr/local/apache2.4/bin/rotatelogs -l logs/123.com-access_%Y%m%d.1og 86400"combined
php_admin_value open_basedir
"/data/wwwroot/111.com:/tmp/"
<
/VirtualHost>
//起作用的是php_admin_value,它定义了php
.ini的参数
5
. 定义date
.timezone,减少警告
6
.
7
. date
.timezone = Asia
/Shanghai
PHP动态扩展模块
1
. /usr
/local
/php
/bin
/php
-m
//查看模块
2
. 下面安装一个redis的模块
3
. cd
/usr
/local
/src
/
4
. wget https:
//github
.com
/phpredis
/phpredis
/archive
/4
.3
.0
.tar
.gz
5
. wget http:
//pecl
.php
.net
/get
/redis
-2
.2
.5
.tgz
6
. tar
-zxvf redis
-2
.2
.5
.tgz
7
. mv redis
-2
.2
.5 phpredis
-develop
8
. mv 4
.3
.0
.tar
.gz phpredis
-4
.3
.0
.tar
.gz
9
. tar
-zxvf phpredis
-4
.3
.0
.tar
.gz
10
. cd phpredis
-4
.3
.0
11
. /usr
/local
/php
/bin
/phpize
//生成configure文件
12
. ./configure
--with
-php
-config=
/usr
/local
/php
/bin
/php
-config
13
. make && make install
14
. /usr
/local
/php
/bin
/php
-i
|grep extension_dir
//查看扩展模块存放目录,我们可以在php
.ini中去自定义该路径
15
. vim
/usr
/local
/php7
/etc
/php
.ini
//增加一行配置(可以放到文件最后一行)
16
. extension = redis
.so
17
./usr
/local
/php7
/bin
/php
-m
|grep redis
问题:
Error downloading packages: unzip-6.0-15.el7.x86_64: [Errno 256] No more mirrors to try.
cd
/etc
/yum
.repos
.d
/
wget http:
//mirrors
.163
.com
/.help
/CentOS7
-Base
-163
.repo
桥豆麻袋!!!
这么好看点个赞再走也不迟, 这样我也就能回答问题了