Get started and transition to PHP7 (1)--Homestead based PHP7 and xddebug environments

Source: Internet
Author: User
Tags php development environment php source code docker ps

PHP7 up and running

Real-Park Learning video
The original link of the park learning
PHP7, Xdebug and Homestead

After going through 13 RC versions, PHP 7 finally came. Before we start evaluating the new features of PHP 7, we need to build a separate development environment.

Homestead-a full-feature PHP 7 Box

Install Homestead vagrant Box

Homestead is a vagrant "box" officially maintained by Laravel. It is based on Ubuntu 14.04, a LNMP environment, PHP development commonly used packages and PHP module "packaged" Together, is our deployment of the PHP development environment is one of the most "cool" way. As one of the most popular frameworks in the PHP community, Laravel certainly won't miss the PHP 7 version of Homestead. Next, we'll build a separate vagrant box for testing PHP 7 based on Homestead.

Before you start, you need to install two software on your operating system:

Virtualbox: Our development environment will be deployed and run in a virutalbox virtual machine;
Vagrant: Tools for managing and starting homestead;
If you're not familiar with them, it's okay to download and install them first. After installation, we need to download the Homestead box locally. Open the terminal of the system and run the following command:

vagrant box add laravel/homestead-7


After choosing 1, after that, it is quiet waiting for the homestead download to complete. Upon completion, we use:

vagrant box list

To see the Vagrant box installed locally.

If you can see the red box in the section, it means that the download has been successful.

Installing the Homestead Deployment script

Execute the following command, Clone Homestead deployment project to Local:

git clone -b php-7 https://github.com/laravel/homestead.git Homestead7

After that, go to the Homestead7 directory and execute the initialization script:

cd Homestead7bash init.sh

When finished, in the ~/.homestead directory, there will be a Homestead.yaml file. In the future, all of our LNMP project configurations will be unified in this document.

LNMP Project Settings

Before we start homestead, we need to do some setup first. First, we create a new directory, PHP7, to store the PHP 7 script we wrote.

mkdir php7

Next, we open ~/.homestead/homestead.yaml, the newly created code directory, "add" to homestead, become a site.

In Homestead.yaml, we need to change the two places where the red box is marked:

Folders: Synchronize the source directory on the host to the directory inside the VirtualBox virtual machine;
SITES:MAP Specifies the HTTP root of servername;to for the specified site;
As for the rest of the section, we don't need to change it for the time being, after saving the file, exit the editor.

Vagrant up

When everything is configured, we add a test script demo.php to the new PHP7 directory:

 <?php phpinfo();

After that, go to Homestead7 directory, execute vagrant up command, start homestead-7 box!

After successful startup, the demo.php we added earlier will be automatically synced to the directory we configured in folders, and homestead will automatically add the Nginx configuration file that we defined in sites.

Next, we add a parse record to the/etc/hosts:

192.168.10.10 php7.app

Open the browser, visit http://php7.app/demo.php, if you can see the iconic PHP info page, congratulations, Homestead has been working properly.

Xdebug-debug PHP code Step by step

Compiling and installing Xdebug

After the successful deployment of PHP 7, we want to solve the problem of code debugging, for a slightly more complex project, using Var_dump () print variable debugging is very inconvenient, and it is not conducive to our dynamic understanding of PHP code execution process. And this is the problem that xdebug to solve.

After a long period of time, xdebug from the 2.4.0 version, support debugging PHP 7 code, Next, we use the source code to compile the way to install.

First, we are in the Homestead7 directory, execute vagrant SSH login to homestead virtual machine;

Next, download and unzip the Xdebug source code:

wget http://xdebug.org/files/xdebug-2.4.0rc1.tgztar xvzf xdebug-2.4.0rc1.tgz

Next, go to the extracted directory and use phpize7.0 to generate the configuration file, configure, make, and make install:

--enable-xdebugmakesudo make install

After the installation is successfully compiled, Xdebug displays the compiled. So file directory, and we want to record this directory so that the current PHP environment supports Xdebug debugging.

Enable Xdebug

First, we create a configuration file for Xdebug, Xdebug.ini, here, notice to replace the Zend_extension directory with its own. So directory:

zend_extension="/usr/lib/php/20151012/xdebug.so"xdebug.remote_enable = 1xdebug.remote_connect_back = 1xdebug.remote_port = 9000xdebug.max_nesting_level = 500

After that, we copy the Xdebug.ini to the/etc/php/mods-available directory.

Next, create the corresponding symbolic link in the current PHP 7 CLI and FPM's CONF.D directory:

sudo ln -snf /etc/php/mods-available/xdebug.ini /etc/php/7.0/cli/conf.d/20-xdebug.inisudo ln -snf /etc/php/mods-available/xdebug.ini /etc/php/7.0/fpm/conf.d/20-xdebug.ini

Finally, we restart PHP7.0-FPM for the new configuration to take effect:

service php7.0-fpm restart

We have a number of ways to confirm that Xdebug is working properly:

In the terminal execution Php-m, in the final output of the [Zend Modules] section, you can see Xdebug;
Execute php-i |grep xdebug, in the output results, you can see xdebug support = = enabled;
Visit our previous http://php7.app/demo.php, next to the Zend engine picture, you can find the Xdebug logo;

Phpstorm

After PHP 7 and Xdebug are set up, we need an IDE to configure and use them. Here, we use Phpstorm, you can download the official EAP version for free.

After installation, we use Phpstorm to open the PHP7 directory we created earlier, and we need to configure the server environment for our project. Click "Run/edit configurations ...". In the pop-up dialog box, click + in the top left corner and select PHP Web application.

In the right-hand interface, after setting the name, click the Red Arrow Position button to set the remote server:

The remote server here refers to the Homestead startup VirtualBox, click on the upper left corner of the +, after, fill in the corresponding information (be sure to set the path mapping):

Finally, based on the server Host we filled out, fill in the file we want to access at the start URL. Here we write the demo.php,phpstorm that we created before will automatically generate the default access link for us.

Everything is set up, click the OK button. Next, to test the debug function, we modify the previous demo.php:

<?php$foo = 10;$bar = 20;$compare = $foo <=> $bar;echo $compare;

Then, click on the area to the left of $foo to set a breakpoint.

Click on the menu "Run/debug ' Php7demo ... '",

If all goes well, Phpstorm will start chrome and automatically stop where demo.php set breakpoints.

This way, you can click the red Arrow Position button and step through your PHP 7 code.

Package all of them into a container

While it is not difficult to deploy an adjustable PHP 7 environment, it takes a lot of effort to follow the steps above, and after understanding exactly what we need to do, we offer a simpler way to deploy the PHP 7 development environment.

Parking provides a lnmp docker image, like Homestead, we have packaged a new LNMP environment, a debug PHP 7 version, and a PHP modules that is compatible with Laravel.

* This is just an easy way to build a development environment, and we don't use Docker's single-container single-process approach, and not the container in a production environment. For Docker deployment issues, we will provide a separate video series for Docker automation deployment based on Laravel.
-Special attention *

Open the terminal and execute the following command:

docker pull boxueio/php7-with-xdebug

When Docker is finished downloading, we do (replace [your source dir] with your own PHP source code directory):

8088:80 -p 33060:3306 -v [your source dir]:/var/www/php7.app php7-with-xdebug

Docker then returns a container ID, and we can view the running container using the Docker PS command. Next, as long as you add a Php7.app resolution record in/etc/hosts, we can access the PHP 7 development environment through http://php7.app:8088.

Original:

1190000004148696

Get started and transition to PHP7 (1)--Homestead based PHP7 and xddebug environments

Related Article

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.