HIPAA Compliant Cloud Storage

What is PHP7 Vs. HHVM

Origin Story of the Rivalry Between Facebook and PHP

Back in 2010 Facebook developers announced that they had been working on a solution to the rising costs of running Facebook’s cloud servers. Due to the ever-growing resource demands being placed on Facebook, they needed to develop a solution that would not require them to make substantial changes to their source code but would still offer optimized performance.

Their solution was “HipHop for PHP” (HPHPc), which translated the PHP codebase of Facebook into heavily optimized C++ and then compiled that code with g++. The project’s success was considerable–Facebook boasted that they were able to reduce CPU usage on their web servers by around 50%, translating to a significant reduction in the overhead cost of running their servers.

Because of this success, Facebook open-sourced the project with the goal of showing the web community how easy it was to enhance website performance without having to make major changes to their codebase. Facebook developers often stated during presentations that PHP’s interpreter needed optimization and that that was one of the primary reasons behind their development of the Hip Hop Platform.

PHP’s development team may have taken this criticism by Facebook to heart when they began development of the next generation of PHP; the result of PHP7’s development (which began in 2014) has produced in significant performance upgrades when compared to PHP 5.X. They started by analyzing PHP’s performance on popular platforms such as WordPress, Drupal, and phpBB. By focusing on enhancing performance on these popular web platforms, the development team was able to make small but numerous changes to the existing source code. After over a year of finding, improving, and testing these changes, they found they were able to considerably reduce the source code of PHP, resulting in a faster and more lightweight programming language.
.

The Goals and Features of HHVM

After the success of HPHPc, Facebook decided to invest in developing HPHPc more to push for a more substantial increase in performance and a greater reduction of resources necessary to run one of the internet’s most high-traffic websites. Their next step was to create a virtual machine to execute the HPHPc code, a VM that came to be called the HipHop Virtual Machine (HHVM).

HHVM is a virtual machine that executes programs written in PHP or Facebook’s own Hack programming language. It works by taking PHP or Hack code and converting it into untyped bytecode and metadata, using their own Abstract Syntax Tree to convert PHP and Hack into bytecode that they call HipHopByteCode (HHBC).

HHVM then analyzes the HHBC and converts it into a typed Intermediate Representation(IR). HHVM then converts the IR into x64 machine code and executes the program off the x64 machine code.
.

Summary of HHVM Execution Flow:

PHP source–(parse)–> Abstract Syntax Tree–(emit)–>Bytecode–(analyze)–(intermediate representation)–(codegen)–> x64 machine code.
.

Why Does HHVM Use C++?

It may be confusing to some as to why you would convert PHP code to C++ code. Facebook argues that C++ gives developers a much-needed balance between performance and maintainability, noting that C++ offers many convenient features, such as:

  • virtual methods
  • multiple inheritances
  • templates
  • macros
  • reinterpretcast vs. dynamiccast
  • plain old data vs. constructors/destructors
  • raw pointers vs. references vs. smart pointers
  • stack allocation vs. malloc vs. new

One important thing to take away from these features is that you have to know what your bytecode will look like at compile time to be able to properly customize HHVM to optimize your code.
.

The Goals and Features of PHP 7

PHP 7’s development team sought to improve the performance of their source code with the end goal of having the ability for any website to update to PHP7 to see a substantial increase in performance without having to make any changes to the site’s current code.

They boast that, with the source code streamlining, the decreased memory usage, and the inclusion of an Abstract Syntax Tree to boost the performance of the PHP parser, users can see as much as a doubling in performance compared to PHP 5.x. The addition of a secondary file-based cache for OPcache also further augments the OPCache introduced in PHP 5.3.x.
.

The Major Difference Between HHVM and PHP 7

