1. 公司的电脑是纯净版的,没有安装其他的集成环境xampp,xmpp等,自带的php是7,安装了nginx。
用nginx做的服务器,执行php的程序,访问php程序时报错,因为还没有配置文件,因为是新系统,需要自己手动添加,其实是复制
server { listen 8060; server_name localhost.agent.pz.simuhao.com agent.pz.simuhao.com; charset utf-8; #access_log logs/host.access.log main; root /Volumes/D/git/xxx/public; index index.html index.php index.htm; #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /Volumes/D/oakgit/www; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php { root /Volumes/D/git/xxx/public; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(.*)$; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param SCRIPT_FILENAME $document_root/$fastcgi_script_name; include fastcgi.conf; } location / { try_files $uri /index.php$uri?$query_string; } # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # location ~ /\.ht { deny all; } }
mac自带的php目录在
cd /private/etc/ ,进入到目录下面,ls会看到很多default后缀的文件,需要将这些文件复制去掉后面的default
cp (-r/-R) oldfile newfile
然后执行
sudo php-fpm -D
这样php就能运行了。
然后启动nginx服务器。
现在是用PHP连接数据库,因为是php7所有使用mysqli
<?php $mysqli = new mysqli('localhost:3306', 'root', '123456', 'support'); if ($mysqli->connect_error) { die('Connect Error (' . $mysqli->connect_errno . ') ' . $mysqli->connect_error); } echo "连接成功"; $mysqli->close(); ?>
重点是端口号 3306,之前没加一直报错,加上就好了。
还有一个汉字没办法插入的问题,没有解决
2. 家里的电脑是集成环境xampp, 项目放到固定的目录即可,这个不用加端口号也能访问,一样有汉字乱码的问题,这个能插入,但是是乱码。
3. 可以用mac自带的Apache服务启动php,
https://blog.csdn.net/wj_november/article/details/51417491
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步