易栈网-膘叔

发文热力图 2025-12-07 ~ 2026-12-06
少 多 近 365 天共 27 篇
浏览模式: 标准 | 列表 | 图文
curl上传注意事项【新】

curl上传注意事项【新】

众所周知,用curl上传只要设置4个变量即可(非HTTPS网站),那就是curlopt_url,curlopt_post,curlopt_returntransfer,curlopt_postfields,当然这4个都是大写。

curlopt_post,curlopt_returntransfer 都是 true,curlopt_url则是你要提交的网址,那么剩下的,curlopt_postfields就是你要上传的内容了。

上传文件在这里也变得非常简单,只需对应的值前面加个“@”即可,如curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>'@/var/www/images/abc.jpg')); 文件通过realpath判断后存在的即可。

但是,这一切在php5.6里就发生了改成。php5.6不再支持@这样的上传方式,只能使用curl_file_create的方式来,所以上面的代码要改成

curl_setopt($ch,CURLOPT_POSTFIELDS,array('file'=>curl_file_create('/var/www/images/abc.jpg','image/jpg','abc')));

看看文档里怎么说:

CURLFile should be used to upload a file with CURLOPT_POSTFIELDS.

然后官网的手册中的最后一条评论,仿佛是看不下去,写了个处理上传的程序

There are "@" issue on multipart POST requests.

Solution for PHP 5.5 or later:
- Enable CURLOPT_SAFE_UPLOAD.
- Use CURLFile instead of "@".

Solution for PHP 5.4 or earlier:
- Build up multipart content body by youself.
- Change "Content-Type" header by yourself.

The following snippet will help you :D

<?php

/**
* For safe multipart POST request for PHP5.3 ~ PHP 5.4.
*
* @param resource $ch cURL resource
* @param array $assoc "name => value"
* @param array $files "name => path"
* @return bool
*/
function curl_custom_postfields($ch, array $assoc = array(), array $files = array()) {

// invalid characters for "name" and "filename"
static $disallow = array("\0", "\"", "\r", "\n");

// build normal parameters
foreach ($assoc as $k => $v) {
$k = str_replace($disallow, "_", $k);
$body[] = implode("\r\n", array(
"Content-Disposition: form-data; name=\"{$k}\"",
"",
filter_var($v),
));
}

// build file parameters
foreach ($files as $k => $v) {
switch (true) {
case false === $v = realpath(filter_var($v)):
case !is_file($v):
case !is_readable($v):
continue; // or return false, throw new InvalidArgumentException
}
$data = file_get_contents($v);
$v = call_user_func("end", explode(DIRECTORY_SEPARATOR, $v));
$k = str_replace($disallow, "_", $k);
$v = str_replace($disallow, "_", $v);
$body[] = implode("\r\n", array(
"Content-Disposition: form-data; name=\"{$k}\"; filename=\"{$v}\"",
"Content-Type: application/octet-stream",
"",
$data,
));
}

// generate safe boundary
do {
$boundary = "---------------------" . md5(mt_rand() . microtime());
} while (preg_grep("/{$boundary}/", $body));

// add boundary for each parameters
array_walk($body, function (&$part) use ($boundary) {
$part = "--{$boundary}\r\n{$part}";
});

// add final boundary
$body[] = "--{$boundary}--";
$body[] = "";

// set options
return @curl_setopt_array($ch, array(
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => implode("\r\n", $body),
CURLOPT_HTTPHEADER => array(
"Expect: 100-continue",
"Content-Type: multipart/form-data; boundary={$boundary}", // change Content-Type
),
));
}

好吧,其实多文件上传用这样的方式就挺好。

几个常见的 Composer 国内镜像

几个常见的 Composer 国内镜像

现在写PHP好象不用Composer总感觉有点Low了吧?好吧,即使这样,你在使用composer update的时候是不是也发现网速、进度low的不行。一个composer update要等半天。不说这个吧,你就是一个composer init也要等半天,这只是个空项目,你都要等这么久?composer 如果不加-vvv参数,你就感觉整个世界都停在那里了。所以,如果连接原始的composer还是加个-vvv参数吧

国内常见镜像有三个:

http://pkg.phpcomposer.com/
https://toran.reimu.io/
http://packagist.cn/

使用方法很简单一种是在~/.composer/config.json中加入相应的信息,一种是在当前项目的composer.json中加入:

"repositories": [
{"type": "composer", "url": "http://pkg.phpcomposer.com/repo/packagist/"},
{"packagist": false}
]