While HHVM and PHP7 have the same goal of improving the speed and performance of executed PHP code, they both have vastly different ways to accomplish these improvements. One noteworthy difference between the two is the inclusion of the “Just in Time” (JIT) compiler in HHVM. The PHP 7 development team attributed this inclusion as the reason many early benchmarks showed HHVM outperforming PHP 7. So while much of PHP7’s efforts focused on optimizing the source code of PHP, they were also able to include an Abstract Syntax Tree (AST) in the source code for the language. With the inclusion of the AST, PHP7’s development team has set up for the inclusion of a JIT compiler in a future version of PHP 7. A JIT compiler should allow PHP7 to significantly outperform HHVM in any non-Facebook application.
.

Who is the winner?

Despite the rivalry between PHP’s and Facebook’s development teams, both acknowledge that performance will widely vary from system to system. Because both projects are open source, they encourage community feedback to help them further develop and optimize their code. Developers with a large PHP code base now have the potential ability to increase the performance of their PHP code base with HHVM. For those who mostly handle small websites that don’t quite have the resource requirements of Facebook, the optimization and performance updates that PHP 7 brings will help enhance user experience so websites will be able to run as fast as those with any large code base do.
.
.


Features to Simplify Your Cloud Hosting Comparison

Which cloud hosting provider is the best option out there? When you look at infrastructure-as-a-service companies, you will find that the public cloud offered through Atlantic.Net is stronger than those of major competitors including AWS, Digital Ocean, Linode, and Rackspace.

  • Cloud Hosting Comparison
  • Features at Atlantic.Net
  • The Choice is Simple

Cloud Hosting Comparison

Every cloud provider out there wants to differentiate itself from the competition. The fact is that some companies try to outperform their rivals primarily through branding and becoming a recognized name rather than by developing a truly higher-quality product. That is why you see a lot of disappointment in many cloud hosting reviews.

Read More


How to Install and Configure Fail2ban on CentOS

Verified and Tested 4/28/16

Introduction

Fail2ban is a great, wonderful service that is primarily used to stop brute forcers from accessing your system. It’s simple to install and configure and works great at deterring your basic attackers away.

This article is specifically for installation on Centos. To install  and use Fail2Ban in Ubuntu and Debian, check out our how-to on that here.

Installing and configuring Fail2Ban on CentOS

We will be performing steps below as the root user. You will just need to sudo if you are using another user. For all editing of configuration files, we will be using vi. However, you can use whichever editor you are comfortable with. This installation is performed on a clean CentOS 6.5 64bit cloud server.

Read More


How to: FTP Uploads with Python

Introduction

In another article on using ftplib in Python, we talked about using Python’s ftplib library to connect to an FTP server and download both binary and text files to our local machine. In this segment, I’ll introduce several new concepts, including uploading text and binary files, error handling, and common directory commands using the same imported library.
.

Prerequisites

It is difficult to experiment with many of these calls with a server that you don’t own–most FTP servers will not allow anonymous logins. Assuming you do not have access to a web-based FTP server, your best bet is to install a server on your local machine (see “Installing an FTP server“) and test your code using localhost as the target server.
.

FTP Uploads

As with downloads, you’ll need to specify whether a file you wish to upload to a server is a text file or a binary file since each uses a different method. You can upload text files using the storlines() method and binary files with the storbinary() method. A nice feature of these functions is that neither one requires you to write a separate function to handle reading the source file: storlines() calls the readline() method on each line in the file until it reads the last line, while storbinary() uses the read() method until there is no more data to read and upload.

Read More


How to Install Your Own FTP Server

Introduction

If you’re interested in learning about networking, or if you have files that you would like to share with the world at large, then at some point you’re probably going to want to get an FTP server running on a machine. There is a vast array of options for a server, depending on what operating system your server is running and how much work you want to put in to setting it up. Read on for instructions on how to get free FTP servers up and running quickly using Linux, Mac, or Windows. All of the software mentioned here is free; paid FTP server programs do exist, but almost anything you need to do with an FTP server can be done with an open-source program.

Read More


How to: Useful pip Commands

Introduction

A good knowledge of how to use the pip command to manage Python packages can make the difference between a jumbled mess of spaghetti code and a nicely organized codebase. This guide will teach you the basics of using pip effectively so you can spend more time writing, and less time wrangling code.

.

Prerequisites

Read More


