Symfony安装及使用
安装Symfony,使用
brew install homebrew/php/symfony-installer
开始一直下载不了包,我手动浏览器下载了几个,发现好像都是Permission问题,运行了下面的命令:
sudo chown -R $(whoami) /Users/baidu/Library/Caches/Homebrew/
Symfony安装在:
$ which symfony
/usr/local/bin/symfony
在以下目录:
/Users/baidu/Documents/Data/Work/Installed/symfony
运行
symfony new mywebsite 2.8
一直超时。
所以就自己到Symfony下了个demo,解压到html根目录,然后运行
http://127.0.0.1:7080/symfony-demo/web/config.php
发现两个major问题:
- Vendor libraries must be installed
Vendor libraries are missing. Install composer following instructions from http://getcomposer.org/. Then run "php composer.phar install" to install them.
- date.timezone setting must be set
Set the "date.timezone" setting in php.ini* (like Europe/Paris).
发现还是有很多问题。
连上公司网络,然后重新进行命令:
symfony new mywebsite 2.8 -vvv
初步看来可以运行。
安装成功会显示:
✔ Symfony 2.8.12 was successfully installed. Now you can:
* Change your current directory to /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite
* Configure your application in app/config/parameters.yml file.
* Run your application:
1. Execute the php app/console server:run command.
2. Browse to the http://localhost:8000 URL.
* Read the documentation at http://symfony.com/doc
来到mywebsite目录下面,跑命令
php app/console server:run 开始会出现以下错误:
[Symfony\Component\Debug\Exception\ContextErrorException]
Warning: date_default_timezone_get():
需要 sudo vi /private/etc/php.ini (没有的话,从php.ini.template拷贝过来)
date.timezone = Asia/Shanghai
然后运行成功:
[OK] Server running on http://127.0.0.1:8000
页面展现:
Welcome to
Symfony 2.8.12 Your application is now ready. You can start working on it at: /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/ What's next? Read the documentation to learn
How to create your first page in Symfony
下一步是要把Nginx和Symfony结合起来。
nginx的配置文件 /usr/local/etc/nginx/nginx.conf
#user nobody;
worker_processes 1; #error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info; #pid logs/nginx.pid; events {
worker_connections 1024;
} http {
include mime.types;
default_type application/octet-stream; #log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"'; #access_log logs/access.log main; sendfile on;
#tcp_nopush on; #keepalive_timeout 0;
keepalive_timeout 65; #gzip on; server {
listen 8080;
server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / {
root html;
index index.html 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 html;
} # proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#} # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
} # deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
} # another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias; # location / {
# root html;
# index index.html index.htm;
# }
#} # HTTPS server
#
#server {
# listen 443 ssl;
# server_name localhost; # ssl_certificate cert.pem;
# ssl_certificate_key cert.key; # ssl_session_cache shared:SSL:1m;
# ssl_session_timeout 5m; # ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on; # location / {
# root html;
# index index.html index.htm;
# }
#}
include servers/*;
}
Symfony的配置文件/usr/local/etc/nginx/servers/mywebsite.conf :
log_format logformat '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"'; server {
listen 7090;
server_name localhost;
index app.php;
root /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/web; location / {
if (!-e $request_filename){
rewrite ^/(.+)$ /app.php/$1 last;
}
client_max_body_size 20M;
}
location ~ ^/(app|app_dev)\.php(/|$) {
fastcgi_pass 127.0.0.1:9000;
fastcgi_split_path_info ^(.+\.php)(/.*)$;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param HTTPS off;
client_max_body_size 20M;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 1h;
client_max_body_size 20M;
} access_log /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/log/mywebsite.log logformat;
error_log /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/log/mywebsite.error_log;
}
以上全部完成后,运行命令:
$ brew services restart nginx 得到输出: Stopping `nginx`... (might take a while)
==> Successfully stopped `nginx` (label: homebrew.mxcl.nginx)
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)
但是浏览器页面出现如下错误:
Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone 'UTC' for now, but please set date.timezone to select your timezone. in /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/app/cache/prod/classes.php on line 6526
开始试了,是不是要改php7的配置
vi /usr/local/etc/php/7.0/php.ini date.timezone = "Asia/Shanghai"
发现还是报错,看了一下,需要改两个地方:
一是php的配置文件
vi /etc/php.ini date.timezone = "Asia/Shanghai"
二是报错的代码中加上:
vi /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/app/cache/prod/classes.php
6526行 加上 date_default_timezone_set('Asia/Shanghai');:
if (!static::$timezone) {
date_default_timezone_set('Asia/Shanghai');
static::$timezone = new \DateTimeZone(date_default_timezone_get() ?:'UTC');
}
然后就不报错了。
浏览器页面正常显示(Nginx):
http://127.0.0.1:8080/ Welcome to nginx! If you see this page, the nginx web server is successfully installed and working. Further configuration is required. For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com. Thank you for using nginx.
(Symfony): (注意,Symfony自己运行的时候用的是8000端口,而跟Nginx结合用的是7090端口)
http://localhost:7090/ Welcome to
Symfony 2.8.12 Your application is now ready. You can start working on it at: /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/ What's next? Read the documentation to learn
How to create your first page in Symfony
Symfony还有一个debug模式,访问的url是:
http://localhost:7080/app_dev.php/ (区别在于:1. 错误提示到页面,2无缓存)
开始访问的时候,还是报timezone的错,
然后根据提示,在
vi /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/app/cache/dev/classes.php 6008行加上:
date_default_timezone_set('Asia/Shanghai');
就不报错了,页面显示:
Welcome to
Symfony 2.8.12 Your application is now ready. You can start working on it at: /Users/baidu/Documents/Data/Work/Installed/symfony/mywebsite/ What's next? Read the documentation to learn
How to create your first page in Symfony
Symfony安装及使用的更多相关文章
- symfony 安装使用(一)
Symfony安装教程网上已经存在很多了,但是这里还是要写一下: 1.symfony 安装有以下几种,对应不同的环境 1.1通过composer 命令安装 composer create-projec ...
- symfony安装使用
symfony是一个强大的具有DI特性的框架,目前比较流行的php开发框架Drupal,Laravel底层都是使用了symfony. 想了解symfony更多内容,传送门 安装symfony很简单,一 ...
- Symfony 安装FOUSerBundle
第一按照官网安装 : https://symfony.com/doc/current/bundles/FOSUserBundle/index.html#main 可能版本无法安装 : $ compos ...
- symfony安装笔记
下载http://symfony.com/download,这里版本是2.8 将D:\ApacheServer\php路径添加到环境变量path中,在cmd命令行中可以执行php命令 打开php.in ...
- symfony安装总结
将D:\ApacheServer\php路径添加到环境变量path中,在cmd命令行中可以执行php命令 打开php.ini 打开extension=php_openssl.dll file_put_ ...
- symfony的安装
Symfony 是一个基于MVC的PHP框架,最新版本为2.7 工作原理 Synfony安装的两种方法 1.使用composer进行安装 1)下载composer http://getcomposer ...
- symfony-安装,使用与创建应用程序以及创建第一个hello world界面
说明:由于学校里面要用到symfony3进行开发,并且之前对php和mysql有了一定的学习,所以这里进行对symfony2.3版本的学习,目前的版本已经到了symfony4了,但是本人之后要用到的是 ...
- Symfony框架系列----1.入门安装
一.安装 (1)Composer安装(可选) $ curl -s https://getcomposer.org/installer | php $ php composer.phar crea ...
- Symfony没有安装依赖_PHP Fatal error: require(): Failed opening required
$ php bin/console server:run PHP Warning: require(D:\home\workspace\pd\app/../vendor/autoload.php): ...
随机推荐
- PyQt5点击按钮产生新窗体
import sys from PyQt5.QtWidgets import QApplication,QWidget from form1 import Ui_Form1 from form2 im ...
- LR11中自定义函数web_custom_request请求
Action() { char * ip,temp; int state; double time_elapsed, duration, waste; merc_timer_handle_t time ...
- 未能从程序集“Elmah”中加载类型“Elmah.ErrorLogModule”错误
项目名与Elmah重名了,以为是配置文件的问题,搞了好久.
- 2017年浙江中医药大学大学生程序设计竞赛(重现赛)D - CC的神奇背包
题目描述 cc最近收到了好多礼物,对着满地大小不一的礼物,她想要一个包来装,于是dd就掏出了一个会说话的神奇背包给cc装礼物.cc为了一次性装尽可能多的礼物,于是跟这个背包定下了一个规则,对每个礼物, ...
- Python类总结-描述符__get__(),__set__(),__delete__()
1 描述符是什么:描述符本质就是一个新式类,在这个新式类中,至少实现了__get__(),set(),delete()中的一个,这也被称为描述符协议 get():调用一个属性时,触发 set():为一 ...
- Python之路【第三篇】:文件操作
一.文件操作步骤 打开文件,得到文件句柄并赋值给一个变量 通过句柄对文件进行操作 关闭文件 歌名:<大火> 演唱:李佳薇 作词:姚若龙 作曲:马奕强 歌词: 有座巨大的停了的时钟 倾倒在赶 ...
- 图论之初,拓扑排序、前向星(通过存储边来存储图)加优先队列对拓扑的优化-----hdu1285
确定比赛名次 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Sub ...
- 【BZOJ 3566】 3566: [SHOI2014]概率充电器 (概率树形DP)
3566: [SHOI2014]概率充电器 Description 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品——概率充电器:“采用全新纳米级加工技术,实现元件与导线能否通电 ...
- SQL Server附加数据库提示“版本为661,无法打开,支持655版本……”
在我们使用别人导出的数据库的时候,有时候我们会通过附加数据库的方法,把别人导出的数据库附加到我们的电脑中,这时,或许你会遇到这种问题,附加时,提示版本为XXX,无法打开,支持AAA版本. 这是怎么回事 ...
- [Codeforces #172] Tutorial
Link: Codeforces #172 传送门 A: 一眼看上去分两类就可以了 1.每个矩形只有两条边相交,重合的形状为菱形 2.每个矩形四条边都有相交 对于情况1答案为$h*h/sin(a)$ ...