Technical note

PHP学习笔记

资源

macOS环境手动搭建

参考文档

安装PHP

# 安装
brew search php
brew install php@7.4
brew services start php@7.4

# 添加PATH
echo 'export PATH="/usr/local/opt/php/sbin:$PATH"' >> ~/.zshrc
source ~/.zshrc

# 查看版本
php -v
php-fpm -v

# 启动服务(php-fpm监听9000端口)
brew services run php@7.4

安装Nginx

brew install nginx
brew services start nginx
nginx -h

vi /usr/local/etc/nginx/nginx.conf
cd /usr/local/etc/nginx/servers/
vi test.conf
server {
    listen 8099;
    server_name localhost;
    root /home/www/php-project;
    rewrite . /index.php;
    location / {
    index index.php index.html index.htm;
    autoindex on;
    }
    #proxy the php scripts to php-fpm
    location ~ \.php$ {
        include /usr/local/etc/nginx/fastcgi.conf;
        fastcgi_intercept_errors on;
        fastcgi_pass 127.0.0.1:9000;
    }
}

DEMO

vi index.php
<?php
    phpinfo();

直接启动

# 内置server方式启动
php -S localhost:9000

# 命令行执行
php start.php

MongoDB扩展安装

pecl install mongodb

Xdebug安装

参考文档

安装

# 安装
pecl install xdebug

# 查看PHP配置路径
php --ini

# 修改php.ini
vi /usr/local/etc/php/7.4/php.ini
[xdebug]
xdebug.mode=debug
xdebug.client_host="127.0.0.1"
xdebug.client_port=9001
xdebug.collect_return=On
xdebug.idekey="PHPSTORM"
xdebug.log="/tmp/xdebug.log"

PhpUnit

# 安装依赖
composer require phpunit/phpunit

 vi composer.json
"require-dev" : {
    "phpunit/phpunit" : "^8.0"
}

# 生成配置
vendor/bin/phpunit --generate-configuration