Loading...

How to Up and Running with the Fastest PHP Framework on PHP7 in 5 Mins

View: 407    Dowload: 0   Comment: 0   Post by: hanhga   Category: Php&mySql   Fields: Other

In this post, we’ll go through the process of getting it up and running in 5 minutes on one of our Homestead Improved instances. If you’re not interested in why or what Phalcon is, just skip ahead to “Setting it up”.

 

Recap

If you’re not familiar with it, Phalcon is a PHP framework written in Zephir, a language mid-way between C and PHP that helps in developing PHP extensions without having to know C. It’s a golden middle ground which lets PHP developers develop highly optimized modules for their programming language environment without the overhead of learning a completely new language, because Zephir compiles into C, which is what PHP extensions are made of.

Originally, Phalcon was an extension written in pure C – which made it incredibly fast. However, this also introduced massive overhead in fixing bugs or inspecting what’s going on under the hood when something doesn’t work the way it should. It also took ages to add new features, since developing in C is so much more difficult. In version 2, Phalcon was rewritten in Zephir, but as PHP 7 was looming on the horizon and announced a dramatic departure from the extension API of PHP 5+, Zephir could not compile code to PHP 7 compatible extensions and was left behind in PHP 5 land.

We try to walk the bleeding edge here, and there was no more room for Phalcon in our arsenal. With our Homestead Improved box up and running and powering all our tutorials, and with PHP 7’s performance advances making up for any kind of speed gains Phalcon may have offered in PHP 5 time, the cost of installing Phalcon was no longer worth it in any way.

Recently, things have changed: Phalcon went 3.0 LTS.

Apart from following Semver from now on, supporting the 3.0 version for the next 3 years, and various new features and changes you can read about in the post, the biggest update by far is the fact that Zephir now supports PHP 7, and allows for not only the compilation of Phalcon, but also the compilation of any other Zephir code into PHP 7 as well. You can now easily port your custom extensions to Zephir, and have them compiled into PHP 7 in a jiffy. A compiled framework combined with PHP 7’s performance gains offers unparalleled advantages in terms of speed and resource conservation.

Setting it Up

We’ll now go through the process of setting up Phalcon 3 on a PHP 7 powered Homestead Improved instance. You can use any kind of environment you feel comfortable in, but the instructions below will be specific to an Ubuntu 16.04 instance with PHP 7+ installed, and things like Git and Wget present. We’ll also use the Homestead Improvedway of defining new sites, via the Homestead.yaml file.

Installing Phalcon

sudo apt-get install software-properties-common
sudo apt-add-repository ppa:phalcon/stable
sudo apt-get update
sudo apt-get install php7.0-phalcon
sudo phpenmod -v 7.0 -s ALL phalcon
sudo service php7.0-fpm restart

The second to last command is a shortcut command to enable a PHP extension. The -v flag tells it which PHP version to activate it for (we want only 7.0 here) and which SAPI (command line, FPM, or both – we want both).

If this tool is not available on your system, then just copy the ini file into the extensions folder like so:

sudo cp /etc/php/7.0/mods-available/phalcon.ini /etc/php/7.0/fpm/conf.d/20-phalcon.ini
sudo cp /etc/php/7.0/mods-available/phalcon.ini /etc/php/7.0/cli/conf.d/20-phalcon.ini

The 20 prefix indicates priority, in case some extensions need to be loaded before others. This is not the case here.

We’ve now unleased the beast. Looking at phpinfo(), it’s there.

Demo Phalcon App

We can test things on a demo Phalcon application – the finished Invo app.

Configuring Nginx for Phalcon

We need to add our app into the Sites block of Homestead.yaml:

- map: phalcon-tut.app
      to: /home/vagrant/Code/phalcon-tut/public

Make sure phalcon-tut.app or what ever vhost name you choose is added to your host OS /etc/hosts file in order to resolve to the VM’s IP address.

Of course, we also need to run vagrant provision outside the VM in order to apply this Nginx setup.

Finally, we edit Nginx’s location block, and change from

location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

to

location / {
        try_files $uri $uri/ /index.php?_url=$uri&$args;
    }

We need to restart Nginx to apply the changes:

sudo service nginx restart

This takes care of the server end of things.

Bootstrapping the app

cd /home/vagrant/Code
git clone https://github.com/phalcon/invo phalcon-tut

Once the app has been cloned, we need to initialize its database, as per instructions. We’ll update those to be a bit more modern, by using utf8mb4 instead of utf8.

echo 'CREATE DATABASE invo CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci' | mysql -u homestead -psecret
cat schemas/invo.sql | mysql -u homestead -psecret invo

There’s one more step which isn’t described in the app’s repo – changing the baseUri in the configuration. We have to go into app/config/config.ini and change baseUri to /, otherwise assets (JS/CSS) will fail to load.

After doing that, sure enough, INVO is up and running.

How to Up and Running with the Fastest PHP Framework on PHP7 in 5 Mins

In this post, we’ll go through the process of getting it up and running in 5 minutes on one of our Homestead Improved instances. If you’re not interested in why or what Phalcon is, just skip ahead to “Setting it up”.

Posted on 24-08-2016 

Comment:

To comment you must be logged in members.

Files with category

  • Twitter-like Hashtag Function in PHP

    Twitter-like Hashtag Function in PHP

    View: 215    Download: 1   Comment: 0

    Category: Php&mySql     Fields: none

    If you ever want a function to hashtag and style words within a string which has '#' next to it like twitter. This piece of code will help

  • PSITS Automated Voting System

    PSITS Automated Voting System

    View: 233    Download: 12   Comment: 0

    Category: Php&mySql     Fields: none

    A free sourcecode for PSITS Automated Voting System develop in PHP programming language. The purposed of the system is to automate the process of voting and maintain the quality of data

  • PHP-University Application System

    PHP-University Application System

    View: 206    Download: 13   Comment: 0

    Category: Php&mySql     Fields: none

    Greeting from Malawi the warm heart of Africa. I developed this university registration system project just to share with the people who can make use of the project like this and at the same time for others like students who can learn from it. This...

  • School Event Management System in PHP/MSQLi

    School Event Management System in PHP/MSQLi

    View: 392    Download: 0   Comment: 2

    Category: Php&mySql     Fields: none

    This School Event Management System can create school events such as Volleyball games, Basketball, Cultural presentation, Election of school officers etc . During school election Instead of having a compile list of candidates and voters this system...

  • Resort Reservation System with PayPal/Credit Card/Debit Card Payment

    Resort Reservation System with PayPal/Credit Card/Debit Card Payment

    View: 186    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    This reservation system has the ability to help its customers find available rooms, cottages and even function hall for their convenience . And in here, they will also have the idea of the room rates where they can quickly reserve for their family...

  • Activity log

    Activity log

    View: 190    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    Simple program to track user's activity log-in time and online/offline status.

  • Electricks - eCommerce

    Electricks - eCommerce

    View: 178    Download: 0   Comment: 0

    Category: Php&mySql     Fields: none

    Electricks is an e-commerce website built using PHP, Bootstrap and some jQuery plugins. It has all the major functionalities of a typical e-shop. This project was used to present in Southern Luzon State University - Lucban. Feel free to use this code...

  • Simple Email App Using PHP

    Simple Email App Using PHP

    View: 156    Download: 1   Comment: 0

    Category: Php&mySql     Fields: none

    Creating a simple PHP script using mail function for sending out emails.

 
File suggestion for you
Loading...
File top downloads
Loading...
Loading...
Codetitle - library source code to share, download the file to the community
Copyright © 2018. All rights reserved. codetitle Develope by Vinagon .Ltd