Andrei Pall

Linux Software Engineering

Setup Symfony with Nginx, PHP 7 and PostgreSQL on Ubuntu 16.04

Symfony was heavily inspired by other web application frameworks such as Ruby on Rails, Django, and Spring.

Symfony makes heavy use of existing PHP open-source projects as part of the framework, including:

  • Propel or Doctrine as object-relational mapping layers
  • PDO database abstraction layer
  • PHPUnit, a unit testing framework
  • Twig, a templating engine
  • Swift Mailer, an e-mail library
sudo apt-get install nginx postgresql php php7.0-fpm php7.0-pgsql php7.0-gd php7.0-xml php7.0-intl phpunit git
sudo -u postgres psql postgres
\password postgres
cd /etc/nginx/sites-available
sudo nano default
server {
	listen 80 default_server;
	listen [::]:80 default_server;

	# SSL configuration
	#
	# listen 443 ssl default_server;
	# listen [::]:443 ssl default_server;
	#
	# Note: You should disable gzip for SSL traffic.
	# See: https://bugs.debian.org/773332
	#
	# Read up on ssl_ciphers to ensure a secure configuration.
	# See: https://bugs.debian.org/765782
	#
	# Self signed certs generated by the ssl-cert package
	# Don't use them in a production server!
	#
	# include snippets/snakeoil.conf;

	root /var/www/bug_tracker/web;

	# Add index.php to the list if you are using PHP
	index index.html app_dev.php index.htm index.nginx-debian.html;

	server_name _;

	location / {
		# First attempt to serve request as file, then
		# as directory, then fall back to displaying a 404.
		try_files $uri $uri/ /app_dev.php?$args;
	}

	# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
	#
	location ~ \.php$ {
	#	include snippets/fastcgi-php.conf;
	#
	#	# With php7.0-cgi alone:
	#	fastcgi_pass 127.0.0.1:9000;
	#	# With php7.0-fpm:
		fastcgi_pass unix:/run/php/php7.0-fpm.sock;
		fastcgi_index app_dev.php;
		include fastcgi_params;
		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    		include /etc/nginx/fastcgi.conf;
	}

	# deny access to .htaccess files, if Apache's document root
	# concurs with nginx's one
	#
	#location ~ /\.ht {
	#	deny all;
	#}
}
sudo curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer

sudo gedit /etc/php/7.0/cli/php.ini
sudo gedit /etc/php/7.0/fpm/php.ini

sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony
sudo chmod a+x /usr/local/bin/symfony

sudo service php7.0-fpm restart
sudo service nginx restart