search
HomeBackend DevelopmentPHP Tutorial在win7中搭建Linux+PHP 开发环境_php实例

我用了 3 年多的 Linux 桌面,很是不爽,主要是各个软件的体验不够统一,太分裂,太多选择让人无从选择。
而回到 Windows, 则更糟糕,使用 *nix 工具集变得非常折腾,部署 Web 环境也很麻烦,而且我的服务器都是 Linux 的,代码里有些功能是不能运行在 Windows 上的。

因为我偶尔还打打游戏,一个月前,我还是选择回到 Windows 桌面。
但我下面的这些软件几乎都是跨平台的,如果你使用 Linux 桌面,也不会有什么影响的。

我的主机是 Windows 7 x64, 然后跑一个 Arch 的虚拟机,所有代码的运行和调试都在虚拟机中进行。

Arch 虚拟机

Arch 安装略折腾,但我喜欢它 KISS 的哲学,我用 VirtualBox, 分配 512MiB 甚至 256MiB 就够用了。
网络改成「桥接网卡」然后在路由器设置一个 MAC 绑定的固定 IP, 我给虚拟机的是 192.168.0.105, 而我主机的是 192.168.0.100.

需要装的软件包最核心的有:openssh, nginx, mariadb, php, xdebug.
至于其他一些:vim, mongodb, php-mongo, phpmyadmin 就看个人需要了。

直接在 VirtualBox 的虚拟机窗口上敲命令很不方便,我会装一个叫 VirtuaWin 的虚拟桌面软件,类似于 KDE 的 Workspace(工作区), 把 VirtualBox 的窗口丢到另一个桌面。
然后用 XShell 连 SSH 上去敲命令。

当然你还需要建一个非 root 账户来日常使用,我建了一个 jysperm.
然后你可以修改 /etc/php/php-fpm.conf:

user = jysperm
group = jysperm
这样 PHP-FPM 的进程会以你的用户来跑,读写文件不会遇到任何权限问题。

作为开发服务器,可能同时需要开发测试多个项目,每次都要去 Nginx 里面新建站点是很折腾的事情,下面的配置文件可以让你一劳永逸:

复制代码 代码如下:

server {
    listen 80;
    server_name ~(?.*)\.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 这个域名被我解析到了 192.168.0.105, 这样下来,只需访问 test.ab.jyprince.me, 就相当于访问位于 /home/jysperm/test 中的文件了,以后就不用再修改 Nginx 的配置文件了。

PHPStorm

我见过最好的 IDE 是 PHPStorm.

PHPStorm 的 Deployment 功能可以在你每次修改文件后自动部署到服务器,你只需建一个 SFTP 类型的服务器,并把 Arch 虚拟机的信息填上去,然后勾选 Automatic Upload 就好。
每一个项目都上传到 /home/jysperm 下的一个文件夹。

然后访问 项目名.ab.jysperm.me 就行了,一切都是自动的。

远程调试

在 Arch 虚拟机中修改 /etc/php/conf.d/xdebug.ini:

复制代码 代码如下:

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

然后在 PHPStorm 中新建一个 PHP Remote Debug 即可。
需要调试时,先在 PHPStorm 中打开调试,设上断点,然后让请求带上 XDEBUG_SESSION=jysperm 的 Cookie 即可。
调试页面的时候,可以用 这个工具 生成书签,点击书签就可以控制调试的开关了。

调试 RESTful API 的话我一般会用一个叫 Postman 的 Chrome 扩展,这个应用似乎没有编辑 Cookie 的功能,这样的话,在 HTTP Header 里加上一项 Cookie:XDEBUG_SESSION=jysperm 就行了。

其他推荐

Robomogo - 跨平台的 Mongo GUI 客户端
SourceTree - Windows 下的 Git GUI
Secure Shell - Chrome 中的 SSH
Clover - 让 Windows 的资源管理器像 Chrome 一样
FileZilla - 跨平台的 FTP 客户端
SmartGit - 跨平台的 Git GUI
Sublime Text - 好用的跨平台编辑器

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
The Continued Use of PHP: Reasons for Its EnduranceThe Continued Use of PHP: Reasons for Its EnduranceApr 19, 2025 am 12:23 AM

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python: Exploring Their Similarities and DifferencesPHP and Python: Exploring Their Similarities and DifferencesApr 19, 2025 am 12:21 AM

PHP and Python are both high-level programming languages ​​that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools