GY Laboratory-PHALCON+NGINX+PHP-FPM Environment Construction (ext.)

Source: Internet
Author: User
Tags php framework

Phalcon Introduction

Because of halfway decent's sake, not a few PHP frameworks, the first to understand the framework is the company's own, and then try to use the YII,CI. After reading Csdn in some degree of high ranking translation articles (PHP Development Framework popularity rankings: Laravel first), looked at the fur of Laravel. I have to say that Laravel's documentation is beautiful, but as a daemon developer, I always feel that it is not what I want.

The role of the framework: back-and-forth code decoupling, database operations encapsulation, built-in generic program modules (such as routing, authentication, encryption, etc.);

Although the entire site, frame performance is not the main factor, but still want to play it to the extreme, can only say that the programmer's idealism is at work.
Phalcon is the framework. PHP Framework so a direct deal with the business code of Things, are written in a localized language, enough geek. In fact, although the framework only provides code scheduling and encapsulation, its own performance can not be ignored.

Localized language: Is the language that can be compiled into machine code (the kind of code that can run directly on the native CPU), C/C++/OBJ-C, ASM. The advantage is fast and fast implementation, and some hardware API, perhaps only the C interface, so the more interpreted language is more suitable for the embedded domain, the disadvantage is the need to recompile to achieve cross-platform, and the same functionality, the development of complexity than the script and Java to high

1. Ubuntu compilation

The Phalcon approach is to compile the framework code through PHP extensions, allowing the compiled PHP commands to support some framework classes and dependency injection. Compiling is simple

#下载安装依赖库sudo apt-get install php5-dev libpcre3-dev gcc make php5-mysql php5-fpm  #下载git库clone --depth=1 git://github.com/phalcon/cphalcon.gitcd cphalcon/buildsudo ./install#增加/etc/php5/fpm/conf.d/30-phalcon.iniecho‘extension=phalcon.so‘ > /etc/php5/fpm/conf.d/30-phalcon.ini#增加/etc/php5/cli/conf.d/30-phalcon.iniecho‘extension=phalcon.so‘ > /etc/php5/cli/conf.d/30-phalcon.ini
2. Check the PHP extension

Now check that the installation is successful.

php‘echo phpinfo();‘ | grep -i phalcon

If the output below is counted as successful

/etc/php5/cli/conf.d/301.3.4phalcon.db.escape_identifiers => On => Onphalcon.orm.column_renaming => On => Onphalcon.orm.enable_literals => On => Onphalcon.orm.events => On => Onphalcon.orm.exception_on_failed_save => Off => Offphalcon.orm.not_null_validations => On => Onphalcon.orm.virtual_foreign_keys => On => Onphalcon.register_psr3_classes => Off => Off

It can also be detected in the following way:

php‘echo print_r(get_loaded_extensions());‘

If the output below is counted as successful

Array(    [0] => Core    [1] => date    [2] => ereg    [3] => libxml    [4] => openssl    ...
3. Nginx Configuration

Installation of Nginx is omitted

Configuration modification: Modify/etc/nginx/site-avaliable/default or/etc/nginx/conf.d/default, depending on/etc/nginx/nginx.conf configuration and personal preferences

Here for testing, two domain names are configured in the default file, with a total of 8080 ports

Server{Listen   8080Default_server;server_name~^(.+)$;Indexindex.php index.html index.htm;Set $root _path '/srv/www/htdocs/phalcon-website/public ';Root $root _path;Try_files $uri $uri/@rewrite; Location @rewrite{rewrite ^/(.*)$/index.php?_url=/ $; } Location ~* ^/(css|img|js|flv|swf|download)/(. +) ${Root $root _path; } Location ~/\.ht{DenyAll } Location ~ \.php${Fastcgi_index/index.php;Fastcgi_pass Unix:/var/run/php5-fpm.sock;includeFastcgi_params;Fastcgi_split_path_info      ^ (. +\.php) (/.+) $;Fastcgi_paramPath_info$fastcgi _path_info;Fastcgi_paramPath_translated$document _root$fastcgi _path_info;Fastcgi_paramScript_filename$document _root$fastcgi _script_name; }}Server{Listen   8080;#这里在测试时用store_server域名, this machine needs to be bound to the hosts to parse    server_nameStore_server;Indexindex.php index.html index.htm;Set $root _path '/srv/www/htdocs/store/public ';Root $root _path;Try_files $uri $uri/@rewrite; Location @rewrite{rewrite ^/(.*)$/index.php?_url=/ $; } Location ~* ^/(css|img|js|flv|swf|download)/(. +) ${Root $root _path; } Location ~/\.ht{DenyAll } Location ~ \.php${Fastcgi_index/index.php;Fastcgi_pass Unix:/var/run/php5-fpm.sock;includeFastcgi_params;Fastcgi_split_path_info      ^ (. +\.php) (/.+) $;Fastcgi_paramPath_info$fastcgi _path_info;Fastcgi_paramPath_translated$document _root$fastcgi _path_info;Fastcgi_paramScript_filename$document _root$fastcgi _script_name; }}
4. Phalcon-devtools Installation

This is a Phalcon scaffolding tool that supports a set of commands that automatically generate code for you.

clone git://github.com/phalcon/phalcon-devtools.gitcd-s ~/devtools/phalcon.php /usr/bin/phalcon

Then execute phalcon commands , the command prompt will appear

Phalcon DevTools (1.3.4)Available commands:  commands (alias of: list, enumerate)  create-controller)  model (alias of: create-model)  all-models (alias of: create-all-models)  project (alias of: create-project)  scaffold  migration  webtools

Execute create-project to generate a set of framework code!

/srv/www/htdocs/ && phalcon create-project store
5. Start the server

Finally, a little excitement, haha.

#重启fpm和nginxsudo service php5-fpm restartsudo service nginx restart

Then the native binding Host:store_server, in the browser bar input store_server:8080, you can see the big congratulations!

6. Server Virtual user name modification

You may encounter permissions issues during the process, either because Nginx creates a subprocess or php5-fpm creates a child process, which is used by www-data user names and groups.
To modify the default value, assign the value to a custom value. Please modify the user and group of/etc/nginx/nginx.conf and/etc/php5/fpm/pool.d/www.conf respectively.

At this point, the environment is set up, the next to explore the various internal mechanisms of Phalcon it!

GY Laboratory-PHALCON+NGINX+PHP-FPM Environment Construction (ext.)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.