PHP 7

From wiki.mikejung.biz
Jump to: navigation, search

LiquidWeb API Banner.jpg

PHP 7

Everything in this page is most certainly going to change over time. Some of this might not work for you, so I don't suggest doing this on a production server. If you just want to mess around with PHP 7 and don't care about stability or security or any of that nonsense and you just want to see PHP go fast, then this page is for you. Welcome!


Installing PHP 7 from source on Ubuntu

These commands were taken from the source above. I have slightly modified the commands because the original ones were not copypasta friendly. Make sure you have git installed, then clone the php-src repo. Please note that you must install the packages listed below or else you might get one of these errors when you try to configure PHP 7.

  • configure: error: xml2-config not found. Please check your libxml2 installation.
  • configure: error: bison is required to build PHP/Zend when building a GIT checkout!
  • configure: WARNING: You will need re2c 0.13.4 or later if you want to regenerate PHP parsers.


The errors above can be resolved by installing the autoconf, libxml2-dev, and libxml2-utils packages.

apt-get install git autoconf libxml2-dev libxml2-utils
mkdir ~/tmp
cd ~/tmp
git clone https://git.php.net/repository/php-src.git

If all the right packages are installed, you should be able to cd into the php-src directory, run the buildconf script, then the configure script. I left out all the other options to make the process smoother, so this is a bare bones install. See the link above for the official php documentation.

cd php-src
./buildconf
./configure 
make
make install

If you want to learn more about what the heck is going on during the install process, you should check out the INSTALL file in the php-src directory, there's all kinds of information in that file.

root@ubuntu:~/tmp/php-src# cat INSTALL

Now we make the php.ini file

vim /usr/local/lib/php.ini

##Add the stuff below to the file from above##

max_execution_time=600
memory_limit=128M
error_reporting=0
display_errors=0
log_errors=0
user_ini.filename=
realpath_cache_size=2M
cgi.check_shebang_line=0

zend_extension=opcache.so
opcache.enable_cli=1
opcache.save_comments=0
opcache.fast_shutdown=1
opcache.validate_timestamps=1
opcache.revalidate_freq=60
opcache.use_cwd=1
opcache.max_accelerated_files=100000
opcache.max_wasted_percentage=5
opcache.memory_consumption=128
opcache.consistency_checks=0

At this point you should be able to run php -v and see that you are using PHP 7. Hooray! Obviously you shouldn't be using PHP 7 in production just yet, it's still in development and a lot of stuff may change / improve over the course of the next few months.

php -v


PHP 7.0.0-dev (cli) (built: Mar 22 2015 14:10:17) 
Copyright (c) 1997-2015 The PHP Group
Zend Engine v3.0.0-dev, Copyright (c) 1998-2015 Zend Technologies

Finally, if we run php -m, we can see what modules PHP 7 is using. YAY for ZendOPcache!

php -m


[PHP Modules]
Core
ctype
date
dom
fileinfo
filter
hash
iconv
json
libxml
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
Zend OPcache

[Zend Modules]
Zend OPcache

Configuring Apache Event, mod_fcgid with PHP 7

This section is NOT COMPLETE YET

Install Apache Using apt-get

First we need to install Apache2 with the Event MPM and mod_fcgid

apt-get install apache2 apache2-mpm-event libapache2-mod-fcgid

Installing Apache from source

apt-get install apache2-dev
cd /usr/local/src/
wget http://apache.osuosl.org//httpd/httpd-2.4.12.tar.gz
tar xvf httpd-2.4.12.tar.gz
cd httpd-2.4.12/
./configure --enable-so
make
make install

Configure Apache

Double check that php-cgi is there, if you run which php-cgi it should tell you the location of the binary

which php-cgi

/usr/local/bin/php-cgi

Open up Apache's default vhost configuration file, if you are using Ubuntu 14.10 the file should be located at..

vim /etc/apache2/sites-available/000-default.conf

I removed all the comments from my default apache vhost file and added in some mod_fcgid directives that provide the location of the Fcgid wrapper script as well as some Fcgid process settings.

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

<Ifmodule mod_fcgid.c>
AddHandler fcgid-script .php
Options +ExecCGI
FcgidWrapper /usr/local/bin/php-fcgid-wrapper
</IfModule>
</VirtualHost>

<Ifmodule mod_fcgid.c>

</IfModule>

<IfModule mod_fcgid.c>
    FcgidMaxRequestLen 1073741824
    FcgidMinProcessesPerClass 0
    FcgidMaxProcesses 40
    FcgidIdleTimeout 3
    FcgidProcessLifeTime 30
    FcgidIdleScanInterval 0
    FcgidErrorScanInterval 0
    FcgidZombieScanInterval 0
    FcgidSpawnScoreUpLimit 7000
    FcgidSpawnScore 1
    FcgidTerminationScore -1
    FcgidTimeScore 3
</IfModule>

Using xhprof to profile PHP

How to install xhprof on Ubuntu 14.04

To install xhprof on Ubuntu 14.04 you simply need to install the main PHP packages via apt-get as well as use PECL to install mongo and xhprof-beta

apt-get install build-essential php5 php-pear php5-dev
pecl install mongo
pecl install xhprof-beta

After the packages above have been installed, run the command below to find out where the main php.ini file is located

php -i | grep php.ini

Open up the main php.ini file using vim

vim /etc/php5/cli/php.ini

Scroll down to the bottom of php.ini and add these two lines. Save the php.ini file and then run "php -m" which should display both modules.

extension=xhprof.so
extension=mongo.so

How to install xhgui on Ubuntu 14.04

After you have installed xhprof you can install and configure xhgui if you would like a GUI interface.

apt-get install mongodb git curl
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
cd /var/www/html
git clone https://github.com/perftools/xhgui.git
cd xhgui/
php install.php

PHP Benchmarks

PHP FAQs

What is a PHP engine?

A PHP engine is a program that interprets and executes PHP code. A PHP engine is not part of PHP, it is simply another program that actually runs PHP code. Some current examples of PHP engines are: Zend Engine, as well as HipHopVM (HHVM).

What is a PHP Namespace?

A namespace is a recent PGP feature that organizes PHP code into virtual directories, similar to how most modern file systems work. This allows each vendor to safely use whatever PHP classes are needed without interfering with other vendor's code. PHP namespaces do not map directly to your filesystem layout, so the organization and separation of PHP classes happens virtually.