BlueXIII's Blog

热爱技术,持续学习

0%

PHP学习笔记

资源

macOS环境手动搭建

参考文档

安装PHP

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装
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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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

1
2
3
vi index.php
<?php
phpinfo();

直接启动

1
2
3
4
5
# 内置server方式启动
php -S localhost:9000

# 命令行执行
php start.php

MongoDB扩展安装

1
pecl install mongodb

Xdebug安装

参考文档

安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 安装
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

1
2
3
4
5
6
7
8
9
10
# 安装依赖
composer require phpunit/phpunit

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

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