Symfony安装配置

一、安装Symfony
    切换到WEB根目录下,执行命令 composer create-project symfony/framework-standard-edition symfony_one "3.4.*",其中symfony_one项目名,3.4.*是版本号。
    安装过程中可能会有数据库的设置,按照实际设置就好。比如:
    database_host (127.0.0.1): 127.0.0.1
    database_port (null): 3307
    database_name (symfony): symfony_one
    database_user (root): root
    database_password (null): 123456
二、运行symfony服务
    切换到项目目录下(cd symfony_one),执行命令php bin/console server:run,这样symfony服务就运行起来了。
    在浏览器里打开http://127.0.0.1:8000 即可。
三、Nginx配置

########app.php#############################
    server {
        listen       80;
        server_name  symone.nn;#虚拟域名,要在hosts文件配置上,127.0.0.1       symone.nn 才可用。

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        error_log logs/symone_error.log;
        access_log logs/symone_access.log;

        location / {
            root   D:/www/symfony_one/web;#项目目录
            try_files $uri /app.php$is_args$args;
            #index  index.html index.htm index.php;
        }

        #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 ~ ^/app\.php(/|$) {#配置成app.php
            root           D:/www/symfony_one/web;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  app.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;
        #}
    }

#######app_dev.php##############

server {
        listen       80;
        server_name  symone.nn;
        root   D:/www/symfony_one/web;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;
        error_log logs/symone_error.log;
        access_log logs/symone_access.log;

        location / {
            
            try_files $uri /app_dev.php$is_args$args;
            #index  index.html index.htm index.php;
        }

        #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 ~ ^/(app_dev|config)\.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 DOCUMENT_ROOT $document_root;

        }

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

四、重启Nginx,在浏览器里打开symone.nn即可。

猜你喜欢

转载自blog.csdn.net/uvyoaa/article/details/82628796