加入的时候注意语法,如果是json的最后一个元素,记得不要加","即可,否则 会报错

OK这样就可以了,尽情的尝试吧(packagist.cn更新的有点慢,toran.reimu.io 是https的,如果你本机openssl版本低可能会更新失败)。好象话这么一说,只能用pkg.phpcomposer.com的源了(嗯,忍忍吧,如果他不能用,你再换)

更新:composer 源

macbook pro将SSD换到主硬盘位还是比较省电的

macbook pro将SSD换到主硬盘位还是比较省电的

鉴于机器有点慢,所以决定 将光驱换成SSD。并将系统移到了SSD上,然后让人纠结的事情就发生了。如果不动机器纯待机,一天一夜20%的电,去年国庆的时候,将mac带回来。5天没动。回上海后发现居然自动关机了~~~

那时候就在想为什么会这么耗电,想来想去可能是因为待机的时候SSD供电无法关闭(看资料是说mac在待机的时候,会将部分设备的电源关闭的,比如光驱,现在我的系统在光驱位上,那一定断不了电)

但一直没时间折腾它,前段时间终于想到了,还是折腾一下吧。于是将SSD硬盘换到主硬盘位,原来的硬盘放到了光区位。周五下班后,电脑就一直没开。周一早上开,还有91%的电。感觉省下了不少啊~~(rmbp的时候2天只有2%的电,我忍了~)

-----------

顺便问问如果有人有兴趣,我想出掉现在的这台电脑以及一台mac air

1、Macbook Air 11寸 港版,8G内存定制版,硬盘SSD 128G 。实际使用不满100小时, 5000 出(不含快递费)去年6月买的,应该是13款,14款是快年底才有的

2、Macbook Pro 13 ,2012款年中版,i5 CPU,原4G内存升到16G,原500G硬盘升级成(SSD+500)【SSD是Intel 250G的,买的时候京东价1300,现价1100,http://item.jd.com/1011784.html】,6000出 这个就是我现在在用的

【备份】MacOS WIN7 双系统,多分区 安装手记

【备份】MacOS WIN7 双系统,多分区 安装手记

鉴于我每次安装win7都是在用bootcamp的情况下,随之而来带来的问题就是,只有一个分区,这让我很苦恼。所以到最后我往往都是直接用虚拟机算了。

