Abel'Blog

我干了什么?究竟拿了时间换了什么?

0%

PHP

简介

学习一下PHP相关的知识

开发环境搭建

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
$ brew install php@8.2

==> php
To enable PHP in Apache add the following to httpd.conf and restart Apache:
LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so

<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>

Finally, check DirectoryIndex includes index.php
DirectoryIndex index.php index.html

The php.ini and php-fpm.ini file can be found in:
/opt/homebrew/etc/php/8.2/

To start php now and restart at login:
brew services start php
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
(base) abel@abeldeMacBook-Pro ~> /opt/homebrew/opt/php/sbin/php-fpm --nodaemonize
[21-Oct-2023 12:44:28] NOTICE: [pool www] 'user' directive is ignored when FPM is not running as root
[21-Oct-2023 12:44:28] NOTICE: [pool www] 'group' directive is ignored when FPM is not running as root
[21-Oct-2023 12:44:28] NOTICE: fpm is running, pid 9918
[21-Oct-2023 12:44:28] NOTICE: ready to handle connections
^C[21-Oct-2023 12:53:09] NOTICE: Terminating ...
[21-Oct-2023 12:53:09] NOTICE: exiting, bye-bye!
(base) abel@abeldeMacBook-Pro ~> brew install nginx

==> Caveats
Docroot is: /opt/homebrew/var/www

The default port has been set in /opt/homebrew/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /opt/homebrew/etc/nginx/servers/.

To start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
/opt/homebrew/opt/nginx/bin/nginx -g daemon\ off\;
==> Summary
🍺 /opt/homebrew/Cellar/nginx/1.25.2: 26 files, 2.4MB
==> Running `brew cleanup nginx`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

docker run -p 80:8080 -v ~/my-codebase:/var/www/html trafex/php-nginx

location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}

nginx中设定自动将url增加 index.php

因为thinkphp里面的 url 访问的时候,需要每次自己手动增加这个配置。

1
2
3
4
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}

最终还是通过安装一个宝塔服务器,将配置全部生成出来,这样解决问题是非常顺利的。如果是手动来处理这个事情,还是非常多容易犯错的点。任何的一个错误都会让人花大量时间来处理。

里面的redis库,也是使用的c语言来编写的,如果安装需要将php安装成一个开发版本,然后通过命令行将其启动,在php.ini文件中将这个插件启动。

也有一种方法,去到网上找到合适的php docker 镜像来安装来搭建这个。宝塔系统是比较好用,但是存在安全隐患。

1
2
<?php
phpinfo();

ThinkPHP6.* 手册

ThinkPHP6.0

这里面有一套类似ORM的用法。 PHP其实就是个脚本,网站访问就会执行。

参考