laravel5、php7、mongodb学习

使用laravel-mongodb

mongodb php driver

php7需要mongodb1.1x

PHP Driver PHP 5.3 PHP 5.4 PHP 5.5 PHP 5.6 PHP 7.0 HHVM 3.9
mongodb-1.1  
mongodb-1.0    
mongo-1.6    
mongo-1.5    

下载mongodb之后使用phpize安装

phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make
make install
#php.ini加
extension =mongodb.so
php composer.phar require jenssegers/mongodb  

提示错误,php扩展mbstring错误,用phpize编译安装mbstring

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - danielstjules/stringy 1.10.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - danielstjules/stringy 1.10.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - danielstjules/stringy 1.10.0 requires ext-mbstring * -> the requested PHP extension mbstring is missing from your system.
    - Installation request for danielstjules/stringy == 1.10.0.0 -> satisfiable by danielstjules/stringy[1.10.0].


Installation failed, reverting ./composer.json to its original content.

Laravel错误

5.1在php7环境上运行出现的错误

Fatal error: Uncaught ReflectionException: Class log does not exist in /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php:736 Stack trace: #0 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php(736): ReflectionClass->__construct(‘log’) #1 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php(626): Illuminate\Container\Container->build(‘log’, Array) #2 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Foundation/Application.php(674): Illuminate\Container\Container->make(‘log’, Array) #3 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php(837): Illuminate\Foundation\Application->make(‘log’) #4 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php(800): Illuminate\Container\Container->resolveClass(Object(ReflectionParameter)) #5 /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php(769): Illuminate\Container\Container in /home/liuman/jlcloud2/vendor/laravel/framework/src/Illuminate/Container/Container.php on line 736

解决方案:

删除vendor文件夹和composer.lock

composer install

laravel 500错误是storage没有权限

解决方案:chmod -R 777 storage

cache错误

file_put_contents(/..cache/services.json): failed to open stream: Permission denied

解决方案:sudo php artisan cache:clear

php composer.phar install报错

先安装composer,然后运行php composer.phar install –no-scripts

PDO错误,已安装PDO还提示

[PDOException]
SQLSTATE[HY000] [2002] No such file or directory

解决方案:将.env下的DB_HOST=localhost改为DB_HOST=127.0.0.1

SQLSTATE[HY000] [1045]

解决方案:
php artisan cache:clear
php artisan config:clear

php artisan 没反应

composer dumpautoload

The only supported ciphers are AES-128-CBC and AES-256-CBC with the correct key lengths.

php artisan key:generate

[Dotenv\Exception\InvalidFileException]
Dotenv values containing spaces must be surrounded by quotes.

.env文件中文或者空格必须加引号

OpenSSL extension is required

打开php.ini启用php_openssl

Key path “file://storage\oauth-public.key” does not exist or is not readable

php artisan passport:install

[Composer\Downloader\TransportException] The “https://packagist.phpcomposer.com/p/provider-2017-07%24c3e8d929d5d06fa b76cef9c5b5e4305dbe89c1599b79e63eee70490a6b8df914.json” file could not be d ownloaded (HTTP/1.1 404 Not Found)

composer diagnose

[ErrorException] proc_open(): fork failed – Cannot allocate memory

/bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=1024

/sbin/mkswap /var/swap.1

/sbin/swapon /var/swap.1

LogicException Key path “file:///storage/oauth-public.key” does not exist or is not readable

chown www-data:www-data storage/oauth-*.key

chmod 600 storage/oauth-*.key

[Illuminate\Database\QueryException] SQLSTATE[42000]: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes (SQL: alter table users add unique users_email_unique(email))

AppServiceProvider.php

use Illuminate\Support\Facades\Schema;

public function boot()
{
    Schema::defaultStringLength(191);
}

Illuminate\Database\QueryException : SQLSTATE[HY000] [2054] The server requested authentication method unknown to the client

C:\ProgramData\MySQL\MySQL Server 8.0\my.ini里default_authentication_plugin=caching_sha2_password改default_authentication_plugin=mysql_native_password

exception:”InvalidArgumentException”
file:”C:\web\jinguan\vendor\laravel\framework\src\Illuminate\Http\JsonResponse.php”
line:75
message:”Malformed UTF-8 characters, possibly incorrectly encoded”

Event::fire错误是redis没开

Class session does not exist

chmod -R 777 bootstrap/cache

Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)

php.ini打开扩展

extension=fileinfo

Laravel请求和输入

//获取输入数据,不用担心所使用的HTTP方法
$id = Input::get('id');
 
//可以指定默认值
$id = Input::get('id', 1);
 
//检测提交信息是否存在
if(Input::has('id'))
{
    echo Input::get('id');
}
 
//获取提交的所哟信息
print_r(Input::all());
 
//获取指定的几个提交信息
print_r(Input::only('id'));
 
//获取排除执行信息外的信息
print_r(Input::except('name'));
 
//用点符号获取数组形式的输入信息
$input = Input::get('users.0.name');