A Tale of Stack-Worthiness: The Rise of Nginx

Nginx has accrued increasingly impressive market share in recent years. What’s its story?

  • WordPress Developer Switches to LEMP
  • Nginx is Not Slowing its Pace
  • How the Web is Being Won
  • Growth of Nginx & LEMP to Fuel Your Own Project

WordPress Developer Switches to LEMP

The LAMP stack (open source development environment using Linux, Apache, MySQL, and PHP) has always been incredibly popular among developers, but in the past few years, that has started to change. What people are starting to use instead is called a LEMP stack, which replaces the Apache web server with a Russian little-engine-that-could competitor, Nginx (pronounced “Engine X” – hence the E in LEMP). Keep in mind that the code for Nginx is free, open-source, and is identified by the official site as both NGINX and nginx.

Read More


How to Install LEMP on Ubuntu 15.10 (Linux, Nginx, MySQL and PHP)

Verified and Tested 10/26/15

Introduction

This how-to will go through the process of installing at LEMP stack on Ubuntu 15.10. LEMP is very similar to LAMP, with one significant difference, you are installing NGINX instead of Apache. NGINX development has focused on performance, which is why many are beginning to migrate to NGINX web servers and away from Apache. This guide will still be using MySQL and PHP.

Prerequisites

A server with Ubuntu 15.10 installed.

Installing LEMP on a Ubuntu 15.10 Cloud Server

First we want to make sure that your server is up to date by running the commands:

sudo apt-get update

Note: Depending on your installation you may need to remove apache2. You can do that by running the commands:

sudo apt-get remove apache2*

Followed by:

sudo apt-get autoremove

 

Installing Nginx on Ubuntu 15.10

To install Nginx, use the command:

sudo apt-get install nginx

Hit Enter, when it asks,”Do you want to continue?”

Start the Nginx service with the following command:

sudo service nginx start

Verify that NGINX is working by opening your browser and entering your IP address or hostname.

Don’t know your IP address? No problem, run the following command:

ifconfig

You will get an output similar to the one below. Next to eth0 we can see that the inet addr is 192.168.0.192. That is your IP address.

This is an example of ifconfig that shows the IP address of 192.168.0.192

This is an example of ifconfig that shows the IP address of 192.168.0.192

So in our browser we would go to http://192.168.0.192.

Once you have entered your IP address or Hostname, you should get a web page similar to the following.

This is an example of the default web page for NGINX on Ubuntu 15.10

This is an example of the default web page for NGINX on Ubuntu 15.10

Now that Nginx is installed, we can move on to installing MySQL.

Installing MySQL on Ubuntu 15.10

Install MySQL with the command:

sudo apt-get install mysql-server

Hit Enter, when it asks,”Do you want to continue?”

During the install, a screen similar to the one below will pop up. You need to create a MySQL root password. Choose a password of your choice, It should be a strong password.

Set a secure password for the MySQL root password

Set a secure password for the MySQL root password

Hit enter to continue. Once you have hit enter, a new screen will appear prompting you to re-enter the password you just picked.

Reenter your MySQL root password

Reenter your MySQL root password

MySQL is now installed, but we add some basic security by running the MySQL secure installation:

sudo mysql_secure_installation

It will first prompt you to enter your MySQL root password, which you can do so.  After it will ask you to “Change the root password?”, type N and then press Enter. The rest of the question you can hit Enter for the defaults unless there are certain things you would like to keep open.

This is an example of the MySQL secure installation

This is an example of the MySQL secure installation

Now that MySQL is installed, we can now install PHP.

Installing PHP on Ubuntu 15.10

Install PHP with the following command:

sudo apt-get install php5 php5-fpm php5-mysql

Hit Enter, when it asks, “Do you want to continue?”

To get Nginx to work with PHP correctly, we need to make changes to the Nginx configuration file. This guide we will be using a simple Nginx config file.

First, we are going to move the original configuration file to a new filename. Run the command:

sudo mv /etc/nginx/sites-available/default /etc/nginx/sites-available/default.old

