SoFunction
Updated on 2025-03-09

Building a Linux+PHP development environment in win7

I have been using Linux desktop for more than 3 years and I am very unhappy. The main reason is that the experience of each software is not unified enough, too split, and too many choices make people unable to choose.
Back to Windows, it is even worse. Using the *nix tool set becomes very troublesome, and deploying a web environment is also 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 the Windows desktop a month ago.
But the software below me is almost all cross-platform, and if you use Linux desktop, it won't have any impact.

My host is Windows 7 x64, and then I run an Arch virtual machine, and all the code running and debugging are done in the virtual machine.

Arch Virtual Machine

Arch installation is a little tossing, but I like the philosophy of KISS, and I use VirtualBox, allocating 512MiB or even 256MiB is enough.
Change the network to "bridge network card" and then set up a fixed IP bound by MAC on the router. What I give to the virtual machine is 192.168.0.105, and what I host is 192.168.0.100.

The most core software packages that need to be installed are: openssh, nginx, mariadb, php, xdebug.
As for some other things: vim, mongodb, php-mongo, phpmyadmin depends on your personal needs.

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

Of course, you also need to create a non-root account for daily use, so I created a jysperm.
Then you can modify /etc/php/:

user = jysperm
group = jysperm
In this way, the PHP-FPM process will run as your user, and you will not encounter any permission problems when reading and writing files.

As a development server, you may need to develop and test multiple projects at the same time. It is a very troublesome to create a new site in Nginx every time. The following configuration file can help you solve it once and for all:

Copy the codeThe code is as follows:

server {
    listen 80;
    server_name ~(?<dir>.*)\.ab\.jyprince\.me$;

    access_log /home/jysperm/;
    error_log /home/jysperm/;

    index ;
    autoindex on;

    root /home/jysperm/$dir;

    location / {
        try_files $uri $uri/ /?$args;
    }

    location ~ \.php$ {
        fastcgi_pass unix:/run/php-fpm/;

        fastcgi_index ;
        include fastcgi_params;
    }
}

*. I parsed this domain name to 192.168.0.105. In this way, just accessing it is equivalent to accessing the file located in /home/jysperm/test. There is no need to modify the Nginx configuration file in the future.

PHPStorm

The best IDE I've ever seen is PHPStorm.

The Deployment function of PHPStorm can be automatically deployed to the server after each modification of the file. You only need to build a SFTP-type server, fill in the Arch virtual machine information, and then check Automatic Upload.
Each project is uploaded to a folder under /home/jysperm.

Then visit the project name. It's fine, everything is automatic.

Remote debugging

Modify /etc/php// in the Arch virtual machine:

Copy the codeThe code is as follows:

zend_extension=/usr/lib/php/modules/
xdebug.remote_enable=on
=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 turn on debugging in PHPStorm, set a breakpoint, and then let the request bring the cookie with XDEBUG_SESSION=jysperm.
When debugging the page, you can use this tool to generate a bookmark. Click the bookmark to control the debugging switch.

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

Other recommendations

Robomogo - Cross-platform Mongo GUI client
SourceTree - Git GUI under Windows
Secure Shell - SSH in Chrome
Clover - Make Windows Explorer like Chrome
FileZilla - Cross-platform FTP client
SmartGit - Cross-platform Git GUI
Sublime Text - A useful cross-platform editor