Một vài lưu ý khi cài đặt php7 (php-fpm) từ source code trên linux (fedora)

Giả sử bạn muốn cài đặt trên fedora, php7, php-fpm với nginx là proxy hứng request đẩy qua cho php xử lý (thông qua php-fpm).

Khi cài đặt từ source code có thể bạn sẽ gặp những vấn đề sau:

  1. Thiếu các thư viện khi chạy lệnh ./congigure
  2. Chỉ định đường dẫn đến thư mục sẽ cài php mà bạn muốn( hữu ích khi bạn muốn cài nhiều phiên bản php trên môi trường làm việc của bạn).
  3. Chỉ định đường dẫn đến file php.ini
  • Thiếu các thư viện khi chạy lệnh ./congigure

Tuỳ theo các tuỳ chọn của bạn, khi chạy lệnh ./configure bạn có thể thiếu những thư viện mà php cần, ví dụ bạn thiếu thư viện liên quan đến utf8 chẳng hạn, hãy dùng yum để tìm

  • Chỉ định đường dẫn đến file php.ini

Khi đó bạn chỉ cần copy file php.ini vào thư mục /etc/php7/php.ini, mọi thay đổi trong file này, sẽ ảnh hưởng đến cấu hình của php trên máy của bạn.

  • Chỉ định đường dẫn sẽ cài php ( hữu ích khi bạn muốn cài nhiều phiên bản php trên môi trường làm việc của bạn).

Lưu ý nữa: khi bạn khởi động php-fpm, mặc định php-fpm sẽ đọc file cấu hình của php-fpm tại /usr/local/etc/php-fpm.conf. Nếu bạn muốn chỉ định đến file cấu hình php-fpm trong thư mục cài đặt php /opt/php7/etc/php-fpm.conf.

 

Đây là script mình lưu trên gíst
https://gist.github.com/nguyentienlong/120af89ab11e5ec48014

Tham khảo:
http://php.net/manual/en/install.pecl.php-config.php
http://php.net/manual/en/install.unix.nginx.php

Laravel 5 BindingResolutionException in Container.php line 827

Error:

laravel-ioc-binding-exception
laravel-ioc-binding-exception

Context that caused this eror

test controller
test controller
foo service with php primitive type
foo service with php primitive type

When working with laravel 5, have you ever ask yourself that how Laravel IOC work, how Laravel IOC can handle concrete class binding instead of defining in somewhere (for laravel in Service providers).

Basically, if you inject a concrete class to another class, it will automatically bind to that class by laravel Container

Overview of Laravel Container (make, build, getDependencies, resolveClass (or nonClass))

Screenshot from 2016-03-14 09:38:57

 

 

 

 

 

laravel 5 container class:
make function
build function
getDependencies function

By default, If you inject a concrete class to another class, its will automatically bind and resolve by Laravel container.

Service Container Laravel The PHP Framework For Web Artisans
Service Container Laravel The PHP Framework For Web Artisans
laravel ioc build class based on concrete class name
laravel ioc build class based on concrete class name

but, in case in the constructor of some class you inject to a string or non-class parameter, how laravel 5 handle this  https://github.com/laravel/framework/blob/5.2/src/Illuminate/Container/Container.php#L793

laravle-container-getDependencies
laravle-container-getDependencies

Its not acceptable that throw an error if a non-class cannot resolveable, but its not make sense to make a function name resolveNonClass just only throw an error (imo, should handle this 😉

There is many ways to deal with this is that writing an service provider to inject a string to another class like this (basically, a service provider abstract class contains $app instance, just bind a dependency manually into it). This is one way

then register above service provider to config/app.php
 

its works!!!, other way to bypass this, is use Str provider class instead of built in string primitive php type.

foo service with Str class
foo service with Str class

By the way, need to update Laravel Container class to deal with primitive type ??? in this function resolveNonClass https://github.com/laravel/framework/blob/5.2/src/Illuminate/Container/Container.php#L823

laravel fw container resolveNonClass
laravel fw container resolveNonClass

Reference:
https://laravel.com/docs/5.1/container
https://github.com/laravel/framework/blob/5.2/src/Illuminate/Container/Container.php
http://culttt.com/2014/03/24/exploring-laravels-ioc-container/
http://php.net/manual/en/class.reflectionclass.php

 

A note about solid Principles (Demo in Symfony2)

  1. Single responsibility ( a class have only one reason to change, do not mix up (mess up) everything in a class)
  2. Open for extend, close for modification( move common behavior to interface, flip injection – Uncle Bob)
  3. Liskov Substitution Principle, eg: same output format (array , json, specify type of Type- signature must match, preconditions cannot be greater, post conditional at least equal to, exception type must match). All of the derived class (sub class) could be substitutable (interchangeable)
  4. A client should not be forced to implement an Interface that it does not use (return null in a override function ) – split fat interface to smaller interface.
  5. The higher level of inheritance should not depend on the low level of code, it should depend on the abstract class (Inversion of control, Dependency inversion not Dependency injection, not opposite, but complementary) – decoupling code

note:
class extends 1 class, implements multiple interfaces (like java)
interface extends interface
class implement an interface must override all methods

Demo link:
https://github.com/nguyentienlong/solid-principles-demo

Reference:
https://laracasts.com/collections/solid-principles

TODO: translate to Vietnamese, add more code and explanation

release kunvertor.com beta version

This private project was started long time ago (since july, 2015).

Today, I decide to public beta version of kunvertor.com or chuyendoipdf.com

In this project, I used:
+ symfony2, mysql as web app
+ nodejs + redis as real-time server
+ gearman as job queue server
+ apache pdfbox to extract text from pdf (http://pdfbox.apache.org/index.html)

I will spend more time to write more detail about how to implement this stuff.

Now, breath deep and go to sleep 😉