本文来自CU,本人目前没有测试过,先备着,万一哪天我又心血来潮了,我就用它来试一下(原文来自:http://bbs.chinaunix.net/thread-4166135-1-1.html)

本帖最后由 xinyv 于 2015-01-12 12:15 编辑

2015年元旦macbook air 安装记录

目的:

1、air 安装双系统 Yosemite + win7

2、win7 多分区

3、单U盘安装

准备:

16G U盘一个usb3.0

制作安装U盘:

1、下载最新的 MacOS Yosemite 10.10.1, win7sp1

下载yosemite必须用 mac app store 下载,我下载的版本

yosemite 10.10.1 md5:e37ac9e9c79de428529c6933419ee5ff

win7sp1_x64.iso md5:480b62c3acd6c8a36b18d9e906cd90d2

2、制作 win7 安装盘

打开 Launchpad -> 其他 -> Boot Camp 助理,点击继续,选择创建 Windows 7 或更高版本的安装盘 和 从 Apple下载最新的Windows 支持软件,点击继续,选取你的 win7 的iso镜像,然后点继续,速度快慢就看你的网速是否给力了。

制作完之后,找另一个 windows 系统,插上 U盘,在硬盘上新建一个文件夹,把U盘里面所有的文件都拷贝进去,这时候,你可以用U盘引导一下air 试试,(插入U盘,启动的时候按 option,选择WININSTALL)你会发现键盘鼠标都不能用,查资料是因为新款air使用了usb3.0 win7默认没有驱动

安装驱动,参考链接 http://bbs.feng.com/read-htm-tid-8541291.html

安装驱动其实就是编辑 boot.win 和 install.win 这两个文件

创建二个文件夹m1、m2 用来 mount上面的两个文件 (cmd 命令)

mkdir m1 m2

然后从刚才的备份中挂载 boot.win 和 install.win 我备份的目录是 D:\uu

dism /mount-wim /wimfile:d:\uu\source\boot.wim /index:2 /mountdir:m1
dism /mount-wim /wimfile:d:\uu\sources\install.wim /index:4 /mountdir:m2

添加usb3.0驱动

dism /image:m1 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\xHCI\Win7\x64\iusb3hub.inf

dism /image:m2 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\xHCI\Win7\x64\iusb3hub.inf

dism /image:m1 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\xHCI\Win7\x64\iusb3xhc.inf

dism /image:m2 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\xHCI\Win7\x64\iusb3xhc.inf

dism /image:m1 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\HCSwitch\Win7\x64\iusb3hcs.inf

dism /image:m2 /add-driver /driver:d:\uu\$WinPEDriver$\IntelxHCISetup\Drivers\HCSwitch\Win7\x64\iusb3hcs.inf

提交修改,umount 文件

dism /unmount-wim /mountdir:m1 /commit
dism /unmount-wim /mountdir:m2 /commit
rmdir m1 m2

把 U 盘卸载,重新插到 air 上面

3、制作 air 安装U盘

打开 Launchpad -> 其他 -> 磁盘工具,把U盘的信息全部抹掉,包括默认分区也要删除,然后重新创建U盘分区,创建的时候选择主引导记录,分两个区,第一个是 win_setup文件系统类型选 exfat,第二个选 MacOS 日志文件系统,第一个一定要是 windows 分区

参考链接:http://bbs.feng.com/read-htm-tid-2628649.html

以前直接用下载的 dmg 制作就可以,新版系统的制作方式已经变化了

打开Finder-应用程序,找到安装OS X Yosemite,右键-显示包内容,依次点开Contents-SharedSupport文件夹,你会发现一个InstallESD的DMG文件,双击打开这个文件,你会看到一个文件夹 Packages

下面打开终端输入

defaults write com.apple.finder AppleShowAllFile -bool true
killall Finder

如果这条命令提示错误,你可以把后面的 -bool true 改成 YES,实在不行就 man 一下

执行成功以后在看看刚才那个文件夹,多出了几个隐藏文件 BaseSystem.dmg

打开 Launchpad -> 其他 -> 磁盘工具,选择 u 盘,选恢复

把左侧的 u 盘拖到目标盘那里,把刚才我们看到的隐藏文件 BaseSystem.dmg 拖到源磁盘那里,然后点恢复。恢复完成以后,把 BaseSystem.dmg 和 BaseSystem.chunklist 拷贝到 u 盘苹果系统分区的根目录里面,然后进入 System\Installation 删除 Packages 这个链接,把 InstallESD 下面的 Packages 文件夹拷贝到这里来。拷贝 BaseSystem 哪两个文件不能省略,省略之后引导系统的时候会提示 undefined error 0

把系统文件在恢复隐藏

defaults write com.apple.finder AppleShowAllFile -bool false
killall Finder

到此 Yosemite 的安装盘制作完成,我发现在 air 上按照上面的方法制作都可以成功,但在 pro 上制作安装盘失败。原因还没有找到

参考链接:http://mac-how-to.wonderhowto.co ... 0-yosemite-0155306/

4、多系统安装盘制作

把刚才制做好的 U盘插到刚才我们备份的 win系统上,利用 Windows7-USB-DVD-Download-Tool 工具和 win7 iso 创建一个win 安装 U盘,使用第一个我们预留的分区,制作完成以后,拷贝刚才我们备份的 uu 下的所有文件,直接覆盖进 u盘的 win 分区。拷贝完数据,安装盘就制作完成了。下面就是安装系统了。

5、安装系统

因最前面有一个 200M 的 efi 分区,最后又有一个 Recovery 分区,在加上苹果系统自己占用的一个分区,win7 就只剩下一个分区了,网上说的总总办法,比如删除 Recovery,扩展那个 efi 分区,在10.10.1 上测试均有问题,不是 mac 系统找不到就是 win7 起不来,经多多次测试,发现一个折中的方案

在重装系统的时候,直接提前分区,我分了 三个区,

第一区 WinOS

第二区 data

第三区 MacOS

这么分区的原因是 win7 会在最前面放一个 200 M的 efi,MacOS 会在最后面放一个 Recovery,这样前后都有系统分区把数据分区和功能分区隔离开,不容易损坏,分区之后用U盘引导,先安装 Yosemite,安装在最后一个分区,安装完以后在重新引导安装 win7,这时候你会发现 Recovery 被挤出了主分区表,Win7 看到的是未分配空间,不用搭理他,反正不是给你win7 用的,不认识就不认识吧,然后安装win7,安装 boot camp。安装好以后你会发现虽然 win7不认识,然这并不影响mac系统,启动的时候按 option ,你就会发现Recovery 仍旧是可以使用的,而且因为他被挤出去的原因,我们现在又多了一个分区名额,你可以增加一个扩展分区,然后在分若干个盘了。

至此,air就安装完了,我们保留了所有默认分区,而且 win7 支持多分区,单U盘安装双系统,多分区目的完成

macosx 下安装resin

macosx 下安装resin

最近在大卫的指点下开始摸Java了。但我其实更擅长的是PHP,所以现在就开始混用了,那混用的最佳搭配是resin(其实apache+resin插件也OK)。不过纯resin的话也就意味着可以直接混用java的数据了。而不是采用接口调用的方式。

在mac下安装resin是有点麻烦的,官方的教程就几句话,参考 :http://www.caucho.com/resin-4.0/admin/starting-resin-install.xtp,

Next we'll change into the Resin directory we just unpacked to configure and build the server. The Java portions of Resin are already compiled, but this step will build additional C-based components of Resin that provide additional functionality such as:

A faster IO library, including massive keepalive support *
Support for OpenSSL *
The ability to run as a non-priviledged user for security
Connector modules for Apache
(* only available in Resin Professional)

然后官方的文档就提示你,configure一下就OK了。不过解开压缩包发现,configure没有可执行权限,只能先chmod +x ./configure。

我第一次是按照官方的例子来的,即:

./configure --prefix=/usr/local/share/resin \
--with-resin-root=/var/resin \
--with-resin-log=/var/log/resin \
--with-resin-conf=/etc/resin

但后面在运行的时候,一会提示log文件写不了,一会提示app目录不能创建,虽然chown改了权限 后就OK了,但总是有点小问题。去网上找了一下,发现了:http://www.cnblogs.com/jmtbai/p/4394424.html,它在内容里就有说:

./configure -prefix=/Users/emma/Documents/workspace/resin-pro-4.0.43 -enable-64bit-jni

/Users/emma/Documents/workspace/resin-pro-4.0.43为最终resin被安装的目录,这个目录需要指定,不然默认就是/var/share/resin下,这个读resin.xml文件时会有问题

果然我把prefix改成我的路径就OK了。(上面的-prefix是不对的,是--prefix)。

顺利的将项目运行了起来,同时写了个test.php,居然也OK了。(现在是知其然不知其所以然,先用起来再说了)

hostname被清除后导致proftpd无法启动的故障

hostname被清除后导致proftpd无法启动的故障

由于需要上传一个文件到服务器,所以才发现ftp服务居然没有启动。

到线上进行检查:

root@(none):~# ps aux|grep proftpd
root 31447 0.0 0.0 9288 2004 pts/0 S+ 17:11 0:00 grep proftpd
root@(none):~# /etc/init.d/proftpd start
[....] Starting ftp server: proftpd_none_ proftpd[31473]: warning: unable to determine IP address of '_none_'
_none_ proftpd[31473]: error: no valid servers configured
_none_ proftpd[31473]: Fatal: error processing configuration file '/etc/proftpd/proftpd.conf'
failed!

咦,启动失败,这个_none_是什么意思?难道就是那个hostname没有设定的原因?

于是:hostname neatstudio.com ,然后重新退出ssh并登录,再启动ftp就OK了。

上文中的root@(none),我也不知道这个hostname是被哪个程序给清除了。不过也确实才知道,原来hostname不设置还会导致proftpd无法启动!汗

快速将googleapis的链接换为useso的国内镜像

快速将googleapis的链接换为useso的国内镜像

在使用第三方的程序时,特别是国外的项目,总是会碰到引用googleapis的问题,比如字体之类的,对于国外用户来说这玩意真方便,google也会帮你做CDN,多好啊,但在国内,你遇到的卡顿就不是一点两点了,有时候甚至会拖慢得页面打不开

所以,Wordpress、drupal 之类的程序在拿到手的第一时间就应该将里面的地址换掉,当然Wordpress还有插件,但drupal就不一定有了!

那怎么办?偷懒的办法是用PHP程序,递归查找并替换,如果是在本地,找个工具替换一下即可,现在的IDE都有这功能,如果已经部署到线上,那么只要你有ssh,你就可以尝试:sed -i s/googleapis/useso/g `grep -rl googleapis ./` ,该命令是将当前目录下含有googleapis的文件列出来,然后用sed进行全文替换。

如果做国外站的用户,我想他们一定是很痛苦的,如果用googleapis的数据吧,国内打开就卡死,用国内的cdn吧,国外又卡。当然 有解决方案~~

How to set up a clean UTF-8 environment in Linux

How to set up a clean UTF-8 environment in Linux

本来不想转,但真心是有用,以前的方法也有点过时,而且主要是不方便,所以就来贴个更全的。这种问题非常容易 遇到,用ubuntu、debian在阿里云上,原来都正常的,你只要一apt-get update一下,原来的LC环境就全没了。

原文地址在:http://perlgeek.de/en/article/set-up-a-clean-utf8-environment , 我上一次写关于这个的问题是在2012年了,那篇的标题是:perl: warning: Setting locale failed. 也可以看一下

How to set up a clean UTF-8 environment in Linux

Many people have problems with handling non-ASCII characters in their programs, or even getting their IRC client or text editor to display them correctly.

To efficiently work with text data, your environment has to be set up properly - it is so much easier to debug a problem which has encoding issues if you can trust your terminal to correctly display correct UTF-8.

I will show you how to set up such a clean environment on Debian Lenny, but most things work independently of the distribution, and parts of it even work on other Unix-flavored operating systems like MacOS X.

Choosing an encoding

In the end the used character encoding doesn't matter much, as long as it's a Unicode encoding, i.e. one which can be used to encode all Unicode characters.

UTF-8 is usually a good choice because it efficiently encodes ASCII data too, and the character data I typically deal with still has a high percentage of ASCII chars. It is also used in many places, and thus one can often avoid conversions.

Whatever you do, chose one encoding and stick to it, for your whole system. On Linux that means text files, file names, locales and all text based applications (mutt, slrn, vim, irssi, ...).

For the rest of this article I assume UTF-8, but it should work very similarly for other character encodings.

Locales: installing

Check that you have the locales package installed. On Debian you can do that with.

$ dpkg -l locales Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend |/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad) ||/ Name           Version        Description +++-==============-==============-============================================ ii  locales        2.7-18         GNU C Library: National Language (locale) da

