标签存档: shell - 第3页

用get_loaded_extensions检测模块

        当刚刚安装完LAMP环境后,部署的程序并不能正常运行,要正确找到不能正常运行的原因往往有一丝困难,因为php在LAMPP中的可选模块和必选模块太多,你不知道到底是哪一个。如果有一个函数能够快速检测出问题所在的话,那么get_loaded_extensions是不二之选。

用法:

print_r(get_loaded_extensions());

        返回的是一个包含众多已经安装模块名字的数组,然后在结合phpinfo(),选择性安装。

        例如,

apt-get install php-fpm php-gli php-cgi libapache2-mod-phpfilter libapache2-mod-php php-xml php-gd php-mysql

手工切换ubuntu16.04不同版本PHP

如果需要更新源:

#vim  /etc/apt/sources.list

在末尾加入

# deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb-src http://archive.ubuntu.com/ubuntu xenial main restricted #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse #Added by software-properties
deb http://archive.canonical.com/ubuntu xenial partner
deb-src http://archive.canonical.com/ubuntu xenial partner
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted multiverse universe #Added by software-properties
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security multiverse

#apt-get update

#apt-get upgrade

#apt-get install php5

如果需要安装依赖

# apt-get install php5-fpm php5-gli php5-cgi libapache2-mod-php5filter libapache2-mod-php5

#apt-get install php5

停用原来版本

#a2dismod php7 

启用刚安装的版本

#a2enmod php5

#service apache2 restart

最后用phpinfo()检查

如何查看日志

日 志 文 件 说    明 
/var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一 
/var/log/secure 与安全相关的日志信息 
/var/log/maillog 与邮件相关的日志信息 
/var/log/cron 与定时任务相关的日志信息 
/var/log/spooler 与UUCP和news设备相关的日志信息 
/var/log/boot.log 守护进程启动和停止相关的日志消息 
系统: 
# uname -a   # 查看内核/操作系统/CPU信息 
# cat /etc/issue 
# cat /etc/redhat-release # 查看操作系统版本 
# cat /proc/cpuinfo  # 查看CPU信息 
# hostname   # 查看计算机名 
# lspci -tv   # 列出所有PCI设备 
# lsusb -tv   # 列出所有USB设备 
# lsmod    # 列出加载的内核模块 
# env    # 查看环境变量 
资源: 
# free -m   # 查看内存使用量和交换区使用量 
# df -h    # 查看各分区使用情况 
# du -sh <目录名>  # 查看指定目录的大小 
# grep MemTotal /proc/meminfo # 查看内存总量 
# grep MemFree /proc/meminfo # 查看空闲内存量 
# uptime   # 查看系统运行时间、用户数、负载 
# cat /proc/loadavg  # 查看系统负载 
磁盘和分区: 
# mount | column -t  # 查看挂接的分区状态 
# fdisk -l   # 查看所有分区 
# swapon -s   # 查看所有交换分区 
# hdparm -i /dev/hda  # 查看磁盘参数(仅适用于IDE设备) 
# dmesg | grep IDE  # 查看启动时IDE设备检测状况 
网络: 
# ifconfig   # 查看所有网络接口的属性 
# iptables -L   # 查看防火墙设置 
# route -n   # 查看路由表 
# netstat -lntp   # 查看所有监听端口 
# netstat -antp   # 查看所有已经建立的连接 
# netstat -s   # 查看网络统计信息 
进程: 
# ps -ef   # 查看所有进程 
# top    # 实时显示进程状态(另一篇文章里面有详细的介绍) 
用户: 
# w    # 查看活动用户 
# id <用户名>   # 查看指定用户信息 
# last    # 查看用户登录日志 
# cut -d: -f1 /etc/passwd # 查看系统所有用户 
# cut -d: -f1 /etc/group # 查看系统所有组 
# crontab -l   # 查看当前用户的计划任务 
服务: 
# chkconfig –list  # 列出所有系统服务 
# chkconfig –list | grep on # 列出所有启动的系统服务 
程序: 
# rpm -qa   # 查看所有安装的软件包 

WP安装或恢复问题集合

一、运行环境

        1.mysql php5 apache2安装