Next using a text editor of your choice, we are going to make a file called default in /etc/nginx/sites-available. For nano use the command:

sudo nano /etc/nginx/sites-available/default

Copy the following into your text editor:

server {
        listen       80;
        server_name  your_site_name.com;
        root /usr/share/nginx/html;
        index index.php index.html;

        location / {
                try_files $uri $uri/ =404;
        }

        error_page 404 /404.html;
        error_page 500 502 503 504 /50x.html;

        location = /50x.html {
                root /var/www/html;
        }

        location ~ \.php$ {
                try_files $uri =404;
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
        }
}

In nano, to exit and save, hit Ctrl+x , Ytype , and then Enter.

Since we made changes to the configuration file, we need to restart Nginx, by running the command:

sudo service nginx restart

To test PHP, we are going to create a file called info.php.

Using a text editor of your choice, create info.php in /usr/share/nginx/html/.

sudo nano /usr/share/nginx/html/info.php

Copy the following into your text editor.

<?php
phpinfo();
?>

In your browser, you can go to http://Your-Hostname/info.php or http://Your-IP-Address/info.php. As above, in this example, we would use http://192.168.0.192/info.php.

You should get a web page that shows the version of PHP among other things, it will look like the image below.

This is an example of the PHP.info page on Ubuntu 15.10

This is an example of the PHP.info page on Ubuntu 15.10

Now that we verified that the info.php is working, it is a good idea to remove it as it gives a potential attacker information that can be used to craft a particular attack against your server. To do that run the command:

sudo rm /usr/share/nginx/html/info.php

Congratulations, you have installed LEMP on Ubuntu 15.10. Thank you for following this how-to. Please check back for more updates, or learn more about our reliable HIPAA-compliant cloud storage solutions.


What is: PHP7 – Breaking Changes from PHP5

PHP7 Elephant created by Walker Cahall http://www.waltronic.net/

PHP7 Elephant created by Walker Cahall

Target Audience

This article is geared toward readers with at least a working knowledge of PHP or a thorough knowledge of programming.
.

Introduction

PHP is one of those ubiquitous programming languages that underpins many of the most popular web platforms. With the release of PHP7–the first major revision to PHP in years–the governing body has taken the opportunity to add new features, deprecate others, and remove those that were previously deprecated. To make the transition from older versions to PHP7, developers will likely want to familiarize themselves with these changes to take advantage of the increased performance and to learn how these improvements may affect their code.

In this article, we focus on some of the breaking changes from PHP5 to PHP7.

 

Uniform Variable Syntax

Nested variables often resulted in code that was difficult to read as variable assignment was read right-to-left. Variable resolution now happens left-to-right in an effort to make code-writing and -reading a simpler task.

// code // old evaluation // new evaluation
$$atlantic[‘dot’][‘net’] ${$atlantic[‘dot’][‘net’]} ($$atlantic)[‘dot’][‘net’]
$atlantic->$dot[‘net’] $atlantic->{$dot[‘net’]} ($atlantic->$dot)[‘net’]
$atlantic->$dot[‘net’]() $atlantic->{$dot[‘net’]}() ($atlantic->$dot)[‘net’]()
atlantic::$dot[‘net’]() atlantic::{$dot[‘net’]}() (atlantic::$dot)[‘net’]()

.
Old code can achieve the same effect in PHP7 with the use of braces ({}) as in the center column above.
.

Removal of ASP and Script Tags

PHP7 will no longer recognize alternative tags such as <%, <%=, %>, and <script language="php">. PHP7 will only recognize the traditional <?php and ?>.
.

Removal of Deprecated Extensions and Features

The ereg extension and all ereg_* associated functions have been removed (deprecated in PHP 5.3) and replaced by the PCRE extension: preg_*.

The MySQL function (deprecated since PHP 5.5) has also been changed from mysql_* to mysqli_*.

The assignment of new by reference will now produce an error.

.

Multiple Default Cases Disallowed in a Switch

In what might qualify as an outlier intended usage, switch will no longer accept multiple default statements. In earlier PHP versions, switch would have evaluated the final default in the example below.

