官方网站:http://symfony.com/
这里将使用symfony 2.至于symfony的版本,可以从 http://symfony.com/legacy 找到。
1.下载安装。
当然可以直接从官网主页下载symfony2的发行包,不过我们还是推荐使用composer来安装,这是一个PHP的依赖管理工具。
安装composer:
$ curl -s https://getcomposer.org/installer | php
安装symfony:
phar create-project symfony/framework-standard-edition /path/to/webroot/Symfony 2.4.*
2.配置服务器:http://symfony.com/doc/current/cookbook/configuration/web_server_configuration.html
2.1)apache:
<VirtualHost *:80> ServerName domain.tld ServerAlias www.domain.tld DocumentRoot /var/www/project/web <Directory /var/www/project/web> # enable the .htaccess rewrites AllowOverride All Order allow,deny Allow from All </Directory> ErrorLog /var/log/apache2/project_error.log CustomLog /var/log/apache2/project_access.log combined </VirtualHost>
2.2)NginX:
server { server_name domain.tld www.domain.tld; root /var/www/project/web; location / { # try to serve file directly, fallback to rewrite try_files $uri @rewriteapp; } location @rewriteapp { # rewrite all to app.php rewrite ^(.*)$ /app.php/$1 last; } location ~ ^/(app|app_dev|config)\.php(/|$) { fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_split_path_info ^(.+\.php)(/.*)$; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param HTTPS off; } error_log /var/log/nginx/project_error.log; access_log /var/log/nginx/project_access.log; }
3. 修改app/cache和app/logs文件夹权限:
$ rm -rf app/cache/* $ rm -rf app/logs/* $ APACHEUSER=`ps aux | grep -E '[a]pache|[h]ttpd|[_]www|[w]ww-data' | grep -v root | head -1 | cut -d\ -f1` $ sudo chmod +a "$APACHEUSER allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs $ sudo chmod +a "`whoami` allow delete,write,append,file_inherit,directory_inherit" app/cache app/logs
4. 访问http://localhost/config.php检查symfony运行环境是否正常,在http://localhost/app_dev.php/demo/可以访问自带的demo。