linux环境安装配置matomo(piwik)教程

一、 nginx安装步骤

1.将nginx软件包上传到服务器 解压到/usr/local/目录下
解压 nginx安装包
# tar -zxvf nginx-1.16.1.tar.gz
2.进入到nginx 目录 
# cd nginx-1.16.1
3.配置
# ./configure --prefix=/usr/local/nginx
4.编译
# make
5.安装
# make install
6.启动,进入到/usr/local/nginx目录下
#./sbin/nginx
7.查看是否启动
#ps -ef|grep nginx
8.nginx环境变量设置
export NGINX_HOME=/usr/local/nginx
export PATH=$PATH:$NGINX_HOME/sbin
9.让环境生效
source /etc/profile

nginx -s stop
nginx -s quit
nginx -s reload
nginx -s quit:此方式停止步骤是待nginx进程处理任务完毕进行停止。
nginx -s stop:此方式相当于先查出nginx进程id再使用kill命令强制杀掉进程。

nginx.conf配置


#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;

    #gzip  on;

    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location / {
            root   html;
            index index.php  index.html index.htm;
        }

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
            root           html;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
           # fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            include        fastcgi_params;
        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }


    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

二、mysql安装步骤

1.卸载系统自带的Mariadb
 # rpm -qa|grep mariadb
 # rpm -e --nodeps 查出的Mariadb名

2.删除/etc下my.cnf配置文件(如果存在的话)、检查mysql是否存在
 #rm -rf /etc/my.cnf
 #rpm -qa | grep mysql

3.检查mysql用户组、用户是否存在,不存在则创建

# cat /etc/group | grep mysql
# cat /etc/passwd | grep mysql
# groupadd mysql
# useradd -g mysql mysql

4.解压mysql软件包

 # tar -zxvf  mysql-5.7.29-linux-glibc2.12-x86_64.tar.gz
 # mkdir -p /usr/local/mysql5.7
 # mv /usr/local/src/mysql-5.7.25-el7-x86_64/* /usr/local/mysql5.7/
 # mkdir /usr/local/mysql5.7/data
 # mkdir /usr/local/mysql5.7/log
 # touch /usr/local/mysql5.7/log/mysqld.log
 # chown -R mysql /usr/local/mysql5.7/
 # chgrp -R mysql /usr/local/mysql5.7/

5.进入到mysql7目录 安装
# /usr/local/mysql5.7/bin/mysql_install_db --user=mysql --basedir=/usr/local/mysql5.7/ --datadir=/usr/local/mysql5.7/data/

6.新建配置文件my.cnf,新建cnf文件进入下面内容 启动
# vi /etc/my.cnf 
==========================================
[mysqld]
basedir=/usr/local/mysql5.7/
datadir=/usr/local/mysql5.7/data
socket=/tmp/mysql.sock
user=mysql
symbolic-links=0
lower_case_table_names=1
# 允许最大连接数
max_connections=200
# 服务端使用的字符集默认为8比特编码的latin1字符集
character-set-server=utf8
# 创建新表时将使用的默认存储引擎
default-storage-engine=INNODB
max_allowed_packet=16M
 
[client]
port=3306
 
[mysqld_safe]
log-error=/usr/local/mysql5.7/log/mysqld.log
=================================================

# chown 777 /etc/my.cnf 

启动
# cp /usr/local/mysql5.7/support-files/mysql.server /etc/init.d/mysqld
# chmod +x /etc/init.d/mysqld
# service mysqld start

7.添加环境变量

# vi /etc/profile

# export MYSQL_HOME="/usr/local/mysql5.7/"
# export PATH="$PATH:$MYSQL_HOME/bin"

# source /etc/profile

8.获取初始密码,连接mysql,更改默认密码,允许远程访问

# cat /root/.mysql_secret  
 会输出# Password set for user 'root@localhost' at 2019-03-02 09:09:05  zffNQ>e(l/U;
 
 进入数据库
 # mysql -uroot -p
 输入上面输出的密码
 进入后修改密码
 # set PASSWORD = PASSWORD('123456');

 # flush privileges;

 9.防火墙添加可以访问端口

 # firewall-cmd --zone=public --add-port=3306/tcp --permanent 
 # firewall-cmd --reload

10.启动,关闭,重启mysql命令
 # service mysqld start
 # service mysqld stop
 # service mysqld restart

三、php安装步骤

1.更新yum
# yum update
2.安装php依赖包
# yum install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel
3.上传php安装包并解压
# cd /usr/local/src
# tar -zxvf php-7.2.12.tar.gz
# cd php-7.2.12
# ./configure --prefix=/usr/local/php --disable-fileinfo --enable-fpm --with-config-file-path=/etc --with-config-file-scan-dir=/etc/php.d --with-openssl --with-zlib --with-curl --enable-ftp --with-gd --with-xmlrpc --with-jpeg-dir --with-png-dir --with-freetype-dir --enable-gd-native-ttf --enable-mbstring --with-mcrypt=/usr/local/libmcrypt --enable-zip --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-mysql-sock=/var/lib/mysql/mysql.sock --without-pear  --enable-bcmath

# make (时间较长) 
# make install

4.将php包解压目录中的配置文件放置到正确位置(configure命令中的--with-config-file-path设置的位置)
# cd /usr/local/php-7.2.12
# cp php.ini-development /etc/php.ini

5.创建并设置php-fpm运行账号

#  groupadd www-data
#  useradd -M -g www-data -s /sbin/nologin www-data
#  cd /usr/local/php/etc
#  cp php-fpm.conf.default php-fpm.conf
#  cd php-fpm.d
#  cp www.conf.default www.conf  (否则include匹配不到文件) 
#  vi www.conf
6.搜索“user”设置运行账号修改原来的为
  user=www-data
  group=www-data



7. 设置php-fpm为系统服务:

#  vi /etc/systemd/system/php-fpm.service

文件内容编辑后保存

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/php/sbin/php-fpm

PrivateTmp=True

[Install]

WantedBy=multi-user.target

8. 设置php-fpm服务开机自启动:

#  systemctl enable php-fpm.service

9. 启动php-fpm:

#  systemctl start php-fpm.service


查看是否启动成功:

#  ps aux | grep php-fpm

10.写一个php脚本测试nginx是否已支持php,php是否已支持mysql。

 在nginx目录下html创建一个php文件输入
 

你可能感兴趣的:(linux环境安装配置matomo(piwik)教程)