Thứ Hai, 29 tháng 4, 2013

Những thay đổi trong cấu trúc viết code của Drupal 7


Drupal 7 dường như lột xác so với các phiên bản trước đây, trong những phiên bản trước, Drupal đi theo hướng viết các functions theo các cấu trúc module riêng lẻ nhưng giờ đã khác, trong phiên bản Drupal 7 này thì cấu trúc nó theo hướng lai CMS-Framework

Database

  • Viết lại DAL (Database Abstraction Layor) sử dụng PHP 5's PDO abstraction layer.
  • Viết câu truy vấn cho Drupal dựa trên MySQL 5.0.15 và PostgreSQL 8.3 trở lên.
  • Xây dựng câu truy vấn cho các mệnh đề INSERT, UPDATE, DELETE, MERGE, và SELECT (xem ởhttp://api.drupal.org/api/group/database/7).
  • Hỗ trợ Replication (master/slave), transactions, multi-insert queries, delayed inserts.
  • Hỗ trợ thêm SQLite.
  • Storage engine mặc định là InnoDB.
  • Chuẩn hóa cách đặt tên cho bảng của cơ sở dữ liệu http://drupal.org/node/335086

Security

  • Kịch bản cron.php bây giờ được bảo vệ, chạy cron với một key xác định.
  • Hệ thống mã hóa password bây giờ tương thích với Portable PHP password hashing framework
  • Có cơ chế chống lỗi brute-force password và cải thiện flood control api.
  • Thay đổi module "Update status" thành "Update manager" bảo mật hơn và có thể cài, nâng cấp thông qua giao diện web.

Usability

  • Tích hợp contextual links (a.k.a. local tasks) vào thành phần của trang ví dụ như blocks, nodes, hoặc comments.
  • Cải thiện việc kiểm tra hệ thống khi cài đặt
  • Cải thiện khả năng tích hợp với WYSIWYG editors.
  • Tích hợp drag-and-drop vào input format listings.
  • Tích hợp drag-and-drop vào language listing.
  • Tích hợp drag-and-drop vào poll options.
  • Thêm phần giới thiệu cho từng permission.
  • Bỏ comment controls cho user.
  • Bỏ phần cấu hình display order cho phần comment module, comment display bây giờ sắp xếp thông qua Views module.
  • Bỏ tính năng 'related terms' trong module taxonomy, vì được quản lý thông qua Field API.
  • Thêm một install profile mới và tích hợp 'slimmed down' vào install profile cho developers.
  • Thêm tính năng tự động chạy cron với trigger là khi user load trang.
  • Tự đông tạo một role có tên là administrator khi cài đặt.
  • Thêm edit tab trong trang taxonomy term.
  • Thiết kế lại cơ chế kiểm tra độ an toàn mật khẩu.
  • Thiết kế lại trang add content type.
  • Highlight những liên kết trùng (Duplicate URL aliases).
  • Đổi tên 'Input formats' thành 'text formats'.
  • Thêm vertical tabs.
  • Tích hợp các fieldsets trong edit node và add node với vertical tabs.
  • Chuyển text format permission vào trang permission.

Performance

  • Cải thiện tốc độ load trang không được cache.
  • Cải thiện tốc độ load trang đối với user đăng nhập bằng cách giảm bớt câu truy vấn với đường dẫn ánh xạ (path alias)
  • Cải thiện khả năng hỗ trợ HTTP proxies.

Documentation

  • Hook api documentation bây giờ đã được tích hợp vào core.

News aggregator

  • Thêm OPML import vào rss feeds.
  • RSS feeds bây giờ có thể cấu hình không generate tự động.

Search

  • Hỗ trợ việc nhận biết ngôn ngữ khi tìm kiếm.

Testing

  • Tích hợp mặc định testing vào trong core (simple test).

Improved time zone support

  • Drupal bây giờ sử dụng PHP's time zone database.

Filter system

  • Sửa lại filter API và text format storage.
  • Thêm text format default vào role basic.
  • Viết lại HTML corrector với sự hỗ trợ của PHP5's XML/Dom parser.

User system

  • Thêm clean API khi creating, loading, updating, and deletinguser roles và permissions.
  • Sửa lại 'access rules' trong module user.
  • Bỏ tính năng theme đối với user, module cộng thêm có chức năng này.

OpenID

  • Hỗ trợ Gmail và Google Apps domain. User có thể đăng nhập với user@domain.com với domain.com được đăng ký qua google app domain.
  • Tối lưu lại module OpenID.

Added code registry

  • File include cho module được khai báo thông qua file .info.

Theme system

File handling

  • File bây giờ trở thành đối tượng.
  • Thêm hook hook_file_url_alter() thuận tiện cho việc truy xuất file từ CDN.
  • Viết lại cách tương tác với file thông qua PHP stream wrappers hỗ trợ giao thức như public://, private://, flickr://, s3://.
  • Thêm các hook cho file như file_load, file_save, file_delete, file_move,...

Image handling

  • Khả năng xử lý hình ảnh được cải thiện, hỗ trợ những thư viện cộng thêm cho hình ảnh.
  • Tạo API và giao diện cho việc xử lý hình ảnh như tạo thumbnail.
  • Thêm các xử lý hình như xoay hình
  • Thêm field đặt biệt để upload hình ảnh, ở các bản Drupal trước thì dưới sự hỗ trợ của ImageField.

Added aliased multi-site support

  • Thêm hỗ trợ mapping domain vào thư mục sites.

Search engine optimization and web linking

  • Thêm rel="canonical" vào node và comment tránh duplicate content.
  • Thêm rel="shortlink" mặc định vào node và comment.
  • Thông tin các thẻ Meta có thể được thay đổi bởi module trước khi được render

Field API

  • Những field được tạo mới có thể gắn vào nodes, users, comments và taxonomy terms.
  • Thông tin node body bây giờ được quản lý ở Field API thay vì lưu bản copy như các phiên bản trước.
  • Kế thừa toạn bộ tính năng của CCK.
  • Taxonomy terms bây giờ là Field API fields.

Installer

  • Viết lại api cho phần installer để cho phép có thể cài đặt Drupal 7 qua command line.

Page organization

  • Bỏ site mission thay vào đó là region highlighted
  • Bỏ footer message thay vào đó sử dụng custom block cho region footer.
  • Block main content có thể được sắp xếp với các block khác trong cùng region.
  • Block được trả về là một mảng, giống như page callback.

Translation system

  • Hỗ trợ message context (msgctxt).
  • Hỗ trợ đa ngôn ngữ cho field trong Field API.

JavaScript changes

  • Hỗ trợ jQuery version 1.4.2
  • Hỗ trợ thư viện jQuery Forms 2.36
  • Hỗ trợ jQuery UI 1.8

Removed modules from core

  • Những module được bỏ khỏi core
    • Blog API
    • Ping
    • Throttle

Task handling

Thứ Hai, 22 tháng 4, 2013

24 thư viện PHP mà bạn nên biết


It is an exciting time to be a PHP developer. There are lots of useful libraries released every day, and with the help of Composer and Github, they are easy to discover and use. Here are 24 of the coolest that I’ve come across. Your favorite is not on the list? Share it in the comment section!

1. Dispatch – Micro Framework

Dispatch is a minimal PHP framework. It doesn’t give you the full MVC setup, but you can define URL rules and methods to better organize your application. This is perfect for APIs, simple sites or prototypes:
// include the library
include 'dispatch.php';

// define your routes
get('/greet', function () {
    // render a view
    render('greet-form');
});

// post handler
post('/greet', function () {
    $name = from($_POST, 'name');
    // render a view while passing some locals
    render('greet-show', array('name' => $name));
});

// serve your site
dispatch();
You can match specific types of HTTP requests and paths, render views and more. If you combine Dispatch with some of the other frameworks here, you can have a really powerful and lightweight setup!

2. Klein – Lightning fast router for PHP

Klein is another light weight routing library for PHP 5.3+. It has a bit more verbose syntax than Dispatch, but is quite fast. Here is an example:
respond('/[:name]', function ($request) {
    echo 'Hello ' . $request->name;
});
You can also subscribe to specific HTTP methods and use regexes as paths:
respond('GET', '/posts', $callback);
respond('POST', '/posts/create', $callback);
respond('PUT', '/posts/[i:id]', $callback);
respond('DELETE', '/posts/[i:id]', $callback);

// To match multiple request methods:
respond(array('POST','GET'), $route, $callback);

// Or you might want to handle the requests in the same place
respond('/posts/[create|edit:action]?/[i:id]?', function ($request, $response) {
    switch ($request->action) {
        // do something
    }
});
This is great for small projects, but you have to be disciplined when using a library like this for larger apps, as your code can become unmaintainable very fast. For this purpose, you would be better off with a full blown MVC framework like Laravel or CodeIgniter.

3. Ham – Routing Library with Caching

Ham is also a lightweight routing framework but it utilizes caching for even more speed gains. It achieves this by caching anything I/O related in XCache/APC. Here is an example:
require '../ham/ham.php';

$app = new Ham('example');
$app->config_from_file('settings.php');

$app->route('/pork', function($app) {
    return "Delicious pork.";
});

$hello = function($app, $name='world') {
    return $app->render('hello.html', array(
        'name' => $name
    ));
};
$app->route('/hello/<string>', $hello);
$app->route('/', $hello);

$app->run();
The library requires that you have either XCache or APC installed, which would mean that it won’t work on most hosting providers. But if you do have one of these installed or if you control your webserver, you should try this very fast framework.

4. Assetic – Asset Management

Assetic is am asset management framework for PHP. It combines and minifies your CSS/JS assets. Here is how it is used:
use Assetic\Asset\AssetCollection;
use Assetic\Asset\FileAsset;
use Assetic\Asset\GlobAsset;

$js = new AssetCollection(array(
    new GlobAsset('/path/to/js/*'),
    new FileAsset('/path/to/another.js'),
));

// the code is merged when the asset is dumped
echo $js->dump();
Combining assets in this manner is a good idea, as it can speed up your site. Not only is the total download size reduced, but also a lot of unnecessary HTTP requests are eliminated (two of the things that affect page load time the most).

5. ImageWorkshop – Image Manipulation with Layers

ImageWorkshop is an Open Source library that lets you manipulate images with layers. With it you can resize, crop, make thumbnails, add watermarks and more. Here is an example:
// We initialize the norway layer from the picture norway.jpg
$norwayLayer = ImageWorkshop::initFromPath('/path/to/images/norway.jpg'); 

// We initialize the watermark layer from the picture watermark.png
$watermarkLayer = ImageWorkshop::initFromPath('/path/to/images/watermark.png'); 

$image = $norwayLayer->getResult(); // This is the generated image ! 

header('Content-type: image/jpeg');
imagejpeg($image, null, 95); // We choose to show a JPG with a quality of 95%
exit;
ImageWorkshop is developed to make easy the most common cases for manipulating images in PHP. If you need something more powerful though, you should look at theImagine library.

6. Snappy – Snapshot/PDF Library

Snappy is a PHP5 library that allows you to take snapshots or PDFs of URLs or HTML documents. It depends on the wkhtmltopdf binary, which is available on Linux, Windows and OSX. You use it like this:
require_once '/path/to/snappy/src/autoload.php'; 

use Knp\Snappy\Pdf; 

// Initialize the library with the
// path to the wkhtmltopdf binary:
$snappy = new Pdf('/usr/local/bin/wkhtmltopdf'); 

// Display the resulting pdf in the browser
// by setting the Content-type header to pdf: 

header('Content-Type: application/pdf');
header('Content-Disposition: attachment; filename="file.pdf"'); 

echo $snappy->getOutput('http://www.github.com');
Keep in mind that calling external binaries might not be allowed by your hosting provider.

7. Idiorm – Lightweight ORM Library

Idiorm is a personal favorite that I have used in tutorials in this site before. It is a lightweight ORM library and a fluent query builder for PHP5 that is built on top of PDO. With it, you can forget writing tedious SQL:
$user = ORM::for_table('user')
    ->where_equal('username', 'j4mie')
    ->find_one();

$user->first_name = 'Jamie';
$user->save();

$tweets = ORM::for_table('tweet')
    ->select('tweet.*')
    ->join('user', array(
        'user.id', '=', 'tweet.user_id'
    ))
    ->where_equal('user.username', 'j4mie')
    ->find_many();

foreach ($tweets as $tweet) {
    echo $tweet->text;
}
Idiorm has a sister library called Paris, which is an Active Record implementation built on top of it.

8. Underscore – PHP’s Utility Belt

Underscore is a port of the original Underscore.js – the utility belt for JavaScript applications. The PHP version doesn’t disappoint and has support for nearly all of the original’s functionality. Some examples:
__::each(array(1, 2, 3), function($num) { echo $num . ','; }); // 1,2,3,

$multiplier = 2;
__::each(array(1, 2, 3), function($num, $index) use ($multiplier) {
  echo $index . '=' . ($num * $multiplier) . ',';
});
// prints: 0=2,1=4,2=6,

__::reduce(array(1, 2, 3), function($memo, $num) { return $memo + $num; }, 0); // 6

__::find(array(1, 2, 3, 4), function($num) { return $num % 2 === 0; }); // 2

__::filter(array(1, 2, 3, 4), function($num) { return $num % 2 === 0; }); // array(2, 4)
The library also has support for chaining, which makes it even more powerful.

9. Requests – Easy HTTP Requests

Requests is a library that makes it easy to issue HTTP requests. If you are like me, and can never seem to remember the various options passed to Curl, this is for you:
$headers = array('Accept' => 'application/json');
$options = array('auth' => array('user', 'pass'));
$request = Requests::get('https://api.github.com/gists', $headers, $options);

var_dump($request->status_code);
// int(200)

var_dump($request->headers['content-type']);
// string(31) "application/json; charset=utf-8"

var_dump($request->body);
// string(26891) "[…]"
With this library, you can send HEAD, GET, POST, PUT, DELETE and PATCH HTTP requests, add files and parameters with arrays, and access all the response data.

10. Buzz – Simple HTTP Request Library

Buzz is another PHP library for issuing HTTP requests. Here is an example:
$request = new Buzz\Message\Request('HEAD', '/', 'http://google.com');
$response = new Buzz\Message\Response();

$client = new Buzz\Client\FileGetContents();
$client->send($request, $response);

echo $request;
echo $response;
It is lacking in documentation, so you will have to read through the source code to get a feel of all the options that it supports. Or you can go with the Requests library that I presented above.

11. Goutte – Web Scraping Library

Goutte is a library for scraping websites and extracting data. It provides a nice API that makes it easy to select specific elements from the remote pages.
require_once '/path/to/goutte.phar'; 

use Goutte\Client; 

$client = new Client();
$crawler = $client->request('GET', 'http://www.symfony-project.org/'); 

// Click on links: 

$link = $crawler->selectLink('Plugins')->link();
$crawler = $client->click($link); 

// Extract data with a CSS-like syntax: 

$t = $crawler->filter('#data')->text(); 

echo "Here is the text: $t";

12. Carbon – DateTime Library

Carbon is a simple API extension for the DateTime. It enhances the class with some useful methods for working with dates and time. For example:
printf("Right now is %s", Carbon::now()->toDateTimeString());
printf("Right now in Vancouver is %s", Carbon::now('America/Vancouver'));

$tomorrow = Carbon::now()->addDay();
$lastWeek = Carbon::now()->subWeek();
$nextSummerOlympics = Carbon::createFromDate(2012)->addYears(4);

$officialDate = Carbon::now()->toRFC2822String();

$howOldAmI = Carbon::createFromDate(1975, 5, 21)->age;

$noonTodayLondonTime = Carbon::createFromTime(12, 0, 0, 'Europe/London');

$endOfWorld = Carbon::createFromDate(2012, 12, 21, 'GMT');

// comparisons are always done in UTC
if (Carbon::now()->gte($endOfWorld)) {
    die();
}

if (Carbon::now()->isWeekend()) {
    echo 'Party!';
}

echo Carbon::now()->subMinutes(2)->diffForHumans(); // '2 minutes ago'
Carbon hasn’t seen new commits in the last few months, so you might want to check outDatum, a fork that continues to be worked on.

13. Ubench – Micro Benchmarking Library

Ubench is a micro library for benchmarking your PHP code. It monitors execution time and memory usage. Here’s an example:
use Ubench\Ubench;

$bench = new Ubench;

$bench->start();

// Execute some code

$bench->end();

// Get elapsed time and memory
echo $bench->getTime(); // 156ms or 1.123s
echo $bench->getTime(true); // elapsed microtime in float
echo $bench->getTime(false, '%d%s'); // 156ms or 1s

echo $bench->getMemoryPeak(); // 152B or 90.00Kb or 15.23Mb
echo $bench->getMemoryPeak(true); // memory peak in bytes
echo $bench->getMemoryPeak(false, '%.3f%s'); // 152B or 90.152Kb or 15.234Mb

// Returns the memory usage at the end mark
echo $bench->getMemoryUsage(); // 152B or 90.00Kb or 15.23Mb
It would be a good idea to run these checks only while developing.

14. Validation – Input Validation Engine

Validation claims to be the most awesome validation engine ever created for PHP. But can it deliver? See for yourself:
use Respect\Validation\Validator as v; 

// Simple Validation 

$number = 123;
v::numeric()->validate($number); //true 

// Chained Validation 

$usernameValidator = v::alnum()->noWhitespace()->length(1,15);
$usernameValidator->validate('alganet'); //true 

// Validating Object Attributes 

$user = new stdClass;
$user->name = 'Alexandre';
$user->birthdate = '1987-07-01'; 

// Validate its attributes in a single chain: 

$userValidator = v::attribute('name', v::string()->length(1,32))
                  ->attribute('birthdate', v::date()->minimumAge(18)); 

$userValidator->validate($user); //true
With this library you can validate your forms or other user-submitted data. In addition, it supports a wide number of existing checks, throwing exceptions and customizable error messages.

15. Filterus – Filtering Library

Filterus is another filtering library, but it can not only validate, but also filter input to match a preset pattern. Here is an example:
$f = Filter::factory('string,max:5');
$str = 'This is a test string'; 

$f->validate($str); // false
$f->filter($str); // 'This '
Filterus has a lot of built-in patterns, supports chaining and can even validate array elements with individual validation rules.

16. Faker – Fake Data Generator

Faker is a PHP library that generates fake data for you. It can come handy when you need to populate a test database or generate sample data for your web application. It is also very easy to use:
// require the Faker autoloader
require_once '/path/to/Faker/src/autoload.php';

// use the factory to create a Faker\Generator instance
$faker = Faker\Factory::create();

// generate data by accessing properties
echo $faker->name; // 'Lucy Cechtelar';

echo $faker->address;
  // "426 Jordy Lodge
  // Cartwrightshire, SC 88120-6700"

echo $faker->text;
  // Sint velit eveniet. Rerum atque repellat voluptatem quia ...
As long as you keep accessing properties of the object, it will continue returning randomly generated data.

17. Mustache.php – Elegant Templating Library

Mustache is a popular templating language that has implementations in practically every programming languages. This gives you the benefit that you can reuse your templates in both client and server side. Mustache.php is an implementation that uses – you guessed it – PHP:
$m = new Mustache_Engine;
echo $m->render('Hello {{planet}}', array('planet' => 'World!')); // "Hello World!"
To see more advanced examples, I suggest taking a look at the official Mustache docs.

18. Gaufrette – File System Abstraction Layer

Gaufrette is a PHP5 library that provides a filesystem abstraction layer. It makes it possible to work with local files, FTP servers, Amazon S3 and more in the same way. This permits you to develop your application without having to know how you are going to access your files in the future.
use Gaufrette\Filesystem;
use Gaufrette\Adapter\Ftp as FtpAdapter;
use Gaufrette\Adapter\Local as LocalAdapter; 

// Local files:
$adapter = new LocalAdapter('/var/media'); 

// Optionally use an FTP adapter:
// $ftp = new FtpAdapter($path, $host, $username, $password, $port); 

// Initialize the filesystem:
$filesystem = new Filesystem($adapter); 

// Use it: 

$content = $filesystem->read('myFile');
$content = 'Hello I am the new content';
$filesystem->write('myFile', $content);
There are also caching and in-memory adapters, and more will be added over time.

19. Omnipay – Payment Processing Library

Omnipay is a payment processing library for PHP. It has a clear and consistent API and supports dozens of gateways. With this library, you only need to learn one API and work with a variety of payment processors. Here is an example:
use Omnipay\CreditCard;
use Omnipay\GatewayFactory;

$gateway = GatewayFactory::create('Stripe');
$gateway->setApiKey('abc123');

$formData = ['number' => '4111111111111111', 'expiryMonth' => 6, 'expiryYear' => 2016];
$response = $gateway->purchase(['amount' => 1000, 'card' => $formData]);

if ($response->isSuccessful()) {
    // payment was successful: update database
    print_r($response);
} elseif ($response->isRedirect()) {
    // redirect to offsite payment gateway
    $response->redirect();
} else {
    // payment failed: display message to customer
    exit($response->getMessage());
}
Using the same consistent API makes it easy to support multiple payment processors or to switch as the need arises.

20. Upload – For Handling File Uploads

Upload is a library that simplifies file uploading and validation. When a form is submitted, the library can check the type of file and size:
$storage = new \Upload\Storage\FileSystem('/path/to/directory');
$file = new \Upload\File('foo', $storage);

// Validate file upload
$file->addValidations(array(
    // Ensure file is of type "image/png"
    new \Upload\Validation\Mimetype('image/png'),

    // Ensure file is no larger than 5M (use "B", "K", M", or "G")
    new \Upload\Validation\Size('5M')
));

// Try to upload file
try {
    // Success!
    $file->upload();
} catch (\Exception $e) {
    // Fail!
    $errors = $file->getErrors();
}
This will save you lots of tedious code.

21. HTMLPurifier – HTML XSS Protection

HTMLPurifier (on github) is an HTML filtering library that protects your code from XSS attacks by using a combination of robust whitelists and agressive parsing. It also makes sure that the resulting markup is standards compliant.
require_once '/path/to/HTMLPurifier.auto.php';

$config = HTMLPurifier_Config::createDefault();
$purifier = new HTMLPurifier($config);
$clean_html = $purifier->purify($dirty_html);
The best place to use this library would be when you are allowing users to submit HTML which is to be displayed unmodified on the site.

22. ColorJizz-PHP – Color Manipulation Library

ColorJizz is a tiny library that can convert between different color formats and do simple color arithmetic. For example:
use MischiefCollective\ColorJizz\Formats\Hex;

$red_hex = new Hex(0xFF0000);
$red_cmyk = $hex->toCMYK();
echo $red_cmyk; // 0,1,1,0

echo Hex::fromString('red')->hue(-20)->greyscale(); // 555555
It has support for and can manipulate all major color formats.

23. PHP Geo – Geo Location Library

phpgeo is a simple library for calculating distances between geographic coordinates with high precision. For example:
use Location\Coordinate;
use Location\Distance\Vincenty;

$coordinate1 = new Coordinate(19.820664, -155.468066); // Mauna Kea Summit
$coordinate2 = new Coordinate(20.709722, -156.253333); // Haleakala Summit

$calculator = new Vincenty();
$distance = $calculator->getDistance($coordinate1, $coordinate2); // returns 128130.850 (meters; ≈128 kilometers)
This will work great in apps that make use of location data. To obtain the coordinates, you can use the HTML5 Location API, Yahoo’s API (or both, like we did in the weather web app tutorial).

24. ShellWrap – Beautiful Shell Wrapper

ShellWrap is library that allows you to work with the powerful Linux/Unix command line tools in PHP through a beautiful syntax:
require 'ShellWrap.php';
use \MrRio\ShellWrap as sh; 

// List all files in current dir
echo sh::ls(); 

// Checkout a branch in git
sh::git('checkout', 'master'); 

// You can also pipe the output of one command, into another
// This downloads example.com through cURL, follows location, then pipes through grep to
// filter for 'html'
echo sh::grep('html', sh::curl('http://example.com', array(
    'location' => true
))); 

// Touch a file to create it
sh::touch('file.html'); 

// Remove file
sh::rm('file.html'); 

// Remove file again (this fails, and throws an exception because the file doesn't exist) 

try {
    sh::rm('file.html');
} catch (Exception $e) {
    echo 'Caught failing sh::rm() call';
}
The library throws exceptions when an error occurs in the command, so you can act accordingly. It also can pipe the output of one command as the input of another for even greater flexibility.

Chủ Nhật, 21 tháng 4, 2013

How to Fix The White Screen of Death (Lỗi trang trắng trong wordpress)

Recently, my client had have one product launched and have received some complaints about white screen of death. Then ask for my help.
Typically, the symptom of White Screen of Death is the front-end is okay while the wp-admin is totally blank. It is usually caused by plugin conflict.
It usually occurs when you activate or upgrade a plugin, or theme.
How is a quick way to get it back to working:
  • 1, login to cpanel,
  • 2, navigate to phpmyadmin
  • 3, find your site’s database
  • 4, select wp_options table
  • 5, search option name with “active_plugins
  • 6, backup the value of active_plugins before empty
Try to login to your site again. If it is still not working, maybe theme problem.
From step 5:
5, search option name template and stylesheet
6, replace their values with twentytwelve – the default wordpress theme
To trace the problem:
  • 1, enable wp_debug
  • 2, check php error log file
  • 3, activate plugin one by one until the white screen occurs again.
Note: this method can solve the 500 internal error too.

Thứ Ba, 16 tháng 4, 2013

Các câu lệnh thường dùng trong linux

Góc IT xin giới thiệu với các bạn các câu lệnh thường dùng trong 
Để vào hệ thống file, dùng:
- pwd: xem thư mục hiện hành
- cd: di chuyển đến thư mục
- ls: đưa ra danh sách nội dung thư mục
- mkdir: tạo thư mục mới .
- touch: tạo file mới
- rmdir: bỏ một thư mục
- cp: copy file hoặc thư mục
- mv: di chuyển file hoặc thay đổi tên file
- rm: loại bỏ file
Để tìm kiếm file, bạn có thể dùng:
- find : dùng cho các tên file.
- grep < tiêu chuẩn tìm kiếm>: để tìm nội dung trong file.
Để xem một file, bạn có thể dùng:
- more : hiển thị file theo từng trang.
- cat < tên file>: hiển thị tất cả file.
- head < tên file>: hiển thị các dòng đầu tiên.
- tail < tên file>: hiển thị các dòng cuối cùng (có thể hữu ích trong những trường hợp như khi bạn muốn xem thông tin cuối cùng của một file hệ thống).
Để chính sửa file:  bạn phải sử dụng trình soạn thảo tích hợp sẵn trên dòng lệnh. Thông thường, đây là vi và được dùng với cú pháp: vi .
Để giải nén một lưu trữ  : (thông thường có đuôi tar.gz), bạn phải dùng lệnh tar với cú pháp tar -xvf .
Để in một file : dùng lệnh lpr . Chú ý là bạn phải có một số daemon hoạt động để quản lý máy in. Thông thường đây là các cup (chủ yếu là UNIX Printing System) có thể sử dụng cho tất cả các phân phối chính.
Để loại bỏ file khỏi hàng đợi ở máy in (bạn có thể lên danh sách hàng đợi bằng lệnh lpq), sử dụng câu lệnh lprm .
Để lắp hoặc gỡ bỏ thiết bị (thêm vào hệ thống file với vai trò như một phương tiện được phép sử dụng), dùng:
- mount /mnt/floppy: lắp thêm ổ mềm.
- umount /mnt/floppy: gỡ bỏ ổ mềm.
- mount /mnt/cdrom: lắp ổ CD-ROM.
- mount /mnt/cdrom: gỡ ổ DC-ROM.
Các thiết bị này thường được cài và cho phép sử dụng một cách tự động. Nhưng có thể một ngày đẹp trời nào đó bạn lại phải tự mình thực hiện công việc này khi có lỗi xảy ra. Đừng lo lắng!
Để tạo một phân vùng
Đầu tiên, tạo một thư mục trong /mnt (mkdir /mnt/ổ_đĩa_mới). Sau đó sử dụng lệnh mount (mount /dev/source /mnt/ ổ_đĩa_mới), trong đó /dev/source là thiết bị (tức phân vùng) bạn muốn lắp thêm vào hệ thống file.
Nếu muốn kết nối tới một host từ xa, sử dụng lệnh ssh. Cú pháp là ssh .
Quản lý hệ thống:
- ps: hiển thị các chương trình hiện thời đang chạy (rất hữu ích: ps là cái nhìn toàn bộ về tất cả các chương trình).
Trong danh sách đưa ra khi thực hiện lệnh ps, bạn sẽ thấy có số PID (Process identification – nhân dạng tiến trình).
Con số này sẽ được hỏi đến khi muốn ngừng một dịch vụ hay ứng dụng, dùng lệnh kill .
- top: hoạt động khá giống như Task Manager trong Windows. Nó đưa ra thông tin về tất cả tài nguyên hệ thống, các tiến trình đang chạy, tốc độ load trung bình… Lệnh top -d thiết lập khoảng thời gian làm tươi lại hệ thống. Bạn có thể đặt bất kỳ giá trị nào, từ .1 (tức 10 mili giây) tới 100 (tức 100 giây) hoặc thậm chí lớn hơn.
- uptime: thể hiện thời gian của hệ thống và tốc độ load trung bình trong khoảng thời gian đó, trước đây là 5 phút và 15 phút.
Thông thường tốc độ load trung bình được tính toán theo phần trăm tài nguyên hệ thống (vi xử lý, RAM, ổ cứng vào/ra, tốc độ load mạng) được dùng tại một thời điểm. Nếu tốc độ được tính toán là 0.37, tức có 37% tài nguyên được sử dụng. Giá trị lớn hơn như 2.35 nghĩa là hệ thống phải đợi một số dữ liệu, khi đó nó sẽ tính toán nhanh hơn 235% mà không gặp phải vấn đề gì. Nhưng giữa các phân phối có thể khác nhau một chút.
- free: hiển thị thông tin trên bộ nhớ hệ thống.
- ifconfig : để xem thông tin chi tiết về các giao diện mạng; thông thường giao diện mạng ethernet có tên là eth(). Bạn có thể cài đặt các thiết lập mạng như địa chỉ IP hoặc bằng cách dùng lệnh này (xem man ifconfig). Nếu có điều gì đó chưa chính xác, bạn có thể stop hoặc start (tức ngừng hoặc khởi_động) giao diện bằng cách dùng lệnh ifconfig up/down.
- passwd: cho phép bạn thay đổi mật khẩu (passwd người_dùng_sở_hữu_mật_khẩu hoặc tên người dùng khác nếu bạn đăng nhập hệ thống với vai trò root).
- useradd: cho phép bạn thêm người dùng mới (xem man useradd).
Để thoát hay đóng shell, gõ exit hoặc logout.