红联Linux门户
Linux帮助

ubuntu server 16.04安装配置Symfony 3

发布时间:2016-09-14 09:58:17来源:linux网站作者:uemganix
简单描述,不准确的地方请帮忙纠正。
 
# 更换阿里云源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak #备份
sudo vim /etc/apt/sources.list #修改
sudo apt-get update #更新列表
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
 
# 安装composer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php composer-setup.php
sudo mv composer.phar /usr/bin/composer
php -r "unlink('composer-setup.php');"
参考 https://getcomposer.org/download/
 
# 配置全量镜像
composer config -g repo.packagist composer https://packagist.phpcomposer.com
参考 http://pkg.phpcomposer.com/
 
# 安装symfony
composer create-project symfony/framework-standard-edition your_project -vvv
ps: 这里安装了最新稳定版的symfony
 
# 配置VirtualHost
1)复制一份/etc/apache2/sites-available/下的000-default.config重命名为your_site.conf 编辑这个文件为:
<VirtualHost *:80>
ServerName ldev.your_site.com
ServerAlias ldev.your_site.com
DocumentRoot /path/to/your_project/web
<Directory /path/to/your_project/web>
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeScript assets
# <Directory /var/www/project>
#     Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /path/to/your_project/web/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
2) 保存文件,启用
sudo a2ensite your_site.conf
 
# 一些要点
/***********************************************/
/**
* @Route("/lucky/number")        =>单引号'/lucky/number'会报错
*/
public function numberAction()
{...
/***********************************************/
如果使用codelite中sftp插件,通过鼠标右键创建文件会存在权限问题,造成controller找不到template模板文件,虽然可以通过chmod修正,但还是建议这种情况下直接在shell中创建文件
/***********************************************/
多个routes同时match的情况,可以使用requirements限制,如:requirements={"page": "\d+"} 会限制page通配符只匹配数字
/***********************************************/
In Symfony versions previous to 3.0, it is possible to override the request format by adding a query parameter named _format (for example: /foo/bar?_format=json). Relying on this behavior not only is considered a bad practice but it will complicate the upgrade of your applications to Symfony 3.
 
# 可能遇到的问题及解决办法
* 安装时无法选择UTC时区
安装完后执行 sudo dpkg-reconfigure tzdata ,然后选择 None of the above -> UTC
然后执行 sudo service mysql restart 以使时区更改应用于mysql
* The zip extension and unzip command are both missing
sudo apt install zip unzip
* PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\ClassNotFoundException: Attempted to load class "DOMDocument" from the global namespa  
ce
sudo apt install php-xml
 
本文永久更新地址:http://www.linuxdiyf.com/linux/24142.html