安装;
windows安装
需要PHP版本》=5.4.且开启mcrypt加密扩展
都不想安装的可以从https://github.com/overtrue/latest-laravel 这里下载大神整理好的,解压即可使用
首先等安装cpmposer, 提示openssl错误的打开PHP.INI配置文件将extension=php_openssl.dll 前面的注释去掉,大概在第887行。
copmposer安装过程就不说了。
下面开始Laravel 5安装过程,github有下载,这里分享个网盘连接:http://pan.baidu.com/s/1dD50dWH
下载后解压,为了方便你可以解压到网站根目录下。我这里解压到F:/laravel [当然了,这不是我的根目录,需要配置虚拟主机]。
由于众所周知的原因国内安装composer,laravel比较慢,推荐使用镜像安装。
修改laravel目录的composer.json文件
在末尾结束括号前加上:
, "repositories": [ {"type": "composer", "url": "http://comproxy.cn/repo/packagist"}, {"packagist": false} ]
若不能用试试http://pkg.phpcomposer.com/
在文件夹内单击鼠标右键选择安装
几分钟后就安装完成啦!
这时会发现目录下多了个vendor文件夹。
laravel的默认首页是server.php,需要配置下,打开httpd.conf配置文件
找到[大概第249行以下]
<IfModule dir_module> DirectoryIndex index.html index.php index.htm l.php server.php</IfModule>
加上 server.php重启即可。
试试去浏览器打开http://t.com 试看看, 以你自己的安装为准。
到此为止安装成功了,打开慢的原因是使用了谷歌字体, 可以使用国内CDN,找到F:\laravel\resources\views文件夹,打开welcome.blade.php文件,将第五行改为
360前端公共库:http://libs.useso.com/
接着去试试写个方法,
找到F:\laravel\app\Http文件夹,打开routes.php,加上
/*|--------------------------------------------------------------------------| Application Routes|--------------------------------------------------------------------------|| Here is where you can register all of the routes for an application.| It's a breeze. Simply tell Laravel the URIs it should respond to| and give it the controller to call when that URI is requested.|*/ Route::get('/', 'WelcomeController@index'); Route::get('home', 'HomeController@index'); Route::controllers([ 'auth' => 'Auth\AuthController', 'password' => 'Auth\PasswordController',]);Route::get('hi', function(){ return "hi";});
打开浏览器输入http://t.com/public/hi
试看看,这就是路由了。
如需直接访问到public项目文件夹可以配置vhost
<VirtualHost *:80> DocumentRoot "F:\laravel\public" ServerName t.com ServerAlias t1.zy62.com <Directory "F:\laravel> Options FollowSymLinks ExecCGI AllowOverride All Order allow,deny Allow from all Require all granted </Directory></VirtualHost>
2.linux安装
laravel必须PHP>5.4支持mcrypt。
从https://github.com/overtrue/latest-laravel 这里下载大神整理好的,解压即可使用
nginx伪静态:[我这里用的是LNMP]
server { listen 80; #listen [::]:80; server_name laravel.zy62.com; index index.html index.htm index.php default.html default.htm default.php; root /home/wwwroot/laravel.zy62.com/public; include other.conf; #error_page 404 /404.html; location ~ .*\.(php|php5)?$ { try_files $uri =404; fastcgi_pass unix:/tmp/php-cgi.sock; fastcgi_index index.php; include fcgi.conf; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; } location ~ .*\.(js|css)?$ { expires 12h; }if (!-d $request_filename) { rewrite ^/(.+)/$ /$1 permanent; } # removes trailing "index" from all controllers if ($request_uri ~* index/?$) { rewrite ^/(.*)/index/?$ /$1 permanent; } # unless the request is for a valid file (image, js, css, etc.), send to bootstrap if (!-e $request_filename) { rewrite ^/(.*)$ /index.php?/$1 last; break; } access_log /home/wwwlogs/laravel.zy62.com.log access; }
include fcgi.conf;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;fastcgi_param QUERY_STRING $query_string;fastcgi_param REQUEST_METHOD $request_method;fastcgi_param CONTENT_TYPE $content_type;fastcgi_param CONTENT_LENGTH $content_length; fastcgi_param SCRIPT_NAME $fastcgi_script_name;fastcgi_param REQUEST_URI $request_uri;fastcgi_param DOCUMENT_URI $document_uri;fastcgi_param DOCUMENT_ROOT $document_root;fastcgi_param SERVER_PROTOCOL $server_protocol; fastcgi_param GATEWAY_INTERFACE CGI/1.1;fastcgi_param SERVER_SOFTWARE nginx/$nginx_version; fastcgi_param REMOTE_ADDR $remote_addr;fastcgi_param REMOTE_PORT $remote_port;fastcgi_param SERVER_ADDR $server_addr;fastcgi_param SERVER_PORT $server_port;fastcgi_param SERVER_NAME $server_name; # PHP only, required if PHP was built with --enable-force-cgi-redirectfastcgi_param REDIRECT_STATUS 200;
ERROR: An another FPM instance seems to already listen on /tmp/php-cgi-714ms.com.sock
解决办法:
/root/lnmp reload
数据库配置:\config\database.php
'mysql' => [ 'driver' => 'mysql', 'host' => 'localhost', //'host' => env('DB_HOST', 'localhost'), 'database' => 'test', //'database' => env('DB_DATABASE', 'forge'), 'username' => 'root', //'username' => env('DB_USERNAME', 'forge'), 'password' => 'qaz123', //'password' => env('DB_PASSWORD', ''), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '', 'strict' => false, ],
视图,传值:
路由:
Route::get('/hi',function(){ //echo 123; return View::make('hi')->with('name','laravel');//way1});
在laravel\resources\views下新建hi.blade.php文件
<?php?> <html> <head> <meta charset="UTF-8" /> <title>test</title> <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" /> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script><script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script><link href="http://libs.baidu.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div> <h1 id="laravel-nbsp-view">laravel view</h1> <p><?php echo $name; ?></p></div> </body></html>
视图传值方式:
return View::make('hi')->with('name','laravel');//way1
2.魔术方法
return View::make('hi')->withName('laravel');
$data['name']='laravel';return View::make('hi',$data);
路由传值限制:
那么现在我的博客有一堆文章,我想通过地址 http://yourdomain/article/1 访问 id 为 1 的文章,通过 http://yourdomain/article/2 访问 id 为 2 的文章怎么办?
Route::get('article/{id}', function($id) { return 'Article:' . $id;});
但是,假如有这样一种情况,有很多地方都需要 id 作为参数,id 大都是这种数字,我们肯定不希望每一个路由规则都要写一次 where 方法来设置 id 的匹配规则。这时候可以通过这样一个方法来实现:
Route::pattern('id', '[0-9]+');

PHP仍然流行的原因是其易用性、灵活性和强大的生态系统。1)易用性和简单语法使其成为初学者的首选。2)与web开发紧密结合,处理HTTP请求和数据库交互出色。3)庞大的生态系统提供了丰富的工具和库。4)活跃的社区和开源性质使其适应新需求和技术趋势。

