(首先说句抱歉,因为是连续几天的笔记,记录的有些混乱。有需要的内容请自行翻看忽略其他吧。)
LAMP环境配置查漏补缺
把/usr/local/apache2/bin/apachectl start加入到vim /etc/rc.local里
开机启动apache
在vim/usr/local/apache2/conf/httpd.conf添加
<IfModuledir_module>
DirectoryIndex index.html index.php
</IfModule>
vim /usr/local/apache2/conf/httpd.conf
找到并打开注释
# Virtualhosts
Includeconf/extra/httpd-vhosts.conf
并且把
<Directory/>
Options FollowSymLinks
AllowOverride None
Order deny,allow
Allow from all
</Directory>
中的Deny from all 改为 Allow from all
此步骤解决You don't have permission to access / on this server.问题。
配置虚拟主机
编辑httpd-vhosts.conf
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
虚拟主机核心配置文件
<VirtualHost*:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/usr/local/apache2/docs/dummy-host.example.com"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
</VirtualHost>
更改完配置文件一定要检测有没有错误并解决。
/usr/local/apache2/bin/apachectl -t
discuz相关
discus 下载
http://www.discuz.net/forum-10-1.html
解压后
把upload下的文件移动出来,然后把下载包、upload、readme、utility删除
域名/installdiscuz安装向导
chown -R daemon config/ data uc_client/data uc_server/data 改变文件所属主
安装向导就可以通过第一步了。
启动mysql
/etc/init.d/mysqld start
Starting MySQL... SUCCESS!
加入开机启动
chkconfig --add mysqld
chkconfig mysqld on
查看开机启动是否成功
chkconfig --list |grep mysql
加入环境变量
PATH=$PATH:/usr/local/mysql/bin
可以直接输入mysql命令进入mysql
全局声明
vim/etc/profile
加入
export PATH=$PATH:/usr/local/mysql/bin
给mysql root用户添加密码
mysqladmin -uroot password '123456'
添加成功后登陆mysql需输入
mysql -uroot -p 然后根据提示输入密码进入mysql
使用root用户授权新建user1用户,密码:discuz
mysql>grant all on *.* to 'user1'@'localhost' identified by 'discuz';
QueryOK, 0 rows affected (0.00 sec)
quit推出
登陆user1用户
mysql -uuser1 -pdiscuz
为虚拟主机配置用户认证
<VirtualHost*:80>
# ServerAdminwebmaster@dummy-host.example.com
DocumentRoot "/data/123"
ServerName 123.com
ServerAlias 456.com
# ErrorLog"logs/dummy-host.example.com-error_log"
# CustomLog"logs/123.com-access_log" common
<Directory/data/123/>
AllowOverride Authconfig
AuthName "自定义的"
AuthType Basic
AuthUserFile /data/.htpasswd
require valia-user
</Directory>
</VirtualHost>
在<virtualHost>里加入<directory>
域名跳转
要把访问的域名456.com转发到域名123.com上
在虚拟主机配置文件里添加(vim /usr/local/apache2/conf/extra/httpd-vhosts.conf)
<IfModulemod_rewrite.c>
RewriteEngine on
RewriteCond%{HTTP_HOST} ^456.com$
RewriteRule /(.*)$ http://123.com/$1[R=301,L]
</IfModule>
添加后测试 重新加载服务
graceful重新加载
restart 先停再启
查阅资料关键字 rewrite
配置apache的访问日志
%{User-Agent}浏览器标识
%{Referer}来路
配置静态文件缓存
全局配置 添加缓存过期时间 httpd.conf
添加
<IfModulemod_expires.c>
ExpiresActive on
ExpiresByType image/gif "accessplus 1 days"
ExpiresByType image/jpeg "accessplus 24 hours"
ExpiresByType image/png "accessplus 24 hours"
ExpiresByType text/css "now plus 2hours"
ExpiresByType application/x-javascript"now plus 2 hours"
ExpiresByTypeapplication/x-shockwave-flash "now plus 2 hours"
ExpiresDefault "now plus 0min"
</IfModule>
防盗链
配置vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
SetEnvIfNoCase Referer "^http://123.com" local_ref
SetEnvIfNoCase Referer "^http://456.com" local_ref
<filesmatch "\.(txt|doc|mp3|zip|rar|jpg|gif|png|js|css)">
Order Allow,Deny 先allow再deny
Allow from env=local_ref
Deny from !env=local_ref
</filesmatch>
设置完要测试并刷新
访问控制
Order allow,deny
deny from all
allow from 127.0.0.1
按顺序 谁在前先执行谁,先allow127.0.0.1 然后再执行deny all
在虚拟主机配置里添加
<Directory /data/123/install> 定义条件的目录
Order allow,deny
allow from all
deny from 127.0.0.1
</Directory>
怎样设置Apache访问限制
https://jingyan.baidu.com/article/4b07be3c193d1648b380f3a9.html
PHP配置
/usr/local/php/bin/php -i|head 查看php配置文件路径
vim /usr/local/php/ect/php.ini
配置disable_function 禁用函数提高安全性
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
display_errors= Off 默认是Off 页面错误信息提示关闭,On 开启(页面显示路径不太安全)
检测apache并且graceful 重新加载
log_errors= On 开启错误日志
error_log= /usr/local/php/logs/php_errors.log 自定义错误日志路径 最好定义一下文件夹的权限777
error_reporting= E_ALL & ~E_NOTICE定义错误级别
配置open_basedir
vim /usr/local/php/ect/php.ini
open_basedir= /tmp/:/data/123/ 相当于白名单
还可以在虚拟主机配置文件里面做限制
vim /usr/local/apache2/conf/extra/httpd-vhosts.conf
<VirtualHost*:80>
php_admin_value open_basedir "/dir1/:/dir2/"
</VirtualHost>
php扩展模块的安装(memcache)
wget http://www.apelearn.com/bbs/data/attachment/forum/memcache-2.2.3.tgz
下载memcache
tar zxvf memcache-2.2.3.tgz
解压
进入解压后文件夹
/usr/local/php/bin/phpize
会生产
Configuringfor:
PHP ApiVersion: 20131106
ZendModule Api No: 20131226
ZendExtension Api No: 220131226
Cannotfind autoconf. Please check your autoconf installation and the
$PHP_AUTOCONFenvironment variable. Then, rerun this script.
提示没有发现autoconf需要yum安装一下。yum install -yautoconf
装完后/usr/local/php/bin/phpize一下重新生成需要的文件
./configure --with-php-config=/usr/local/php/bin/php-config
make && make install
安装完成后会有一条提示
Installingshared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
ls 此路径会有.so的文件。
在vim /usr/local/php/etc/php.ini 最后(自己选择位置= =)增加
extension=memcache.so
/usr/local/php/bin/php -m 查看有没有成功加载memcache
最后重新加载一下apache服务
/usr/local/apache2/bin/apachectl graceful
最后引用一下猿课阿铭老师关于memcache和memcached在php中的应用
的笔记http://ask.apelearn.com/question/45