PHP 7 installation considerations
There are three primary means of acquiring PHP 7:
- Downloading and installing directly from the source code
- Installing pre-compiled binaries
- Installing a *AMP package (that is, XAMPP, WAMP, LAMP, MAMP, and so on)
How to do it...
The three methods are listed in order of difficulty. However, the first approach, although tedious, will give you the most finite control over extensions and options.
Installing directly from source
In order to utilize this approach, you will need to have a C compiler available. If you are running Windows, MinGW is a free compiler that has proven popular. It is based on the GNU Compiler Collection (GCC) compiler provided by the GNU project. Non-free compilers include the classic Turbo C compiler from Borland, and, of course, the compiler that is preferred by Windows developers is Visual Studio. The latter, however, is designed mainly for C++ development, so when you compile PHP, you will need to specify C mode.
When working on an Apple Mac, the best solution is to install the Apple Developer Tools. You can use the Xcode IDE to compile PHP 7, or run gcc
from a terminal window. In a Linux environment, from a terminal window, run gcc
.
When compiling from a terminal window or command line, the normal procedure is as follows:
configure
make
make test
make install
For information on configuration options (that is, when running configure
), use the help
option:
configure --help
Errors you might encounter during the configuration stage are mentioned in the following table:
Error |
Fix |
---|---|
|
You just need to install http://superuser.com/questions/740399/how-to-fix-php-installation-when-xml2-config-is-missing |
|
Install |
|
Not a big deal. These options are defaults and don't need to be included. For more details, please refer to the following link: http://jcutrer.com/howto/linux/how-to-compile-php7-on-ubuntu-14-04 |
Installing PHP 7 from pre-compiled binaries
As the title implies, pre-compiled binaries are a set of binary files that somebody else has kindly compiled from PHP 7 source code and has made available.
In the case of Windows, go to http://windows.php.net/. You will find a good set of tips in the left column that pertain to which version to choose, thread safe versus non-read safe, and so forth. You can then click on Downloads and look for the ZIP file that applies to your environment. Once the ZIP file has been downloaded, extract the files into the folder of your choice, add php.exe
to your path, and configure PHP 7 using the php.ini
file.
To install the pre-compiled binaries on a Mac OS X system, it is best to involve a package management system. The ones recommended for PHP include the following:
- MacPorts
- Liip
- Fink
- Homebrew
In the case of Linux, the packaging system used depends on which Linux distribution you are using. The following table, organized by Linux distribution, summarizes where to look for the PHP 7 package.
Distribution |
Where to find PHP 7 |
Notes |
---|---|---|
Debian |
|
Use this command: sudo apt-get install php7
Alternatively, you can use a graphical package management tool such as Synaptic. Make sure you select php7 (and not php5). |
Ubuntu |
|
Use this command:
Be sure to choose the right version of Ubuntu. Alternatively, you can use a graphical package management tool such as Synaptic. |
Fedora / Red Hat |
|
Make sure you are the root user: su
Use this command: dnf install php7Alternatively, you can use a graphical package management tool such as the GNOME Package Manager. |
OpenSUSE |
|
Use this command: yast -i php7
Alternatively, you can run |
Installing a *AMP package
AMP refers to Apache, MySQL, and PHP (also Perl and Python). The * refers to Linux, Windows, Mac, and so on (that is, LAMP, WAMP, and MAMP). This approach is often the easiest, but gives you less control over the initial PHP installation. On the other hand, you can always modify the php.ini
file and install additional extensions to customize your installation as needed. The following table summarizes a number of popular *AMP packages:
Package |
Where is it found |
Free? |
Supports* |
---|---|---|---|
|
Y |
WML | |
|
Y |
WML | |
|
Y |
WM | |
|
Y |
W | |
|
Y |
W | |
|
N |
WML |
In the preceding table, we've enlisted the *AMP packages where * is replaced by W for Windows, M for Mac OS X, and L for Linux.
There's more...
When you install a pre-compiled binary from a package, only core
extensions are installed. Non-core PHP extensions must be installed separately.
It's worth noting that PHP 7 installation on cloud computing platforms will often follow the installation procedure outlined for pre-compiled binaries. Find out if your cloud environment uses Linux, Mac, or Windows virtual machines, and then follow the appropriate procedure as mentioned in this recipe.
It's possible that PHP 7 hasn't yet reached your favorite repository for pre-compiled binaries. You can always install from source, or consider installing one of the *AMP packages (see the next section). An alternative for Linux-based systems is to use the Personal Package Archive (PPA) approach. Because PPAs have not undergone a rigorous screening process, however, security could be a concern. A good discussion on security considerations for PPAs is found at http://askubuntu.com/questions/35629/are-ppas-safe-to-add-to-my-system-and-what-are-some-red-flags-to-watch-out-fo.
See also
General installation considerations, as well as instructions for each of the three major OS platforms (Windows, Mac OS X, and Linux), can be found at http://php.net/manual/en/install.general.php.
The website for MinGW is http://www.mingw.org/.
Instructions on how to compile a C program using Visual Studio can be found at https://msdn.microsoft.com/en-us/library/bb384838.
Another possible way to test PHP 7 is by using a virtual machine. Here are a couple of tools with their links, which might prove useful:
- Vagrant: https://github.com/rlerdorf/php7dev (php7dev is a Debian 8 Vagrant image that is preconfigured for testing PHP apps and developing extensions across many versions of PHP)
- Docker: https://hub.docker.com/r/coderstephen/php7/ (it contains a PHP7 Docker container)