switch ($expr) {
default:
neverExecuted();
break;
default:
executed();
}

But in PHP7, the result of this code will be: Fatal error: Switch statements may only contain one default
.

PHP4 Constructors Are Now Deprecated

PHP4 constructors are methods that have the same name as the class they are defined in. PHP7 will emit an E_DEPRECATED when encountering a PHP4 constructor (in PHP8 this method will no longer be recognized as a constructor). This change may only produce problems with custom error handlers.
.

Redefinition of Function Parameter when the Name is Duplicated

In a fashion similar to the behavior of multiple defaults in a switch statement (see above), using duplicate parameter names within a function definition would return the final value. In PHP7, this redefinition attempt will produce an error.

function foo($bar, $bar) {....} // Return Fatal error: Redefinition of parameter $bar in /duplicate_names.php

.

Hex String No Longer Recognized as Numerical

To clear up inconsistent handling of hexadecimal numbers, PHP7 will no longer recognize a hex string as a number. This change will primarily affect the is_numeric() function and the mathematical operators (e.g., ==, +, -, *, /, %, **, ++, and –)

// In PHP5
var_dump(is_numeric('0x16a'));
// Return bool(true)

// In PHP7
var_dump(is_numeric('0x16a'));
// Return bool(false)

.

Invalid Octal Error

An invalid octal literal (such as one containing a non-octal digit) will now produce an error, instead of making a best-effort to render the value.

 // In PHP5
$octal = 0149;
echo $octal; // Display 12 (rendering octal value 0014)

// In PHP7
$octal = 0148;
echo $octal;
// Return: Parse Error: Invalid numeric literal...

.

Division by Zero Results Change

PHP7 adjusts how it reacts to situations in which it attempts to divide a value by zero. In previous versions, division by zero resulted in a boolean false. Now, dividing (/) by zero will return a float INF or NAN; using a zero divisor in a modulus (%) operation will return an error.

var_dump(5/0); // will result in float(INF)
var_dump(0/0); // will result in float(NAN)

var_dump(5%0); // will produce DivisionByZeroError

 

 

Thank you for reading, and good luck as you migrate your code to PHP7. Check out our how-to’s on installing PHP7  and try it yourself (CentOSDebian, Ubuntu).  For a more comprehensive dive into all the changes and the reasons behind those changes, see the PHP7 RFC list.   Altantic.Net offers many cloud hosting solutions, managed cloud hosting, one-click application installs and many other hosting solutions.

Learn more about our reliable HIPAA-compliant storage hosting solutions..


How to Try PHP7 on a Debian 8.2 LAMP Stack

PHP7 Elephant created by Walker Cahall http://www.waltronic.net/

PHP7 Elephant created by Walker Cahall

Verified and Tested 10/8/15

Introduction

In this How-To, we will be installing PHP7 on a Debian 8.2 LAMP stack. PHP7’s expected release date is sometime in November 2015. If you plan on upgrading to the new version of PHP, you can use this guide to install PHP7 so that you can test your code. This guide will be show you how to install the PHP7 Beta or Nightly Build from repo.

NOTE: Since PHP7 is in development do not use this in production, this guide is only meant to get you ready for the actual release.

Prerequisites

A server with Debian 8.2 installed is required, which will take care of the Linux portion of the LAMP stack install.

Installing LAMP on Debian 8.2 with PHP7

We need to add the PHP7 early access repo to your sources list with the following command:

echo "deb http://repos.zend.com/zend-server/early-access/php7/repos ubuntu/" >> /etc/apt/sources.list

After adding the PHP7 early access repo, we should now update the system with the following command:

apt-get update

Installing Apache on Debian 8.2

The next thing we need is to install Apache; you can do so with the following command:

apt-get install apache2

During the install, hit enter when it asks “Do you want to continue?”

Now that Apache is installed, we can check to see if it running with the following command:

service apache2 status

 Another way to check to see if Apache is working is by opening your web browser and then go to http://youripaddress

To get your IP address you can run the following command:

