1. 程式人生 > >PHP框架:Symfony2學習筆記(1)

PHP框架:Symfony2學習筆記(1)

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.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