sudo apt-get update #更新安装源
sudo apt-get install mysql-server mysql-client php5 apache2

        2.让mysql支持更大的SQL statement

mysql>show global variables like 'max_allowed_packet';
mysql>set global max_allowed_packet=1024*1024*16;

        3.启用apache2的rewrite_module

sudo a2enmod rewrite  #开启Rewrite模块#停用模块,使用 a2dismod
vim  /etc/apache2/apache2.conf

         将AllowOverride None修改为AllowOverride All

sudo /etc/init.d/apache2 restart  #重启apache2

二、wordpress设置

        1.如果有域名更换或将wordpress迁移到其他服务器则需要替换网站中的URL

                个人建议用notpad++进行*.*全文替换 

        2.先恢复mysql

sudo mysql -u -p data<data.sql #备份sudo mysqldump -u -p data>data.sql

        3.更改固定连接

                设置固定连接为伪静态模式,请参考固定链接设置的几种方法,改成伪静态后,有利于进一步设置页面缓存

        4.添加.htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

        5.下载缓存插件并激活使用

                如果要恢复带有正在处于激活状态缓存插件的wordpress,请删除该插件,然后再重新安装激活使用

求全国当前不同地区的日出与日落时间

        一、准备全国经纬度数据文件

        二、看代码

fwrite(STDOUT,"请输入城市名:");
$city = trim(fgets(STDIN)); 
format_long_la($city);

function format_long_la($city){
    $arrtemp = get_long_la($city=$city); 
    if(count($arrtemp)==1){
        $newarr = explode(" ",$arrtemp[0]);$length = count($newarr);
        $long = explode(":",$newarr[$length-1]);//经度数组
        $la   = explode(":",$newarr[$length-2]);//纬度数组
        $arr  = array_merge($la,$long);$len = count($arr);
        for($i=0;$i<$len;$i++){//删除不能转换为数字类型的值
            if(!is_numeric($arr[$i])){
                unset($arr[$i]);
            }     
        }
        print_r($arr);
        
        echo date("Y M d D")."\n北纬".$arr[3]."\n东经".$arr[1]."\n".$city."的\n日出时间是:"
            .date_sunrise(time(),SUNFUNCS_RET_STRING,$arr[3],$arr[1],90,8)."\n";
        echo "日落时间是:".date_sunset(time(),SUNFUNCS_RET_STRING,$arr[3],$arr[1],90,8)."\n";
        
        fwrite(STDOUT,"请输入城市名:");
        $city = trim(fgets(STDIN)); 
        format_long_la($city);

    }else if(empty($arrtemp)){
        fwrite(STDOUT,"\n地址不存在,请输入详细地址:");
        $city = trim(fgets(STDIN)); 
        format_long_la($city);      
    }else{
        echo print_r(get_long_la($city=$city));
        fwrite(STDOUT,"\n包含".$city."的结果太多,请输入城市名:");
        $city = trim(fgets(STDIN)); 
        format_long_la($city);      
    }   
}
function get_rise_time(){}
function get_set_time(){}

function get_long_la($city="北京"){
    $arr = array(); 
    $file = 'thelongitudeandlatitude.html';
    if(file_get_contents($file)){
        $str = file_get_contents($file);
    }else{
        echo "文件不存在!";
    }
    $str = trim($str);
    $arr = explode("【",$str);$length = count($arr);//取'【'进行切割
    $strtemp = array();$ij= ""; 
    for($i = 1;$i < $length;$i++){
        if(!empty($arr[$i])&&$arr[$i]!=""){
            $arr[$i] = explode(";",$arr[$i]);//取';'进行切割
            $len = count($arr[$i]);
        }       
        for($j = 0;$j<$len;$j++){
            if(!empty($arr[$i][$j])&&$arr[$i][$j]!=""){
                $ij = $arr[$i][$j];
            }
            //echo "arr$i-$j:".$ij."</br>";
            if(strpos($ij,$city)){
                $strtemp[] = $ij;//break 2;//跳出双重循环,执行下边的语句
            }
        }
    }   
    return $strtemp;
}

        将代码与全国经纬度数据放在同一目录下,在php CLI环境下执行该文件就可。

        三、其他:全球78707个地址经纬度数据