用遠振主機又踩雷啦,遠振將escapeshellarg這個函式disabled
所以只要有用到
SebastianBergmann\Environment\Runtime
Symfony\Component\Console\Input\Input
Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser
Symfony\Component\Process\ProcessUtils
Tracy\Debugger
都會提示 escapeshellarg() has been disabled for security reasons
不過還好php5.3之後就支援namespace,可以讓我們輕鬆略過這個問題
(如果使用的套件不支援namespace那就只好認命的去修改程式囉)
只要require下面的檔案就可以解決這些問題了
```php
namespace Yuan\Jhen
{
if (function_exists('escapeshellarg') === true) {
function escapeshellarg($input)
{
return \escapeshellarg($input);
}
} else {
function escapeshellarg($input)
{
$input = str_replace('\'', '\\\'', $input);
return '\''.$input.'\'';
}
}
}
namespace SebastianBergmann\Environment
{
function escapeshellarg($input)
{
return \Yuan\Jhen\escapeshellarg($input);
}
}
namespace Symfony\Component\Console\Input
{
function escapeshellarg($input)
{
return \Yuan\Jhen\escapeshellarg($input);
}
}
namespace Symfony\Component\HttpFoundation\File\MimeType
{
function escapeshellarg($input)
{
return \Yuan\Jhen\escapeshellarg($input);
}
}
namespace Symfony\Component\Process
{
function escapeshellarg($input)
{
return \Yuan\Jhen\escapeshellarg($input);
}
}
namespace Tracy
{
function escapeshellarg($input)
{
return \Yuan\Jhen\escapeshellarg($input);
}
}
```
2015年12月28日 星期一
2015年12月22日 星期二
利用Git來升級Laravel
照著影片操作,就會出現conflicts,處理完conflicts之後,再執行
```bash
composer install
```
這樣大致上就升級完畢了,而且如果升級出問題還可以利用git本身的功能來進行還原...
2015年12月20日 星期日
php 偵測語系
```php
function getDefaultLanguage()
{
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
return parseDefaultLanguage($_SERVER['HTTP_ACCEPT_LANGUAGE']);
} else {
return parseDefaultLanguage(null);
}
}
function parseDefaultLanguage($http_accept, $deflang = 'zh-TW')
{
if (isset($http_accept) && strlen($http_accept) > 1) {
# Split possible languages into array
$x = explode(',', $http_accept);
foreach ($x as $val) {
#check for q-value and create associative array. No q-value means 1 by rule
if (preg_match("/(.*);q=([0-1]{0,1}.\d{0,4})/i", $val, $matches)) {
$lang[$matches[1]] = (float) $matches[2];
} else {
$lang[$val] = 1.0;
}
}
#return default language (highest q-value)
$qval = 0.0;
foreach ($lang as $key => $value) {
if ($value > $qval) {
$qval = (float) $value;
$deflang = $key;
}
}
}
return strtolower($deflang);
}
echo getDefaultLanguage();
```
資料庫備份工具
```php
class DatabaseClone
{
public $link;
public function __construct($host, $username, $password)
{
$this->link = mysqli_connect($host, $username, $password);
mysqli_query($this->link, 'SET NAMES utf8');
mysqli_query($this->link, 'SET AUTOCOMMIT = 0');
mysqli_query($this->link, 'SET UNIQUE_CHECKS = 0');
mysqli_query($this->link, 'SET FOREIGN_KEY_CHECKS = 0');
}
public function fetch($query)
{
$results = [];
$query = mysqli_query($this->link, $query);
while ($row = mysqli_fetch_assoc($query)) {
$results[] = $row;
}
return $results;
}
public function copy($copyTo)
{
set_time_limit(-1);
ini_set('memory_limit', -1);
$query = mysqli_query($this->link, $sql = 'show databases');
while ($database = mysqli_fetch_assoc($query)) {
$database = $database['Database'];
if (in_array($database, ['mysql', 'information_schema', 'performance_schema'], true) === true) {
continue;
}
$createDatabase = mysqli_fetch_assoc(mysqli_query($this->link, 'SHOW CREATE DATABASE `'.$database.'`'));
mysqli_query($copyTo->link, $sql = 'DROP DATABASE IF EXISTS `'.$database.'`') or var_dump($sql);
mysqli_query($copyTo->link, $sql = $createDatabase['Create Database']) or var_dump($sql);
mysqli_select_db($this->link, $database);
mysqli_select_db($copyTo->link, $database);
$query2 = mysqli_query($this->link, $sql = 'show tables');
while ($table = mysqli_fetch_assoc($query2)) {
$table = current($table);
$createTable = mysqli_fetch_assoc(mysqli_query($this->link, 'SHOW CREATE TABLE `'.$table.'`'));
mysqli_query($copyTo->link, $sql = $createTable['Create Table']) or var_dump($sql);
$counts = current(mysqli_fetch_assoc(mysqli_query($this->link, 'SELECT COUNT(*) as counts FROM `'.$table.'`')));
$range = range(0, $counts - 1);
$offset = 0;
$limit = 200;
$chunks = array_chunk($range, $limit);
foreach ($chunks as $chunk) {
$query3 = mysqli_query($this->link, $sql = 'SELECT * FROM `'.$table.'` LIMIT '.$limit.' OFFSET '.$offset) or var_dump($database, $sql);
while ($row = mysqli_fetch_assoc($query3)) {
$keys = [];
$values = [];
foreach ($row as $key => $value) {
$keys[] = '`'.$key.'`';
$values[] = "'".addslashes($value)."'";
}
mysqli_query($copyTo->link, $sql = 'INSERT INTO `'.$table.'` ('.implode(',', $keys).') VALUES ('.implode(',', $values).')') or var_dump($database, $sql);
}
$offset += count($chunk);
}
}
}
}
}
$database = new DatabaseClone('localhost:3306', 'root', '');
$database->copy(new DatabaseClone('localhost:3308', 'root', ''));
```
2015年11月7日 星期六
使用instance來進行Tracy Panel
```php
// PHP程式碼
include __DIR__.'/vendor/autoload.php';
use Tracy\Debugger;
use Tracy\IBarPanel;
class CustomPanel implements IBarPanel
{
/**
* Renders HTML code for custom tab.
* @return string
*/
public function getTab()
{
return 'sql';
}
/**
* Renders HTML code for custom panel.
* @return string
*/
public function getPanel()
{
$data = $this->data;
ob_start();
require __DIR__.'/custompanel.php';
return ob_get_clean();
}
public function push($data)
{
$this->data[] = $data;
}
public $data = [];
private static $_instance;
public static function instance()
{
if (static::$_instance === null) {
static::$_instance = new static;
}
return static::$_instance;
}
}
// 開發環境
$environment = Debugger::DEVELOPMENT;
// 啟用
Debugger::enable($environment);
Debugger::getBar()
->addPanel(CustomPanel::instance());
$i = 0;
CustomPanel::instance()->push([
'sql' => 'select * from user where id = '.++$i,
]);
CustomPanel::instance()->push([
'sql' => 'select * from user where id = '.++$i,
]);
CustomPanel::instance()->push([
'sql' => 'select * from user where id = '.++$i,
]);
```
```php
//樣板<h1>SQL</h1>
<div class="tracy-inner">
<table>
<?php foreach ($data as $key => $value): ?>
<tr><td><?php echo $value['sql']; ?></td></tr>
<?php endforeach ?>
</table>
</div> ```
<div class="tracy-inner">
<table>
<?php foreach ($data as $key => $value): ?>
<tr><td><?php echo $value['sql']; ?></td></tr>
<?php endforeach ?>
</table>
</div> ```
2015年10月23日 星期五
Laravel的Session不等於PHP Native Session
在Laravel內我們可能寫了以下的程式碼
```php
get('/session', function () {
session_start();
session()->put('foo', 'bar');
$_SESSION['foo'] = 'bar';
header('location: '.url('/session/display'));
exit;
});
get('/session/display', function () {
session_start();
ob_start();
dump(session()->get('foo'));
dump($_SESSION['foo']);
$content = ob_get_clean();
// output null, 'bar'
return $content;
});
```
會發現輸出結果完全不如我們所預期,為什麼會這樣呢?我們就好好的來做個探討吧...
## 原因出在Laravel的Session根本不是用PHP Native Session
在遇到這個狀況後,於是就去查了一下Laravel Session倒底是怎麼一回事,發現Laravel的程式碼內根本沒有執行session_start()啊
## Laravel Session倒底是怎麼運作的
追了一下Laravel的原始碼,發現它是利用[Illuminate\Session\Middleware\StartSession](https://github.com/illuminate/session/blob/master/Middleware/StartSession.php)來進行php session模擬的,
在Laravel執行的最後階段在將存在記憶體內的資料進行實體寫入,
所以只要在我們只要在程式內任意一個地方執行了php的exit, die, header('location: xxx');
那Session就不會被存入檔案內,自然在下一次連線也就取不到值了
## 有沒有解決方案
有,當然有,只要輸入
```php
get('/session', function () {
session_start();
session()->put('foo', 'bar');
$_SESSION['foo'] = 'bar';
session()->save(); // 手動寫入
dump($_SESSION['foo']);
$content = ob_get_clean();
// output 'bar', 'bar'
return $content;
});
```
## 後記
為什麼會有這一篇的出現,因為我們可能會用很多其它已經寫好的library,但它們就是有用到session_start();外加header, die, exit等等指令啊,所以記錄一下來提醒自己囉
2015年9月20日 星期日
重寫Laravel Socialite
最近需要用到OAuth的Client套件
所以就使用目前最多人使用的Laravel
不過需要的部份只有Laravel Socialite
看了一下composer.json的相依性
```json
"require": {
"php": ">=5.4.0",
"illuminate/contracts": "~5.0",
"illuminate/http": "~5.0",
"illuminate/support": "~5.0",
"guzzlehttp/guzzle": "~5.0|~6.0",
"league/oauth1-client": "~1.0"
},
```
只需要這些package並不需要整個Laravel
所以就開始使用它
不過在使用的過程遇到了不少問題
它所需要的package其實不止這些
所以程式在撰寫的過程中確實遇到不少問題
再在上在本機端上開發會遇到cURL error 60: SSL certificate problem
於是決定以[PHPoAuthLib](https://github.com/Lusitanian/PHPoAuthLib.git)進行開發
所以就寫了[Recca0120 Socialite](https://github.com/recca0120/Socialite)
並使它可以獨立使用
[Demo](https://github.com/recca0120/Socialite/tree/master/demo)
目前只先實作Laravel Socialite原本的功能,之後會視情形再加功能
OAuth1
BitBucket
Twitter
OAuth2
Facebook
GitHub
Google
Instagram
LinkedIn
2015年9月19日 星期六
cURL error 60: SSL certificate problem: unable to get local issuer certificate
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEinE8PbXmRzH1srPLp3BbrAwyuMCcC4FeDkwFxq14m3nRX540JhHTWveaBg3QBUrn3vl4Zrzs20koBH7t8gEGyZDKWczCyzzFfXOJFhOXHIHT5dljDaiUfk2CmIyZNMWOdxQYd09QMWrwaR/s1600/Image+2.png)
在使用Guzzle時,遇到cURL error 60: SSL certificate problem: unable to get local issuer certificate
只要下載[ca-bundle.crt](https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt)並放到相對應的路徑
```php
[
// Red Hat, CentOS, Fedora (provided by the ca-certificates package)
'/etc/pki/tls/certs/ca-bundle.crt',
// Ubuntu, Debian (provided by the ca-certificates package)
'/etc/ssl/certs/ca-certificates.crt',
// FreeBSD (provided by the ca_root_nss package)
'/usr/local/share/certs/ca-root-nss.crt',
// OS X provided by homebrew (using the default path)
'/usr/local/etc/openssl/cert.pem',
// Google app engine
'/etc/ca-certificates.crt',
// Windows?
'C:\\windows\\system32\\curl-ca-bundle.crt',
'C:\\windows\\curl-ca-bundle.crt',
];
```
如果再無法正常運作的話就得去修改php.ini
再加入
```ini
[curl]
curl.cainfo=C:\Windows\curl-ca-bundle.crt
[openssl]
openssl.cafile=C:\Windows\curl-ca-bundle.crt
```
就可以正常運作了
2015年9月14日 星期一
發撲克牌
在奇摩知識+看到有人發問發撲克牌,依花色及數字大小做排序,所以我就寫了這個程式囉
```php function Poker($member = 4, $POSTCARDS = 52) { /*撲克花色*/ $Poker = [ 'Spades', 'Hearts', 'Diamonds', 'Clubs', ]; /*人頭牌*/ $CARD = [ 11 => 'J', 12 => 'Q', 13 => 'K', ]; /*發牌順序*/ $P = range(0, $POSTCARDS - 1); shuffle($P); /*存放結果陣列*/ $result = []; $total = count($P); for ($i = 0; $i < $total; $i++) { /*發給玩家*/ $t = $i % $member + 1; /*發牌編號 0-51*/ $v = $P[$i]; /*發牌花色 Spades,Hearts,Diamonds,Clubs*/ $c = $Poker[$v % count($Poker)]; /*花色大小 1-13*/ $k = ($v % 13) + 1; $result[$t][$c][$k] = (in_array($k, array_keys($CARD))) ? $CARD[$k] : $k; /*依牌大小排序*/ krsort($result[$t][$c]); /*依花色排序*/ krsort($result[$t]); } return $result; } /*印出結果*/ print_r(Poker(1, 13)); /*如果要發4個人52張牌*/ print_r(Poker(4, 52)); ```
```php function Poker($member = 4, $POSTCARDS = 52) { /*撲克花色*/ $Poker = [ 'Spades', 'Hearts', 'Diamonds', 'Clubs', ]; /*人頭牌*/ $CARD = [ 11 => 'J', 12 => 'Q', 13 => 'K', ]; /*發牌順序*/ $P = range(0, $POSTCARDS - 1); shuffle($P); /*存放結果陣列*/ $result = []; $total = count($P); for ($i = 0; $i < $total; $i++) { /*發給玩家*/ $t = $i % $member + 1; /*發牌編號 0-51*/ $v = $P[$i]; /*發牌花色 Spades,Hearts,Diamonds,Clubs*/ $c = $Poker[$v % count($Poker)]; /*花色大小 1-13*/ $k = ($v % 13) + 1; $result[$t][$c][$k] = (in_array($k, array_keys($CARD))) ? $CARD[$k] : $k; /*依牌大小排序*/ krsort($result[$t][$c]); /*依花色排序*/ krsort($result[$t]); } return $result; } /*印出結果*/ print_r(Poker(1, 13)); /*如果要發4個人52張牌*/ print_r(Poker(4, 52)); ```
php 下載限速
```php
function getlocalfile($filename, $readmod = 1, $range = 0)
{
if ($fp = @fopen($filename, 'rb')) {
@fseek($fp, $range);
$download_rate = 10;//限制网速10kb/s
while (! feof($fp)) {
print fread($fp, round($download_rate * 1024));
flush();
ob_flush();
sleep(1);
}
}
@fclose($fp);
@flush();
@ob_flush();
}
```
2015年8月26日 星期三
VirtualBox 5.0.2安裝Mac OS X 10.10 (Yosemite)
新增虛擬主機,並依照圖片中的設定即可正常安裝
1.
版本請選擇 Mac OS X 10.10 Yosemite (64-bit)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEie3e_o9LHnVwEcdQYGCdaFO4Ds4QAqYimFAYsTbDmf3yUTyOqyQE0phRvx8OOmTEhu457yUXulNjhEdhva1BtSBj2sDDLKNbXbTESsuq8YLZP_T2D40ay3xOy_u6e1WdYd3Xgtvp1AoThk/s640/Image+1.png)
2.
晶片組 ICH9
指標裝置 USB平板
延伸功能 全選
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjTXV7zaqRi1-a1TK3u91-h2h6HsUsaGpqXmPNxPe7-e26Q7miXwsjoVlISUcyiHqQaSy5E3GidJsJz1u9iy4CX0d1FkYMYpdXM2LDm7kokRNlcqSwj_jbhk6kz2jpbeVBN_SsxDe0v2cSI/s1600/Image+2.png)
3
啟用 VT-x/AMD-V
啟用Nested Paging
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgwppiIn1rb_nuqC8BGHtfQ_njI_2VBQpqIVHeNqBBm71TkbXDkOBcstbPMW-X0amc2T1ztUoRwPzG0ZjY7_YXc73dcsoAi1SB-Ej_2rk4qfM_RDnLGNE3lMCG-eJU85TB6Qxfj86fKOnOP/s1600/Image+3.png)
4
視訊記憶體調到128M
啟用3D加速
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhKjacY0c0_Rl8gOthhK2f-mwuNJgqvgvLJJBtYPjbtSKo14gZGKm9SLahqnQfsre7uYt33dR8SB2x8njjGteX6qBD5t1ibM61s1iCPDhV3b7PKdCQkc-yaa6EmRDhJpMF_tY-v9ay2pu5Q/s1600/Image+4.png)
5
掛載Yosemite原版ISO
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyM6xP46i__ESwBUoXdoVcTAWU88U-PLFyN5qLp1IFURA8rPpO5dZkRNNMufmWJuXaEU2BRvwk-Xal3peCaTsAwsJblD7h5Kuc9Vt3eED-JFFRLyi3au417DkNkjV856nwK78QKmPWOhi1/s1600/Image+5.png)
6.
執行以下指令
```bash
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro11,3"
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0"
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple"
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc"
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1
VBoxManage setextradata "虛擬機器名稱" "VBoxInternal2/EfiGopMode" 4
```
這樣就能在Virtualbox 5.0.2上正常安裝Yosemite
2015年8月14日 星期五
Laravel 5 取得 Artisan::call的執行結果
```php
// 輸出結果
class WelcomeController extends controller {
public function index() {
return response()->stream(function() {
Artisan::call('inspire');
echo Artisan::output();
});
}
}
```
2015年8月9日 星期日
Laravel 5 資料庫timezone設定
原本在設定database的timezone的設定方式是採取
```php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'options' => [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET time_zone = "+08:00"'
],
],
```
後來卻在laravel的原始碼發現
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_u-41FbGyPsJq6Z6AqMqSbCalwbp1QGNb5pazM_r-74k1coiFCRQE_2sRby6ZdxDPAumL7GPPKDJwlthyphenhyphenlrA4nujOquoQk2pRyf-5Tbjtm0iYv2N3NJyZz9ozEzxtyR69BtKVJuk7lZSL/s1600/Image+6.png)
所以timezone的設定只要這樣寫就可以
```php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
'timezone' => '+08:00',
],
```
2015年8月2日 星期日
找出Windows的序號
重灌或升級windows時有時候會忘記序號
又找不到序號時就很煩好
還好找到一個免費又簡單的找出序號的軟體
### [Lazesoft Windows Key Finder](http://www.lazesoft.com/lazesoft-windows-key-finder.html)
而且它是Open Source Freeware的軟體
不用擔心會有病毒喔
支援的作業系統
* Windows 2000 SP4
* Windows XP
* Windows Vista
* Windows 7
* Windows 8
* Windows 8.1
* Windows Server 2003
* Windows Server 2008
* Windows Server 2008 R2
* Windows Server 2012
* Windows Server 2012 R2
支援的OFFICE
* Microsoft Office 2000
* Microsoft Office 2003
* Microsoft Office 2007
* Microsoft Office 2010
* Microsoft Office 2013
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgcv9WM3kZgUz7pZdrdmM14Fb7nzy8LD9Z68A-dwfnfy5b_11BAphW0kRIWkjwsSkb7FGlv4WyjzO_aH3vIgByle12ybOptzNpoeZTeDDEGoeX0qQ83c_Wf3DbmeFNZK5tBENa12m6d2GAb/s1600/lazesoft-windows-key-finder.jpg)
2015年7月27日 星期一
使用Laravel artisan schedule:run時 exec被禁用時的替代方案
```php
namespace App\Console;
use Artisan;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
class Kernel extends ConsoleKernel
{
/**
* The Artisan commands provided by your application.
*
* @var array
*/
protected $commands = [
'App\Console\Commands\Inspire',
];
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*/
protected function schedule(Schedule $schedule)
{
// 當exec被disabled時只要改成使用Artisan::call('command')即可
$schedule->call(function () {
Artisan::call('inspire');
})
->hourly();
}
}
```
遠振主機上利用crontab執行 laravel artisan schedule:run
在專案中有個需求需要在固定時間去抓取固定資料
既然都已經使用laravel所以當然開始使用artisan寫寫console指令
於是很快速的寫完程式,當然第一時間就在自己本機上測試
測試的結果當然是一切都正常
所以很快的就把程式上傳到遠振主機上
並且設定了Cron的排程
```bash
* * * * * php /path/to/artisan schedule:run 1>> /dev/null 2>&1
```
設定完後,想說一切都妥當了,
但程式一直出錯
系統就回應
```ini
[ErrorException]
Invalid argument supplied foreach()
```
這要怎麼debug啊
而且明明在自己電腦內測試都能正常執行啊
所以只好開始研究程式碼囉,查到最後原來.....
遠振主機的php預設為 php-cgi
所以無法取得正確的參數
如果要artisan正常執行的話必須使用php-cli
所以在遠振主機上要執行artisan應該要改為
```bash
* * * * * /usr/bin/php-cli /path/to/artisan schedule:run 1>> /dev/null 2>&1
```
應該所有的cpanel主機只要是可選php版本的都會遇到這個問題......
php-cli和php-cgi兩個在console上執行的差異
php-cli 的參數會存入 $_SERVER['argv'];
php-cgi的參數則會存入 $_GET;
如果要讓php-cgi能正常執行則可以用以下做法
```php
if (empty($_GET) === false) {
foreach ($_GET as $key => $value) {
$_SERVER['argv'][] = $key;
}
}
```
2015年4月12日 星期日
sublime 安裝 less
1. 安裝[nodejs](https://nodejs.org/)
2. 開啟cmd,並執行
```bash
npm install -j less
```
3. sublime安裝 LESS, smart less build
4. 修改smart less build設定檔
```json
{
"source_map": false
"custom_args": "--clean-css=\"--s1 --advanced --compatibility=ie8\""
}
```
sublime 安裝 coffeescript
1. 安裝[nodejs](https://nodejs.org/)
2. 開啟cmd,並執行
```bash
npm install -j coffee-script
```
3. sublime安裝 Better CoffeeScript
4. 修改coffeescript設定檔
```json
{
"checkSyntaxOnSave": true
"lintOnSave": true
"lintConfFile": true
}
```
sublime syncing
windows內如何同步sublime的設定檔至多台電腦呢?
我們可以利用Dropbox加mklink的方式來做設定喔
請使用系統管理者權限開啟cmd
1.將已設定好的sublime的設定檔移至dropbox內
```bash
mkdir %USERPROFILE%\Dropbox\Sublime
cd %APPDATA%\"Sublime Text 3\Packages"
copy /Y User\* %USERPROFILE%\Dropbox\Sublime
```
2.同步所有資料夾
```bash
cd %APPDATA%\"Sublime Text 3\Packages"
rmdir /S /Q User
mklink /D User %USERPROFILE%\Dropbox\Sublime
```
sublime terminail套件使用git bash
1.安裝 [git](http://git-scm.com/download/win)
2.sublime安裝Terminal
3.將Terminal => Settings - Default的內容複製到Terminal => Settings - User
4.修改
```json
{
"terminal": C:\\Program Files\\Git\\git-bash"
}
```
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj9raJknXL-st6xur1NB_oFc1eae_gr5l2JrjQ7DfCFgoN1pzblcEMPztphGxZIiWK9RjAjCE1IhZRHkW8I9fWRUNfaBTIC6xn2AH1eYzGLnbN8Bhg-q0XIBPhE0FV3bLDH8uGAlGItmwAz/s1600/Image+2.png)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj2_y8Z-a_Xi6csjteuzvpFnLyhG_z5yimOO14uIVHYDNb3-GlHs8vsWtvtNF4Yj4NHigRP43FbJKpYbWLa8yc4bufrqgofcu40Wu0D8sOhlxm-zRzkNBI_3KgGrXJgj7fUcLETyr7_LFGS/s1600/Image+3.png)
sublime安裝phpcs windows版
1.安裝sublime並安裝好package control
2.安裝phpcs
3.打開command並利用composer安裝
[PHP_CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer)
[PHP-CS-Fixer](https://github.com/FriendsOfPHP/PHP-CS-Fixer)
[PHPMD](https://github.com/phpmd/phpmd)
```bash
composer global require squizlabs/php_codesniffer fabpot/php-cs-fixer phpmd/phpmd
```
4.將PHP Code Sniffer => Settings - Default的內容複製到 PHP Code Sniffer => Settings - User
5.修改Settings - User
```json
{
"phpcs_executable_path": "phpcs.bat",
"php_cs_fixer_on_save": true,
"php_cs_fixer_executable_path": "php-cs-fixer.bat",
"phpcbf_on_save": true,
"phpcbf_executable_path": "phpcbf.bat",
"phpmd_run": true,
"phpmd_executable_path": "phpmd.bat"
}
```
如果進行存檔時還是會提示錯誤訊息修改下列參數即可
```json
{
"phpcs_php_prefix_path": "php路徑\\php.exe"
}
```
參考
[wamp安裝](http://phpwrite.blogspot.tw/2015/04/uniform.html)
[composer安裝](http://phpwrite.blogspot.tw/2015/04/windowscomposer.html)
如何在windows下安裝composer
[composer](https://getcomposer.org/)是目前最多人使用的php套件管理單,
只要下一個指令,
就可以將所有套件相依性的軟體下載,
並只要require一隻autoload.php即可
不過要安裝composer有些步驟得進行,
說明一下如何安裝composer
1.下載windows版composer[下載](https://getcomposer.org/Composer-Setup.exe) 並安裝(安裝過程中,會要求指定php.exe資料夾)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhCJLUmc3y6Q5MazY7kyTzHHyHkSphJ-OHFL0-VvM5BMShknPvoce5rEZw65bJVmifgi4xNdhEkkY5YPJ8ygJCarmsRVxa0mQdme9Z8oPJJklhrkcJA3NSNQTpCRqNHt2k1ClfryhhcReBY/s1600/Image+26.png)
2. 開始右鍵 => 系統 => 進階系統設定 => 環境變數
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg2k6hfBqgv0RlBGd6DG5y8f71seI33xlYh8tAaby8AIYDoA2yKiGzzDNH39Blbqm5beEBlrvkBssXYLAWWkt2Dj9Qj_UnjS5rGkDKcg972fCFOcuj9goa5kvWu67KQr3QqjSBl7UBn1u0v/s1600/Image+21.png)
3. 新增變數
變數名稱: PHP_HOME
變數值: PHP路徑(範例為C:\PHP)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgAU0l5C5paiYe8DTWgQ-uxW1u7EdqM3ILgjPA1KblmBu-L5fFBGFBTf58yNc07_XjFfQ8fKDCTq4a9p7bcOnrsQ4WZlipPBjBMD0DxmwzzJ4c0zkgzCnrAgDadtWfM2R-qq6nyTdGKnGXT/s1600/Image+24.png)
4. 新增變數
變數名稱: COMPOSER_HOME
變數值: C:\ProgramData\ComposerSetup
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGLdjNYUgYAS5EgGiuiJdSjKb14iQpDyUUeAKVv3IB656jfUBArkFeBRmO9ZpR6ZHY0ftxzfY9WIcq2-K10hE2WIHS1qp_YLzLGkQHVI-ybzoARguulnrmWruDFfq1NOIVUtriasaJb6Pm/s1600/Image+27.png)
5. 修改path
在原本的path後面新增
;%PHP_HOME%;%COMPOSER_HOME%\bin;%COMPOSER_HOME%\vendor\bin
※由於已經設定%COMPOSER_HOME%所以往後利用 composer global require 套件
都會安裝至%COMPOSER_HOME%\vendor
如果套件內有執行檔則會自動安裝至%COMPOSER_HOME%\vendor\bin
所以%COMPOSER_HOME%\vendor\bin也要加入path變數之中
6. 打開command模式,直接執行composer即可
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhGeIdIBzh740FFfx_vK-zOyAga0_4rBeaD9wiPut0MqvGghSl2uR0xfsGtWw1UT95tkC38lYZUpJWmDfCtBbztVYYfPTXPV9tsNWotAZoLD1qiRWkRNEi0b7Y8tul7GBlAj_3-RBL7BG0v/s1600/Image+28.png)
uniform server 在windows下體積小快速安裝的wamp server
在Windows裡安裝wamp server
除了常見到的[xampp](https://www.apachefriends.org/zh_tw/index.html)、[wampserver](http://www.wampserver.com/en/)之外
還有這一套『[uniform server](http://www.uniformserver.com/)』
uniform server標榜的是體積小
主程式安裝檔案也才27M
不過相對功能就比較少
安裝程式只包含了apache、php5.4、mysql
其他的phpmyadmin、mariadb等等都可以利用plugin的方式來進行安裝
至於安裝的方法,只要將[檔案](http://sourceforge.net/projects/miniserver/files/latest/download?source=files)下載後,解壓縮到任一資料夾就可以使用了
以下為安裝步驟
1. 下載檔案(只有27M)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGSMZIWZYVqVwXtgsKk82q4q3qMkk-wu7VTtbCXYvf5CC4RnJ9JyYXEWa_yvRHSIIEjN-gQaclVmjebZPrw_BtV20O5peIy0VaMWxLQtw6ZMbyB_Z0L5ENk9fGElAMlMwGcH8Usl8IReXr/s1600/Image+2.png)
2. 點擊兩下解壓縮
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_iseZ0LLaI6G0Sn436leWTYHEpqWk5VlO_4HAqe66Q-MAZMbEo7qlvbEMZBRR9rBOYKh5fB_OVvL6dOJfdhrxRbqLvQ_ngTKS5goFDss3iwxT2UuZEMOfWoB01srNd9MZTnT-UrceDgh0/s1600/Image+4.png)
3. 進入UniServerZ資料夾
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjGRBqRr6ZqJfp-Oq0P8pOnSpOiI6_kW-HAljC7Il6Lkrz0HElJNLrF8NinHP3ZQ-qj0SswbBpFOfmao_mPaHcXdAcwJT_qu6REP9I3DRVFBnFtGNTIJsTJfkrfeMpdy_xMswcbDBf9MsN1/s1600/Image+6.png)
4. 點擊UniController.exe(用系統管理員身份執行才能設定開機後自動執行wamp)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiAtpKZskDbmo1NgqmVADAfBdGOBoktmuO5mXtpVEe8b02Ib04sh4BzoJnb8Ezu3XHBqlBxK-r48iHcVoz9DIa8I2OWkh1GWkuChrETvZZzHPn4UFAZXlWFJEgmYpN2DjEg5IrYvaQyWGQR/s1600/Image+8.png)
5. 允許防火牆
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhAxbCelBqSOGgDcc5-Wqk7XOZWaY1lkbr4UZ-3QKqIT-6XuuyUDkN9BFqTyO6Dimh-JqIgx4pBO1pE-XMZHblI3H3kKDAYF6CopyCYVlVn3FUy7wSCjfEgwD-MBbbQjWnJE5ziYXyawHFa/s1600/Image+9.png)
6. 更改mysql root預設密碼,不更改可直接點選cancel(預設密碼為 root)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgniAC1VXppDyDwfibU7UGA2Nuz_D2DFyrxTf7VWrk_244cd2IKqhtz3XI5rs1SRKO2eTUth75Y80OnWgNbBfI6Olf3ileEeOMETHP4GUJS-YlFjFn9sLCyFa3n0tpS3Jp5EauPDaHxYAK3/s1600/Image+10.png)
7. 啟動apache及mysql
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEghzDrxzzuv6Pj9PdJuWKFqe2H_Rm3VBkYm703-4P-vvPaUzpBPcmtFMeN2Sz93wxT63-0FfUVa8VHJ7Tt0BefMmUj-aW35lBzFz_eiHpXIpYHVwSeOqtdym7D7nCP5EeSDBO6kIK3ByO99/s1600/Image+14.png)
8. 設定開機執行apache及mysql
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiVy_G0mWWtxBwkb_LLXpsGJwf_FOF6xxuFxQO3SaxwmiJqqBrQSLIETbpRl0Y50OdgMnn6zy753ZlbkgMXYNdmKCy2wBUCF8-5_PmHN5n0g5gZJWnNjpPH0Z77hHNqRyUZyuL9HcxBSZdn/s1600/Image+15.png)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEio_nddjp6pVCPep37Smjvq_Z2J2IdeK4ggN6IUIq8msqC322odhViqqe7KFCrUcQnq-jlh_sB3Qu5H-hWRMigL1Pc9r8cctCvZU6EkxHjJwN2iJTK2L_SUV-GC4BYK92pXh-ZRR5saEk3Z/s1600/Image+16.png)
9. 這樣就設定完成了
![Alt text]()
其他比較常用到的apache及php設定
1.設定apache rewrite
2.設定php curl
要更改apache及php的設得先停止apache
設定rewrite的方法
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhXsFIWK3aNI15VN_bwMuMA3T71_1IxwO7g_T6LhpEC76ZolQeNh4XSJ6Ez4r4Sgk8Bq4dHp39QVv8T6eHSv5gcVid_FoObbQDHxvVz97c1mdesmd6ATI_ZT-N0azzHyWHQnmiLMKKp6Emb/s1600/Image+17.png)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi-YAcghp3EdqavoEhO9oJXzgFUYyDowhNWtSQhoFNQL0yklDeVGek2xsySNaMDta2AoPferkDNmc11naMNonlTJetGuF51tQuNN8ysEsBjSmC0hEwQ_cOtyw4VrI_XTLC4wlAo-WNKdnnV/s1600/Image+18.png)
設定php curl
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhZIfNM56k7l1SyObNnrniKI00sRSXVVWiTbL6MhEHX3Fy4VeJOJWx6pqiRqt8pwsVkAZbI42ZjV-77bpsCwrbZf3Ze-MqE2HfRKE-4DUFuCg_zaHyCLER9mUsX4uuaSB6kIoyrWldIRAUC/s1600/Image+19.png)
![Alt text](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjb-SAYNPXW6r0hyphenhyphen5R0R3tij_EsBZ2dG-raaT02vRidtitVH-4S89_FJ5cxz4F-9ylMWp-oBU2Qjv57ICl3AnQmmTSFSV20FfagOJjRl7KzLuRSOMCwJl2G58gd7cZz1sqnvECDktWefGNd/s1600/Image+20.png)
訂閱:
文章 (Atom)