Building Linux+PHP Development Environment in win7

  • 2021-07-21 08:04:05
  • OfStack

I have used Linux desktop for more than 3 years, which is very uncomfortable. The main reason is that the experience of each software is not unified enough, too divided, and too many choices make people unable to choose.
Going back to Windows, it's even worse. Using * nix toolset becomes very troublesome, and deploying Web environment is also very troublesome. Moreover, my servers are all Linux, and some functions in the code cannot run on Windows.

Because I occasionally play games, I chose to return to Windows desktop a month ago.
But almost all of my software below is cross-platform, and if you use the Linux desktop, it won't make any difference.

My host is Windows 7 x 64, and then I run a virtual machine of Arch, and all the code runs and debugs in the virtual machine.

Arch Virtual Machine

Arch installation is a little tossed, but I like its philosophy of KISS. I use VirtualBox, and assign 512MiB or even 256MiB is enough.
The network was changed to "bridging network card" and then a fixed IP bound to MAC was set on the router. I gave the virtual machine 192.168. 0.105 and my host 192.168. 0.100.

The core software packages that need to be installed are: openssh, nginx, mariadb, php and xdebug.
As for the other ones: vim, mongodb, php-mongo and phpmyadmin, it depends on individual needs.

It is inconvenient to knock commands directly on the virtual machine window of VirtualBox. I will install a virtual desktop software called VirtuaWin, which is similar to Workspace (workspace) of KDE, and throw the window of VirtualBox to another desktop.
Then use XShell and SSH to type the command.

Of course, you also need to set up a non-root account for daily use. I set up an jysperm.
You can then modify the/etc/php/php-fpm. conf:

user = jysperm
group = jysperm
This PHP-FPM process will run as your user, read and write files will not encounter any permissions issues.

As a development server, you may need to develop and test multiple projects at the same time. It is very troublesome to build a new site in Nginx every time. The following configuration file can make you work forever:


server {
    listen 80;
    server_name ~(?<dir>.*)\.ab\.jyprince\.me$;     access_log /home/jysperm/nginx.access.log;
    error_log /home/jysperm/nginx.error.log;     index index.html index.php;
    autoindex on;     root /home/jysperm/$dir;     location / {
        try_files $uri $uri/ /index.php?$args;
    }     location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/php-fpm.sock;         fastcgi_index index.php;
        include fastcgi_params;
    }
}

*. ab. jyprince. me was resolved to 192.168. 0.105, so that just accessing test. ab. jyprince. me is equivalent to accessing the file located at/home/jysperm/test, and there is no need to modify the configuration file of Nginx in the future.

PHPStorm

The best IDE I have ever seen is PHPStorm.

The Deployment function of PHPStorm can be automatically deployed to the server every time you modify the file. You only need to build an SFTP type server, fill in the information of Arch virtual machine, and then check Automatic Upload.
Every item is uploaded to a folder under/home/jysperm.

Then just access the project name. ab. jysperm. me, and all cuts are automatic.

Remote debugging

Modify/etc/php/conf. d/xdebug. ini in Arch Virtual Machine:


zend_extension=/usr/lib/php/modules/xdebug.so
xdebug.remote_enable=on
xdebug.idekey=jysperm
xdebug.remote_host=192.168.0.100
xdebug.remote_port=9000

Then create a new PHP Remote Debug in PHPStorm.
When debugging is needed, first open debugging in PHPStorm, set a breakpoint, and then ask for Cookie with XDEBUG_SESSION=jysperm.
When debugging the page, you can use this tool to generate bookmarks, and click on the bookmarks to control the debugging switch.

When debugging RESTful API, I will generally use an Chrome extension called Postman. This application does not seem to have the function of editing Cookie. In this case, just add an Cookie to HTTP Header: XDEBUG_SESSION=jysperm.

Other recommendations

Robomogo-Cross-platform Mongo GUI client
Git GUI under SourceTree-Windows
SSH in Secure Shell-Chrome
Clover-Make the resource manager of Windows look like Chrome 1
FileZilla-Cross-platform FTP client
SmartGit-Cross-platform Git GUI
Sublime Text-A Useful Cross-Platform Editor


Related articles: