1.Piwik简介
Piwik是一个PHP和MySQL的开放源代码的Web统计软件,它给你一些关于你的网站的实用统计报告,比如网页浏览人数,访问最多的页面,搜索引擎关键词等等。
Piwik拥有众多不同功能的插件,你可以添加新的功能或是移除你不需要的功能,Piwik同样可以安装在你的服务器上面,数据就保存在你自己的服务器上面。你可以非常容易的插入统计图表到你的博客或是网站亦或是后台的控制面板中。安装完成后,你只需将一小段代码放到将要统计的网页中即可。
2.Piwik环境要求
要运行Piwik,你的主机需要几件事情:
Web服务器,如Apache,Nginx,IIS等
PHP版本5.5.9或更高
MySQL 5.5或更高版本,或MariaDB
(默认启用)PHP扩展名pdo和pdo_mysql,或者是mysqli扩展
具体查看:https://piwik.org/docs/requirements/
3.php+nginx环境搭建
下载
# wget http://php.net/get/php-7.0.2.tar.gz/from/a/mirror
解压安装
# tar zxvf php-7.0.2.tar.gz
# cd php-7.0.2
首先查看安装帮助
# ./configure --help
# ./configure --prefix=/usr/local/php \
--with-curl \
--with-freetype-dir \
--with-gd \
--with-gettext \
--with-iconv-dir \
--with-kerberos \
--with-libdir=lib64 \
--with-libxml-dir \
--with-mysqli \
--with-openssl \
--with-pcre-regex \
--with-pdo-mysql \
--with-pdo-sqlite \
--with-pear \
--with-png-dir \
--with-xmlrpc \
--with-xsl \
--with-zlib \
--enable-fpm \
--enable-bcmath \
--enable-libxml \
--enable-inline-optimization \
--enable-gd-native-ttf \
--enable-mbregex \
--enable-mbstring \
--enable-opcache \
--enable-pcntl \
--enable-shmop \
--enable-soap \
--enable-sockets \
--enable-sysvsem \
--enable-xml \
--enable-zip
假设配置错误,须要安装须要的模块,直接yum一并安装依赖库
# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel
注意:安装php7beta3的时候有几处配置只是去,须要yum一下。如今php-7.0.2已经不用这样了。
# yum -y install curl-devel
# yum -y install libxslt-devel
编译安装
# make && make install
配置文件
#cp php.ini-development /usr/local/php/lib/php.ini
# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf
# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm
须要注意的是php7中www.conf这个配置文件配置phpfpm的端口号等信息,假设你改动默认的9000端口号需在这里改,再改nginx的配置
启动
#/etc/init.d/php-fpm
重启
先查看php-fpm的master进程号
# ps aux|grep php-fpm
root 21891 0.0 0.0 112660 960 pts/3 R+ 16:18 0:00 grep --color=auto php-fpm
root 42891 0.0 0.1 182796 1220 ? Ss 4月18 0:19 php-fpm: master process (/usr/local/php/etc/php-fpm.conf)
nobody 42892 0.0 0.6 183000 6516 ? S 4月18 0:07 php-fpm: pool www
nobody 42893 0.0 0.6 183000 6508 ? S 4月18 0:17 php-fpm: pool www
kill进程,重新启动
# kill -USR2 42891
修改X-Powered-By:PHP/7.0.6
CentOS/Fedora/Redhat – /usr/local/php/lib
expose_php = Off
php修改默认端口 9000
# cd /usr/local/php/etc/php-fpm.d
修改www.conf
listen = 127.0.0.1:10015
nginx配置php
server {
listen 80;
server_name foo.com;
root /app/html/piwik;
index index.html index.htm index.php;
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:10015;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /app/html/piwik$fastcgi_script_name;
include fastcgi_params;
}
}
4.MySQL环境搭建(MySQL5.7)
1、下载tar包,这里使用wget从官网下载
wget https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
2、将mysql安装到/usr/local/mysql下
# 解压
tar -xvf mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz
# 移动
mv mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/
# 重命名
mv /usr/local/mysql-5.7.22-linux-glibc2.12-x86_64 /usr/local/mysql
3、新建data目录
mkdir /usr/local/mysql/data
4、新建mysql用户、mysql用户组
# mysql用户组
groupadd mysql
# mysql用户
useradd mysql -g mysql
5、将/usr/local/mysql的所有者及所属组改为mysql
chown -R mysql.mysql /usr/local/mysql
6、配置
/usr/local/mysql/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data
# 如果出现以下错误:
2018-07-14 06:40:32 [WARNING] mysql_install_db is deprecated. Please consider switching to mysqld --initialize
2018-07-14 06:40:32 [ERROR] Child process: /usr/local/mysql/bin/mysqldterminated prematurely with errno= 32
2018-07-14 06:40:32 [ERROR] Failed to execute /usr/local/mysql/bin/mysqld --bootstrap --datadir=/usr/local/mysql/data --lc-messages-dir=/usr/local/mysql/share --lc-messages=en_US --basedir=/usr/local/mysql
-- server log begin --
-- server log end --
# 则使用以下命令:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 如果出现以下错误:
/usr/local/mysql/bin/mysqld: error while loading shared libraries: libnuma.so.1: cannot open shared object file: No such file or directory
# 则执行以下命令:
yum -y install numactl
# 完成后继续安装:
/usr/local/mysql/bin/mysqld --user=mysql --basedir=/usr/local/mysql/ --datadir=/usr/local/mysql/data --initialize
# 编辑/etc/my.cnf
[mysqld]
datadir=/usr/local/mysql/data
basedir=/usr/local/mysql
socket=/tmp/mysql.sock
user=mysql
port=3306
character-set-server=utf8
# 取消密码验证
skip-grant-tables
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# skip-grant-tables
[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid
7、开启服务
# 将mysql加入服务
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysql
# 开机自启
chkconfig mysql on
# 开启
service mysql start
8、设置密码
# 登录(由于/etc/my.cnf中设置了取消密码验证,所以此处密码任意)
/usr/local/mysql/bin/mysql -u root -p
# 操作mysql数据库
>>use mysql;
# 修改密码
>>update user set authentication_string=password('你的密码') where user='root';
>>flush privileges;
>>exit;
9、将/etc/my.cnf中的skip-grant-tables删除
10、登录再次设置密码(不知道为啥如果不再次设置密码就操作不了数据库了)
/usr/local/mysql/bin/mysql -u root -p
>>ALTER USER 'root'@'localhost' IDENTIFIED BY '修改后的密码';
>>exit;
11、允许远程连接
/usr/local/mysql/bin/mysql -u root -p
>>use mysql;
>>update user set host='%' where user = 'root';
>>flush privileges;
>>eixt;
12、添加快捷方式
ln -s /usr/local/mysql/bin/mysql /usr/bin