在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 ~(?
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 - 好用的跨平台编辑器

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP is a server-side scripting language used for dynamic web development and server-side applications. 1.PHP is an interpreted language that does not require compilation and is suitable for rapid development. 2. PHP code is embedded in HTML, making it easy to develop web pages. 3. PHP processes server-side logic, generates HTML output, and supports user interaction and data processing. 4. PHP can interact with the database, process form submission, and execute server-side tasks.

PHP has shaped the network over the past few decades and will continue to play an important role in web development. 1) PHP originated in 1994 and has become the first choice for developers due to its ease of use and seamless integration with MySQL. 2) Its core functions include generating dynamic content and integrating with the database, allowing the website to be updated in real time and displayed in personalized manner. 3) The wide application and ecosystem of PHP have driven its long-term impact, but it also faces version updates and security challenges. 4) Performance improvements in recent years, such as the release of PHP7, enable it to compete with modern languages. 5) In the future, PHP needs to deal with new challenges such as containerization and microservices, but its flexibility and active community make it adaptable.

The core benefits of PHP include ease of learning, strong web development support, rich libraries and frameworks, high performance and scalability, cross-platform compatibility, and cost-effectiveness. 1) Easy to learn and use, suitable for beginners; 2) Good integration with web servers and supports multiple databases; 3) Have powerful frameworks such as Laravel; 4) High performance can be achieved through optimization; 5) Support multiple operating systems; 6) Open source to reduce development costs.

VS Code system requirements: Operating system: Windows 10 and above, macOS 10.12 and above, Linux distribution processor: minimum 1.6 GHz, recommended 2.0 GHz and above memory: minimum 512 MB, recommended 4 GB and above storage space: minimum 250 MB, recommended 1 GB and above other requirements: stable network connection, Xorg/Wayland (Linux)

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

VS Code To switch Chinese mode: Open the settings interface (Windows/Linux: Ctrl, macOS: Cmd,) Search for "Editor: Language" settings Select "Chinese" in the drop-down menu Save settings and restart VS Code

VS Code is the full name Visual Studio Code, which is a free and open source cross-platform code editor and development environment developed by Microsoft. It supports a wide range of programming languages and provides syntax highlighting, code automatic completion, code snippets and smart prompts to improve development efficiency. Through a rich extension ecosystem, users can add extensions to specific needs and languages, such as debuggers, code formatting tools, and Git integrations. VS Code also includes an intuitive debugger that helps quickly find and resolve bugs in your code.

The reasons for the installation of VS Code extensions may be: network instability, insufficient permissions, system compatibility issues, VS Code version is too old, antivirus software or firewall interference. By checking network connections, permissions, log files, updating VS Code, disabling security software, and restarting VS Code or computers, you can gradually troubleshoot and resolve issues.