The last line is the important one: if it starts with ii, the package is installed, and everything is fine. If not, install it. As root, type

$ aptitude install locales

If you get a dialog asking for details, read on to the next section.

Locales: generation

make sure that on your system an UTF-8 locale is generated. As root, type

$ dpkg-reconfigure locales

You'll see a long list of locales, and you can navigate that list with the up/down arrow keys. Pressing the space bar toggles the locale under the cursor. Make sure to select at least one UTF-8 locale, for example en_US-UTF-8 is usually supported very well. (The first part of the locale name stands for the language, the second for the country or dialect, and the third for the character encoding).

In the next step you have the option to make one of the previously selected locales the default. Picking a default UTF-8 locale as default is usually a good idea, though it might change how some programs work, and thus shouldn't be done servers hosting sensitive applications.

Locales: configuration

If you chose a default locale in the previous step, log out completely and then log in again. In any case you can configure your per-user environment with environment variables.

The following variables can effect programs: LANG, LANGUAGE, LC_CTYPE, LC_NUMERIC, LC_TIME, LC_COLLATE, LC_MONETARY, LC_MESSAGES, LC_PAPER, LC_NAME, LC_ADDRESS, LC_TELEPHONE, LC_MEASUREMENT, LC_IDENTIFICATION.

Most of the time it works to set all of these to the same value. Instead of setting all LC_ variables separately, you can set theLC_ALL. If you use bash as your shell, you can put these lines in your ~/.bashrc and ~/.profile files:

