登录  /  注册
首页 > 运维 > linux运维 > 正文

一文详解Linux如何安装Symfony2.8

藏色散人
发布: 2021-09-13 16:04:06
转载
1363人浏览过

下面由linux系统教程栏目给大家介绍linux如何安装symfony2.8,希望对需要的朋友有所帮助!

环境说明

操作系统

tony@ubuntu:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.2 LTS
Release:        14.04
Codename:       trusty
登录后复制

Symfony

symfony2.8
登录后复制

安装准备

均使用 apt-get 安装

PHP5.4

至少要有个PHP5.4的环境

nginx

web server 是少不了了

安装步骤

1.下载官方命令工具

sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony
登录后复制

2.创建项目

这里执行项目创建时,会从官网下载源码包,执行完后就能在当前目录看到了

symfony new symfony2.8 2.8
登录后复制

这里我创建了一个新的项目叫symfony2.8, 最后的2.8(不是项目名字中的2.8) 是要下载指定的symfony2.8版本的源码,如果要下载的是其他版本, 修改一下接口

3.检测
在安装完后, symfony还会进行一些检测, 看看你的操作系统环境是否适合运行symfony, 按照提示将缺失的扩展安装(我安装了intl)或者将PHP的配置修改(我就改了时区),再执行

php symfony2.8/bin/symfony_requirements
登录后复制

再次检测是否通过(php 后面的文件就在新创建的项目中,我这里项目名是symfony2.8)

运行

symfony2.8' 自带的console(位置symfony2.8/bin/console)可以临时启动一个webserver,默认端口是8000,启动后,通过http://localhost:8000` 就能看到他的欢迎页面了

nginx 配置

nginx 的配置其官方文档里也有, 这里直接把我的复制过来,我也是直接修改的官方文档

server {
    listen 8028;
    #server_name domain.tld www.domain.tld;
    root /data/app/symfony2.8/web;

    location / {
        # try to serve file directly, fallback to app.php
        try_files $uri /app.php$is_args$args;
    }
    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
    }
    # PROD
    location ~ ^/app\.php(/|$) {
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        # When you are using symlinks to link the document root to the
        # current version of your application, you should pass the real
        # application path instead of the path to the symlink to PHP
        # FPM.
        # Otherwise, PHP's OPcache may not properly detect changes to
        # your PHP files (see https://github.com/zendtech/ZendOptimizerPlus/issues/126
        # for more information).
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;
        # Prevents URIs that include the front controller. This will 404:
        # http://domain.tld/app.php/some-path
        # Remove the internal directive to allow URIs like this
        internal;
    }

    # return 404 for all other php files not matching the front controller
    # this prevents access to other php files you don't want to be accessible.
    location ~ \.php$ {
      return 404;
    }

    error_log /data/log/nginx/symfony_error.log;
    access_log /data/log/nginx/symfony_access.log;
}
登录后复制

需要注意的是, nginx中包含了一个在开发环境适用的配置和一个在生产环境适用的配置,在生产华景部署的时候, 一定不要讲开发环境的配置带上去了

配置好后, 重新reload nginx,我这里监听的是虚拟机的8028端口,通过访问这个端口,也可以直接看到欢迎页面

78457a740e81b28cb0aeb77f0eeeef7.png

推荐学习:《linux视频教程

以上就是一文详解Linux如何安装Symfony2.8的详细内容,更多请关注php中文网其它相关文章!

智能AI问答
PHP中文网智能助手能迅速回答你的编程问题,提供实时的代码和解决方案,帮助你解决各种难题。不仅如此,它还能提供编程资源和学习指导,帮助你快速提升编程技能。无论你是初学者还是专业人士,AI智能助手都能成为你的可靠助手,助力你在编程领域取得更大的成就。
来源:segmentfault网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
最新问题
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2024 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号