PHP和Python都是高层次的编程语言,广泛应用于Web开发、数据处理和自动化任务。1.PHP常用于构建动态网站和内容管理系统,而Python常用于构建Web框架和数据科学。2.PHP使用echo输出内容,Python使用print。3.两者都支持面向对象编程,但语法和关键字不同。4.PHP支持弱类型转换,Python则更严格。5.PHP性能优化包括使用OPcache和异步编程,Python则使用cProfile和异步编程。

PHP主要是过程式编程,但也支持面向对象编程(OOP);Python支持多种范式,包括OOP、函数式和过程式编程。PHP适合web开发,Python适用于多种应用,如数据分析和机器学习。

PHP起源于1994年,由RasmusLerdorf开发,最初用于跟踪网站访问者,逐渐演变为服务器端脚本语言,广泛应用于网页开发。Python由GuidovanRossum于1980年代末开发,1991年首次发布,强调代码可读性和简洁性,适用于科学计算、数据分析等领域。

PHP适合网页开发和快速原型开发,Python适用于数据科学和机器学习。1.PHP用于动态网页开发,语法简单,适合快速开发。2.Python语法简洁,适用于多领域,库生态系统强大。

PHP在现代化进程中仍然重要,因为它支持大量网站和应用,并通过框架适应开发需求。1.PHP7提升了性能并引入了新功能。2.现代框架如Laravel、Symfony和CodeIgniter简化开发,提高代码质量。3.性能优化和最佳实践进一步提升应用效率。

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP类型提示提升代码质量和可读性。1)标量类型提示:自PHP7.0起,允许在函数参数中指定基本数据类型,如int、float等。2)返回类型提示:确保函数返回值类型的一致性。3)联合类型提示:自PHP8.0起,允许在函数参数或返回值中指定多个类型。4)可空类型提示:允许包含null值,处理可能返回空值的函数。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

PhpStorm Mac 版本
最新(2018.2.1 )专业的PHP集成开发工具