export LC_ALL=en_US.UTF-8 export LANG=en_US.UTF-8 export LANGUAGE=en_US.UTF-8

To make these changes active in the current shell, source the .bashrc:

$ source ~/.bashrc

All newly started interactive bash processes will respect these settings.

A Warning about Non-Interactive Processes

There are certain processes that don't get those environment variables, typically because they are started by some sort of daemon in the background.

Those include processes started from cron, at, init scripts, or indirectly spawned from init scripts, like through a web server.

You might need to take additional steps to ensure that those programs get the proper environment variables.

Locales: check

Run the locale program. The output should be similar to this:

LANG=en_US.UTF-8 LANGUAGE=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=en_US.UTF-8

If not you've made a mistake in one of the previous steps, and need to recheck what you did.

Setting up the terminal emulator

Setting up the terminal emulator for your terminal emulator strongly depends on what you actually use. If you use xterm, you can start it as xterm -en utf-8, konsole and the Gnome Terminal can be configured in their respective configuration menus.

Testing the terminal emulator

To test if you terminal emulator works, copy and paste this line in your shell:

perl -Mcharnames=:full -CS -wle 'print "\N{EURO SIGN}"'

This should print a Euro sign € on the console. If it prints a single question mark instead, your fonts might not contain it. Try installing additional fonts. If multiple different (nonsensical) characters are shown, the wrong character encoding is configured. Keep trying :-).