ifconfig
An example of ifconfig showing the IP address of 172.20.6.154

An example of ifconfig showing the IP address of 172.20.6.154

Using the above example we would put  http://172.20.6.154 in the address bar of our browser:

The default page for Apache on Debian 8.2

The default page for Apache on Debian 8.2

Installing MariaDB on Debian 8.2

We are now going to add a database management system, however, if your code does not require a database, you can skip this section. Install MariaDB with the following command:

apt-get install mariadb-server

During the install, hit enter when it asks “Do you want to continue?”

It will also prompt you to enter a MariaDB root password. Set a strong password of your choosing. After entering your password, hit enter to continue.

Enter a strong password of your choice

Enter a strong password of your choice

After hitting enter, it will prompt you to reenter the password, do so and then hit enter to continue.

Re-enter the password you set before

Re-enter the password you set before

After the install completes, we need to run the MariaDB Security installation with the following command:

mysql_secure_installation

Note: During the MariaDB Security installation, you will be prompted with a series of questions. For standard setups,  type N for the change root password question (since you just set it) and Y for yes on all of the rest, see the screen shot below:

An example of what mysql_secure_installation looks like

An example of what mysql_secure_installation looks like using MariaDB

You can check that MariaDB is running with the following command:

service mysql status

Installing PHP7 on Debian 8.2

We can now install PHP7. Below you can find the two choices of the Nightly or the Beta builds. As the nightly build is more up to date, it has more fixed bugs than the Beta version, so I would suggest the nightly.

PHP7 Nightly Build Install:

apt-get install php7-nightly

PHP7 Beta 1 Install:

apt-get install php7-beta1

During the install, hit enter when it asks “Do you want to continue?”

After hitting enter,  you will also get a warning similar to below.

WARNING: The following packages cannot be authenticated!
  php7-nightly
Install these packages without verification? [y/N]

Type Y and then hit Enter to continue.

Getting PHP7 to work with Apache

We need to move the  libraries and modules of PHP7  to the Apache directories with the following commands:

cp /usr/local/php7/libphp7.so /usr/lib/apache2/modules/
cp /usr/local/php7/php7.load /etc/apache2/mods-available/

After moving the files, we need to edit /etc/apache2/apache2.conf and add the following lines to the bottom of the file.

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Now that we fixed the apache2.conf run the following command to enable the PHP mpm module and switch to mpm_prefork.

a2dismod mpm_event && a2enmod mpm_prefork && a2enmod php7

Restart Apache so that the changes we made take effect:

service apache2 restart

Testing PHP 7 on Debian 8.2

To test out PHP7, we are going to create a PHP file a called info.php in /var/www/html/  by using your favorite editor and inserting the following lines of code.

<?php
phpinfo();
?>

Now we can go back to your browser and update the following hyperlink with your IP address.

http://youripaddress/info.php

The result of the php.info file you made, using PHP7

The result of the php.info file you made, using PHP7

At the top of the page, check that the PHP version is  7.0 or higher.

Now that we verified that it is working, we should remove your info.php as hackers could use this information to set up attacks directed at the specific version of PHP you are running. Remove it with the following command:

rm /var/www/html/info.php

Congratulations on installing PHP7 with LAMP on your Debian 8.2 Server! Thank you for following this How-To, and please check back for more updates and to learn more about our reliable HIPAA-compliant cloud storage hosting solutions.


New York, NY

100 Delawanna Ave, Suite 1

Clifton, NJ 07014

United States

San Francisco, CA

2820 Northwestern Pkwy,

Santa Clara, CA 95051

United States

Dallas, TX

2323 Bryan Street,

Dallas, Texas 75201

United States

Ashburn, VA

1807 Michael Faraday Ct,

Reston, VA 20190

United States

Orlando, FL

440 W Kennedy Blvd, Suite 3

Orlando, FL 32810

United States

Toronto, Canada

20 Pullman Ct, Scarborough,

Ontario M1X 1E4

Canada

London, UK

14 Liverpool Road, Slough,

Berkshire SL1 4QZ

United Kingdom

Resources