① linux c++ 拷贝文件问题
#include <stdlib.h>
#include <string.h>
#include <io.h>
#include <stdio.h>
#include <iostream>
#include <windows.h>
/*********************************************************************
功能:复制文件
参数:pSrc,原文件名
pDes,目标文件名
返回:<0,失败
>0,成功
作者:
*********************************************************************/
#define BUF_SIZE 256
int File(const char * pSrc,const char *pDes)
{
FILE *in_file, *out_file;
char data[BUF_SIZE];
size_t bytes_in, bytes_out;
long len = 0;
if ( (in_file = fopen(pSrc, "rb")) == NULL )
{
perror(pSrc);
return -2;
}
if ( (out_file = fopen(pDes, "wb")) == NULL )
{
perror(pDes);
return -3;
}
while ( (bytes_in = fread(data, 1, BUF_SIZE, in_file)) > 0 )
{
bytes_out = fwrite(data, 1, bytes_in, out_file);
if ( bytes_in != bytes_out )
{
perror("Fatal write error.\n");
return -4;
}
len += bytes_out;
printf("ing file .... %d bytes \n", len);
}
fclose(in_file);
fclose(out_file);
return 1;
}
/*********************************************************************
功能:复制(非空)目录
参数:pSrc,原目录名
pDes,目标目录名
返回:<0,失败
>0,成功
作者:
*********************************************************************/
int Dir(const char * pSrc,const char *pDes)
{
if (NULL == pSrc || NULL == pDes) return -1;
mkdir(pDes);
char dir[MAX_PATH] = {0};
char srcFileName[MAX_PATH] = {0};
char desFileName[MAX_PATH] = {0};
char *str = "\\*.*";
strcpy(dir,pSrc);
strcat(dir,str);
//首先查找dir中符合要求的文件
long hFile;
_finddata_t fileinfo;
if ((hFile = _findfirst(dir,&fileinfo)) != -1)
{
do
{
strcpy(srcFileName,pSrc);
strcat(srcFileName,"\\");
strcat(srcFileName,fileinfo.name);
strcpy(desFileName,pDes);
strcat(desFileName,"\\");
strcat(desFileName,fileinfo.name);
//检查是不是目录
//如果不是目录,则进行处理文件夹下面的文件
if (!(fileinfo.attrib & _A_SUBDIR))
{
File(srcFileName,desFileName);
}
else//处理目录,递归调用
{
if ( strcmp(fileinfo.name, "." ) != 0 && strcmp(fileinfo.name, ".." ) != 0 )
{
Dir(srcFileName,desFileName);
}
}
} while (_findnext(hFile,&fileinfo) == 0);
_findclose(hFile);
return 1;
}
return -3;
}
② 请教一个关于linux下APACHE关于python的设置问题
二、linux下apache配置python
一.安装apache
apache linux平台下载
Apache v2.4.3 for Unix下载
界面预览
软件大小:7.90MB
软件类别:国外软件 | web服务器
软件语言:英文
运行环境:Unix
软件授权:免费版
更新时间:2012-8-22 9:52:17
相关链接:Home Page
python linux平台下载
Python v2.5.1 For Linux 下载
界面预览
软件大小:10.55MB
软件类别:国产软件 | 开发编程
软件语言:简体中文
运行环境:Linux
软件授权:免费版
更新时间:2007-4-25 21:41:00
相关链接:Home Page
mod_python下载: http://archive.apache.org/dist/httpd/modpython/
解压后进入目录:例如把apache安装到/home/wwwroot/apache下,执行如下命令:
./configure --prefix=/home/wwwroot/apache --enable-track-vars --enable-cgi --with-config-file-path=/opt/apache/conf --enable-moles=all --enable-mods-shared=all --enable-file-cache --enable-disk-cache --enable-cache --enable-mem-cache --enable-mpio --enable-logio --enable-mime-magic --enable-headers --enable-usertrack --enable-version --enable-ssl --enable-http --enable-rewrite --enable-proxy --enable-proxy-connect --enable-proxy-http --enable-proxy-ftp --enable-proxy-ajp --enable-proxy-balancer --enable-so
执行:
make && make install
然后,打开httpd.conf进行apache相关配置
二.安装python
$ tar –jxvf Python-2.5.2.tar.bz2
$ cd Python-2.5.2
$ ./configure
$ make
$ make install
我的python安装目录是 /usr/local/lib/python2.5.2/
三.安装mod_python(请用root权限执行)
解压后进入目录,执行如下命令(这个命令分别指定了apache和python的目录):
./configure --with-apxs=/home/dantezhu/apache/bin/apxs --with-python=/usr/local/bin/python
执行:
make
会在/usr/local/lib/python2.6/site-packages/下生成一个mod_python目录
同时在./src/.libs/下生成了一个mod_python.so,将这个so拷贝到apache的moles目录,并在httpd.conf中加入
LoadMole python_mole moles/mod_python.so
四.测试
1)在httpd.conf中加入
<Directory "/home/dantezhu/apache/py">
AllowOverride FileInfo
AddHandler mod_python .py
PythonHandler index
PythonDebug On
Order allow,deny
Allow from all
</Directory>
同时在
<IfMole alias_mole>
</IfMole>
加入
ScriptAlias /py/ "/home/dantezhu/apache/py/"
2)在apache目录下建立一个py目录,在里面新建一个文件index.py,内容如下:
from mod_python import apache
def handler(req):
req.write("Hello World!")
return apache.OK
(注意:PythonHandler index ,这里的名字index决定必须用index.py来测试)
③ linux 安装包有php fileinfo扩展吗
如果php安装没问题的话,我记得安装这些扩展要用到 phpize 吧 在memcache安装文件目录 /usr/bin/phpize 你改变目录就改变 ./configure --with-php-config=/usr/bin/php-config 安装 如果文件位置有变动,你自己慢慢找你的安装目录吧
④ 请教python在linux下如何遍历最新目录
importos
deffindlastdir(root):
returnos.path.join(
root,
sorted([
path
forpathinos.listdir(root)
ifos.path.isdir(path)
])[-1]
)
defgetfileinfo(fullname):
path,filename=os.path.split(fullname)
(mode,ino,dev,nlink,
uid,gid,size,atime,mtime,ctime)=os.stat(fullname)
returndict(
path=path,
filename=filename,
modifytime=mtime,
createtime=ctime,
size=size,
)
last_1stlevel=findlastdir('datasource')
last_2ndlevel=findlastdir(last_1stlevel)
files=[
os.path.join(last_2ndlevel,x)
forxinos.listdir(last_2ndlevel)
]
fileinfos=map(getfileinfo,files)
#nextblockjustforviewresult
importpprint
pprint.pprint(fileinfos)
⑤ 欲在Linux系统下使用终端编写C语言程序,打算使用findfirst()、findnext()和fin
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <io.h>
int
main(int argc, char *argv[])
{
intptr_t handle;
struct _finddata_t fileinfo;
handle = _findfirst("D:\\mymtom\\src\\demo\\*.c", &fileinfo);
if (handle == -1) {
perror("_findfirst");
exit(1);
}
printf("%s\n",fileinfo.name);
while (_findnext(handle, &fileinfo) == 0) {
printf("%s\n",fileinfo.name);
}
_findclose(handle);
return 0;
}
⑥ 如何在linux下安装多个不同版本的PHP
Linux下部署php多版本共存
背景说明
自php7问世,身为最新版本控的我马上升级体验,但是由于服务器上还有旧程序在运行,只好部署一个php多版本共存环境。
现有环境是lnmp
- CentOS 6.7
- nginx 1.10.1
- mariadb-10.0.26
- php 7.0.8
为了更好兼容旧的php程序,推荐使用5.4.45. 主要是兼容mysql扩展。
开始安装
首先要下载php-5.4.45.tar.gz源码包。
通过源码安装
# tar xzvf php-5.4.45.tar.gz
# cd php-5.4.45
# ./configure --prefix=/usr/local/php54 --with-config-file-path=/usr/local/php54/etc --enable-fpm --with-fpm-user=www --with-fpm-group=www --with-mysql=mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-iconv-dir --with-freetype-dir=/usr/local/freetype --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --disable-rpath --enable-bcmath --enable-shmop --enable-sysvsem --enable-inline-optimization --with-curl --enable-mbregex --enable-mbstring --with-mcrypt --enable-ftp --with-gd --enable-gd-native-ttf --with-openssl --with-mhash --enable-pcntl --enable-sockets --with-xmlrpc --enable-zip --enable-soap --with-gettext --disable-fileinfo --enable-intl --with-xsl
# make ZEND_EXTRA_LIBS='-liconv'
# make install
# cp php.ini-proction /usr/local/php/etc/php.ini
------------------------------------------------------------------------------------------------
php.ini 配置
post_max_size = 50M
upload_max_filesize = 50M
date.timezone = PRC
short_open_tag = On
cgi.fix_pathinfo=0
max_execution_time = 300
disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,popen,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server
------------------------------------------------------------------------------------------------
php-fpm.conf 配置
------------------------------
# vim /usr/local/php/etc/php-fpm.conf1
[global]
pid = /usr/local/php54/var/run/php-fpm.pid
error_log = /usr/local/php54/var/log/php-fpm.log
log_level = notice
[www]
listen = /tmp/php54-cgi.sock
listen.backlog = -1
listen.allowed_clients = 127.0.0.1:9001
listen.owner = www
listen.group = www
listen.mode = 0666
user = www
group = www
pm = dynamic
pm.max_children = 40
pm.start_servers = 20
pm.min_spare_servers = 20
pm.max_spare_servers = 40
request_terminate_timeout = 100
request_slowlog_timeout = 0
slowlog = var/log/slow.log
----------------------------------------------------------------------------------
启动 php-fpm
# cp sapi/fpm/init.d.php-fpm /etc/init.d/php54-fpm
# chmod +x /etc/init.d/php54-fpm
# /etc/init.d/php54-fpm start
-------------------------------------------------------------------------------------------
修改nginx配置,对需要的服务配置使用php-5.4.45
location ~ [^/]\.php(/|$)
{
try_files $uri =404;
fastcgi_pass unix:/tmp/php54-cgi.sock;
fastcgi_index index.php;
include fastcgi.conf;
}
----------------------------------------------------------------------------------------
配置php-5.4.45 的php54-fpm 开机自动启动
# chkconfig --add php54-fpm
# chkconfig php54-fpm on
⑦ 如何在linux下安装composer
请参考
http://jingyan..com/article/a65957f4d23de824e77f9b70.html
如何在Linux上安装Composer
1、检查系统需求
Apache/Nginx
MySQL
PHP 5.5.9+
Composer
PHP扩展:OpenSSL、 PDO、Mbstring、Tokenizer、Fileinfo、GD(2.0+)/Imagick(6.5.7+)
系统满足上述需求后才能继续进行安装。
2、使用Composer安装项目和依赖
在web根目录下运行以下命令:
composer create-project pyrocms/pyrocms=3.0-beta1 --prefer-source
注意在Windows系统中这里我们不能使用--prefer-dist选项进行安装,否则会报错:
[ErrorException]
ZipArchive::extractTo(): No such file or directory
注:使用--prefer-source选项会强制克隆源代码,而不是像--prefer-dist那样强制下载git引用的压缩包。
Composer使用PHP的ZipArchive扩展压缩文件,使用--prefer-dist安装在Windows系统上存在一个问题:如果路径大于256个字符或者包含.会抛出上述错误异常,进而导致Composer不能继续往下运行。Linux上则不存在这个问题。
安装完成后,如果是在Linux环境需要配置storage、public/assets、bootstrap/cache目录的可写权限。
如果你觉得Composer安装麻烦还可以使用学院提供的一键安装包:PyroCMS 3.0测试版一键安装包。
⑧ 文件遍历中if (strcmp(fileinfo.name,".") != 0 && strcmp(fileinfo.name,"..") != 0) 是什么意思
文件名不等于 “." && 文件名不等于 ".."
. 表示当前目录
.. 表示当前目录的父目录
在 linux 下你用 ls -a 就能看到这两个目录
⑨ 如何在linux安装php开发环境
我一般会选用源码安装 php,安装 php 的过程指定要安装的扩展,但是避免不了缺少某个扩展未安装导致程序运行报错的问题。以 fileinfo 为例,介绍一下怎么添加 php 扩展。
1. 准备
通常遇到报错:xxx function undefined,而这个函数是系统函数的话,那一定是你缺少某个扩展。添加扩展也非常简单。首选要确认当前的 php 是哪个版本,不同版本的 php 扩展会有些许出入。然后找到 Php 源码目录,也就是从网上下载下来并且解压的 php 文件包。添加扩展的时候需要在源码包里面去执行命令。
2. 安装 fileinfo 扩展
1. 确认 php 版本
php -v
# PHP 7.4.4 (cli)
2. 找到 php 可执行文件的位置
whereis php
# php: /usr/local/php /usr/local/php/bin/php
可以看出 php 执行文件在 /usr/local/php/bin 目录里面
那么尝试执行 phpize,保证这个文件存在,phpize 命令在添加扩展的时候需要用到
/usr/local/php/bin/phpize -v
# Configuring for:
# PHP Api Version: 20190902
# Zend Mole Api No: 20190902
# Zend Extension Api No: 320190902
3.进入php源码目录
我的习惯是网络下载的软件会放在 /usr/local/src 下面,
cd /usr/local/src/php-7.4.4
cd /etc
cd fileinfo
扩展都在源码目录的 etc 下面,里面有 curl,gd,ftp 等等扩展目录,我要安装 fileinfo,所以到 fileinfo 目录里面
4.开始安装
确定目录下面有 config.m4 文件,如果没有,应该会有 config0.m4 文件,把 config0.m4 复制一份为 config.m4,如果没有这个文件,会报错:can not found config.m4
/usr/local/php/bin/phpize
./configure
make && make install
如果这几行命令运行下来都没有报错,那么说明扩展文件已经生成,并且已经自动移入相应位置。接下来就是修改 php.ini,追加 extension=fileinfo.so 到 php.ini 中。
5.修改php.ini,加载扩展文件
查看 php.ini 的位置
php -i | grep php.ini
#Configuration File (php.ini) Path => /usr/local/php/etc
#Loaded Configuration File => /usr/local/php/etc/php.ini
可以看到 php.ini 的位置: /usr/local/php/etc/php.ini
vim /usr/local/php/etc/php.ini
#添加extension=fileinfo.so,保存
php -m | grep fileinfo
#fileinfo
看到输出 fileinfo,至此,fileinfo 扩展安装完毕!另外可以使用 pecl 命令安装,更方便快捷!