SSH

If you use SSH to log in into another machine, repeat the previous steps, making sure that the locale is set correctly, and that you can view a non-ASCII character like the Euro sign.

Screen

The screen program can work with UTF-8 if you tell it to.

The easiest (and sometimes the only) way is to start it with the -U option:

$ screen -U

and also when detaching (screen -Urd or so).

Inside a running screen you can try Ctrl+a :utf8 on<return>. If that doesn't work, exit your screen and start a new one with -U

Irssi

There's a complete guide for setting up irssi to use UTF-8, which partially overlaps with this one. The gist is:

/set term_charset utf-8 /set recode_autodetect_utf8 ON /set recode_fallback ISO-8859-15 /set recode ON
gogs 如何不使用端口进行访问

gogs 如何不使用端口进行访问

gogos 默认是 3000端口,如果你本身已经有了其他WEB服务,比如apache,当然不可能同时占用80端口,这时候就可以利用apapche的proxy功能。如果你是apt-get 安装 的apache,就方便了,debian/ubuntu 都支持a2ensiate,a2enmod这样的小脚本。你只要打开a2enmod proxy proxy_http就行了,然后新建一个site加入以下配置

<VirtualHost *:80>
ServerAdmin test@test.com
ServerName yoursitename
ProxyRequests off
ProxyPass / http://127.0.0.1:3000/
ProxyPassReverse / http://127.0.0.1:3000
<Proxy *>
Order Deny,Allow
Allow from all
</Proxy>
ErrorLog ${APACHE_LOG_DIR}/yoursitename.log
LogLevel warn
</VirtualHost>
是不是很简单,这时候你用supervisor启动后就可以通过WEB访问了.不过这时候有具小缺点,那就是如果你killall gogs进程的话,你会发现再也启动不了了.看启动的LOG会告诉你3000端口被占用,用netstat -an|grep 3000,发现有N个进程都是在CLOSE_WAIT的情况,这时候用: echo $(netstat -anp|grep 127.0.0.1:3000 |awk '{print $7}') 发现,全是apache2占着这些进程.

怀疑刚才在强杀gogs进程的时候,apache因为开着proxy导致刚刚向3000端口发起请求就挂起,导致异常关闭所以一直卡住(以前用nginx的做反代的时候也有类似问题,只要客户机挂了,nginx必须 重启),所以我重启了一下apache,立刻发现gogs启动成功.

至此,如果要 重启gogs最好是/etc/init.d/supervisor restart ,如果不正常就再重启一下apache...

OK,问题全部解决

gogs 0.6.1版二进制打包文件缺少start.sh

gogs 0.6.1版二进制打包文件缺少start.sh

在gogs的release包中,linux_amd64.zip这个包里,scripts目录下没有start.sh这个文件,因此在 执行./scripts/gogs_supvisor.sh文件的时候会直接后/usr/local/bin/gogs_start文件不存在

打开这个gogs_supvisor.sh文件后,发现他会判断/usr/local/bin/gogs_start文件是否存在,如果不存在就将./scripts/start.sh文件复制 过去并改为为gogs_start

然而,scripts目录下并没有这个start.sh文件,这个问题在官方的issue中已经提出并有解决方案:https://github.com/gogits/gogs/issues/1198

解决方案就是:

oh man sorry for that.

I would suggest install supervisor as init.d somehow doesn't worked for me after trying lot of diffrent combinations. to do that,

sudo apt-get -y install supervisor

and edit its file via

sudo nano /etc/supervisor/supervisord.conf

[program:gogs]
directory=/home/git/go/src/github.com/gogits/gogs/
command=/home/git/go/src/github.com/gogits/gogs/gogs web
autostart=true
autorestart=true
startsecs=10
stdout_logfile=/var/log/gogs/stdout.log
stdout_logfile_maxbytes=1MB
stdout_logfile_backups=10
stdout_capture_maxbytes=1MB
stderr_logfile=/var/log/gogs/stderr.log
stderr_logfile_maxbytes=1MB
stderr_logfile_backups=10
stderr_capture_maxbytes=1MB
environment = HOME="/home/git", USER="git"

change directory's to match your installation and user to your git user. and restart the supervisor via,
sudo service supervisor restart

that's all you need to make gogs start automatically on boot.

看上述内容,修改一下supervisor的配置,加入gogs的配置,注意修改成你自己的路径即可