PHPackages                             singcl/php\_mvc - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. singcl/php\_mvc

ActiveProject[Framework](/categories/framework)

singcl/php\_mvc
===============

Simple and lightweight PHP framework

v1.0.3(6y ago)021[1 PRs](https://github.com/singcl/php_mvc/pulls)MITPHPPHP 7.3CI failing

Since Jun 18Pushed 3mo agoCompare

[ Source](https://github.com/singcl/php_mvc)[ Packagist](https://packagist.org/packages/singcl/php_mvc)[ Docs](https://www.incoco.com)[ RSS](/packages/singcl-php-mvc/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (5)Used By (0)

[![travis](https://camo.githubusercontent.com/9fb07bc785e39450ec75355f43d8505a165414ddf6b8f27005b5b9146ffee12d/68747470733a2f2f7472617669732d63692e6f72672f73696e67636c2f7068705f6d76632e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/singcl/php_mvc)[![Latest Stable Version](https://camo.githubusercontent.com/856c5b79c9acc56293f966e1c4798fba2ebb9b04c06571986aebe56d3b87fe9a/68747470733a2f2f706f7365722e707567782e6f72672f73696e67636c2f7068705f6d76632f762f737461626c65)](https://packagist.org/packages/singcl/php_mvc)[![Total Downloads](https://camo.githubusercontent.com/661721b60bb49e8b75e4cea1bf4a7c05039308a0b797af06398de93e22bdbbfc/68747470733a2f2f706f7365722e707567782e6f72672f73696e67636c2f7068705f6d76632f646f776e6c6f616473)](https://packagist.org/packages/singcl/php_mvc)[![Latest Unstable Version](https://camo.githubusercontent.com/559e5bc10716184cb27097077bf8d675810862df68199268698672f09826d0a7/68747470733a2f2f706f7365722e707567782e6f72672f73696e67636c2f7068705f6d76632f762f756e737461626c65)](https://packagist.org/packages/singcl/php_mvc)[![License](https://camo.githubusercontent.com/a74b0e869cafcce1f4fe6a7646adcf0220d117bf5c263ee0e056ce71e5b9dffd/68747470733a2f2f706f7365722e707567782e6f72672f73696e67636c2f7068705f6d76632f6c6963656e7365)](https://packagist.org/packages/singcl/php_mvc)[![composer.lock](https://camo.githubusercontent.com/2e4ad89143f91dee3a762d3761f10c08ed2b5ba514ffe20e41e76ddf14c1ddf6/68747470733a2f2f706f7365722e707567782e6f72672f73696e67636c2f7068705f6d76632f636f6d706f7365726c6f636b)](https://packagist.org/packages/singcl/php_mvc)

1. **unable to bind listening socket for address '/run/php/php7.1-fpm.sock' no such file or directory**

原因：`php-fpm` 没有启动，如下启动：

```
# 启动命令：
sudo /etc/init.d/php7-fpm start
```

2. 查看Ubuntu Apache2 服务器日志

```
tail -f /var/log/apache2/*.log
```

3. remote-ssh
4. 启动Apache2后打开php 网站报错

```
sudo apache2 start
```

```
Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

```

有可能是php-fpm没有启动

```
sudo /etc/init.d/php7.3-fpm start
```

5. MYSQL

```
# 启动mysql
sudo service mysql start
```

一直报错

```
-su: 30: export: : bad variable name

```

最终问题定位： 在`/etc/profile` 之前添加了如下语句

```
SET NODE_HOME=/opt/node10.16.0-linux-x64
PATH = $PAHT:NODE_HOME
```

删除上面自己添加的即可启动

6. WSL 暂不支持 netstat ss 等命令
7.

```
# 查看MYSQL数据库中所有用户
mysql> SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user;

# 查看数据库中具体某个用户的权限
mysql> select * from mysql.user where user='singcl' \G

#查看user表结构　需要具体的项可结合表结构来查询
mysql> desc mysql.user;
```

8. 数据库操作相关问题

```
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
# 创建新的管理员账户
https://stackoverflow.com/questions/39281594/error-1698-28000-access-denied-for-user-rootlocalhost

#
# 将新创建的管理员账号设置为密码链接
ERROR 1698 (28000): Access denied for user 'root'@'localhost' (using password: NO)
https://www.jianshu.com/p/2b63c65caf6a
```

启动
--

[](#启动)

```
# 1 启动apache2
sudo service apache2 start

# 2 启动php-fpm
sudo service php7.3-fpm start

# 3 启动mysql
sudo service mysql start
```

9. PDO 相关问题

```
# 环境：Ubuntu 16.02
```

代码中使用PDO 时候返回 `PDOException: can not find driver`。 然后我们查看`phpinfo()` 确认下： PDO 显示：`drivers no value`

说明PDO 链接MYSQL 驱动找不到。

网上搜索这个问题，答案都是挺多的， 赞成数最多的方案：

```
# @see https://stackoverflow.com/questions/32728860/php-7-rc3-how-to-install-missing-mysql-pdo

# 第一步安装
apt-get install php7.3-mysql

#第二步 激活

# phpenmod@see https://tecadmin.net/enable-disable-php-modules-ubuntu/
phpenmod pdo_mysql

ln: failed to create symbolic link '/etc/php/7.3/cli/conf.d/20-pdo_mysql.ini': Permission denied
rm: cannot remove '/var/lib/php/modules/7.3/cli/disabled_by_admin/pdo_mysql': Permission denied

# 可以看出来这一步会在/etc/php/7.3/cli/conf.d/ 中创建一个符号链接 到/etc/php/7.3/mods-abailable/pdo_mysql.so
# 同时创建 /var/lib/php/modules/7.3/cli/enabled_by_admin/pdo_mysql

# 权限不够sudo
sudo phpenmod pdo_mysql
# 第三步 重启
sudo service apache2 restart
```

然后不幸的是还是失败了！！

我观察`/etc/php/7.3`中的目录 发现有个fpm。 fpm 和 cli 目录下都有php.ini 文件？

**我的PHP 使用的是 apache2 fast-cgi php-fpm 方式启动的，那么配置完三个步骤我只是重启了apache， php-fpm 是不是也要重启？**

```
sudo service php7.3-fpm restart
```

OK!! 成功了。

10. Mysql 链接不上

`ERROR 1698 (28000): Access denied for user 'root'@'localhost'`

@see

11. `php -r 'phpinfo();' | grep 'mysql'`

调试
--

[](#调试)

xdebug 安装文档

vscode xdebug 文档

#### pecl安装php扩展

[](#pecl安装php扩展)

Pecl全称The PHP Extension Community Library，php社区扩展库，由社区编写，维护。

使用pecl方便之处在于我们不用到处找源码包下载编译，配置，不用手动phpize,configure,make,make install,自动识别模块安装路径，

我们只需要编辑php.ini配置文件开启扩展，当然我们也需要自己配置一些参数的时候可以先下载源码再构建

Composer
--------

[](#composer)

1. php composer.phar update 时候warning: `Failed to download phpunit/phpunit-mock-objects from dist: The zip extension and unzip command are both missing, skipping.`

解决：没有安装zip导致的。 `sudo apt-get install zip`

Page 相关页面
---------

[](#page-相关页面)

```
loacalhost               # 增删改查数据库
loacalhost/canvas        # canvas画布相关示例
loacalhost/scratch       # 刮刮卡示例
```

Apache2 php7.3 php7.3-fpm
-------------------------

[](#apache2-php73-php73-fpm)

1. 初始化配置

```
sudo apt-get install software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt-get update
```

2. 安装主要package

```
# https://www.zhaokeli.com/article/8496.html
sudo apt-get install apache2 php7.3 php7.3-fpm php7.3-mysql mysql-server
```

3. **配置apache2**（关键步骤）

```
# https://blog.csdn.net/KBellX/article/details/78980317
# https://blog.csdn.net/margin_0px/article/details/82801045

# 配置apache 使用php-fpm fcgi
sudo ln -s /etc/apache2/mods-available/proxy.conf /etc/apache2/mods-enabled/proxy.conf
sudo ln -s /etc/apache2/mods-available/proxy.load /etc/apache2/mods-enabled/proxy.load
sudo ln -s /etc/apache2/mods-available/proxy_fcgi.load /etc/apache2/mods-enabled/proxy_fcgi.load
sudo ln -s /etc/apache2/mods-available/rewrite.load /etc/apache2/mods-enabled/rewrite.load

# 配置 2 /etc/apache2/sites-enabled/000.default.conf
1
  2         # The ServerName directive sets the request scheme, hostname and port that
  3         # the server uses to identify itself. This is used when creating
  4         # redirection URLs. In the context of virtual hosts, the ServerName
  5         # specifies what hostname must appear in the request's Host: header to
  6         # match this virtual host. For the default virtual host (this file) this
  7         # value is not decisive as it is used as a last resort host regardless.
  8         # However, you must set it for any further virtual host explicitly.
  9         ServerName mv.hongde.com
 10         ServerAdmin webmaster@localhost
 11         DocumentRoot /home/singcl/php_mvc
 12
 13         # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
 14         # error, crit, alert, emerg.
 15         # It is also possible to configure the loglevel for particular
 16         # modules, e.g.
 17         #LogLevel info ssl:warn
 18
 19             Options +FollowSymlinks
 20             AllowOverride All
 21             Require all granted
 22
 23
 24
 25             SetHandler "proxy:unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/"
 26
 27         ErrorLog ${APACHE_LOG_DIR}/error.log
 28         CustomLog ${APACHE_LOG_DIR}/access.log combined
 29
 30         # For most configuration files from conf-available/, which are
 31         # enabled or disabled at a global level, it is possible to
 32         # include a line for only one particular virtual host. For example the
 33         # following line enables the CGI configuration for this host only
 34         # after it has been globally disabled with "a2disconf".
 35         #Include conf-available/serve-cgi-bin.conf
 36
```

4. 启动

```
# 1 启动apache2
sudo service apache2 start

# 2 启动php-fpm
sudo service php7.3-fpm start

# 3 启动mysql
sudo service mysql start
```

MYSQL
-----

[](#mysql)

```
# root 用户登录
sudo mysql -u root -p;
```

```
# 新建用户
create user 'singcl'@'localhost' indentified by 'singcl';
```

```
# 新建数据库
create database project;
```

```
# 授权用户singcl@localhost 拥有数据库project 的所有权;
# https://blog.csdn.net/lindiwo/article/details/81708166
grant all privileges on project.* to singcl@localhost identified by 'singcl';
# 刷新
flush privileges;
```

```
# 切换用户
mysql -u singcl -p;

# 在 SQL 中新建一个 project 数据库（上面已经完成），增加一个item 表、并插入两条记录，命令如下：
#CREATE DATABASE `project` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
USE `project`;

CREATE TABLE `item` (
    `id` int(11) NOT NULL auto_increment,
    `item_name` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

INSERT INTO `item` VALUES(1, 'Hello World.');
INSERT INTO `item` VALUES(2, 'Lets go!');
```

@Refer:

MAC 使用系统自带的Apache和PHP-FPM 开启Apache+PHP-FPM服务
============================================

[](#mac-使用系统自带的apache和php-fpm-开启apachephp-fpm服务)

1. copy一份配置文件

```
cd /etc/cd /etc/apache2/
sudo cp httpd.conf.bak httpd.conf
```

2. 打开配置文件编辑

```
sudo vim httpd.conf
```

解开相关依赖模块注释，如图 [![需要解注释](./static/images/81A03208-2D7D-4B35-B231-3F5F0ACE4480.png)](./static/images/81A03208-2D7D-4B35-B231-3F5F0ACE4480.png)

3. 配置web服务器目录

[![web根目录配置](./static/images/documentroot.jpg)](./static/images/documentroot.jpg)

4. 解开虚拟主机路径 [![web根目录配置](./static/images/vhost-path.jpg)](./static/images/vhost-path.jpg)
5. 配置vhost

```
sudo vim extra/httpd-vhosts.conf
```

如图： [![web根目录配置](./static/images/vhostconfig.jpg)](./static/images/vhostconfig.jpg)

好了，现在配置已经完成。在/data/www下建一个文件：

```
touch index.php
```

```
