Getting Started with Symfony

symfony

#1

Symfony is one of the leading PHP Web frameworks. It is Open-Source and built on top of the Symfony Components.

Getting started

Create a Cloud9 workspace of the type “Custom” or “PHP” (if you experience any issues with the install, trying using another workspace type) and install the Intl extension for PHP that is required in most of the Symfony2 projects:

sudo apt-get update
sudo apt-get install php5-intl

Then set a valid PHP timezone:

echo 'date.timezone = UTC' | sudo tee --append /etc/php5/apache2/php.ini

Now start MySQL-Server:

mysql-ctl install
mysql-ctl start

Create a Symfony-Project

Open your Terminal and execute the following to create a new Symfony-Project
You need the first line only if you used the PHP Project type for your workspace.

rm README.md php.ini hello-world.php
composer create-project symfony/framework-standard-edition symfony/ "2.5.*"
mv symfony/{*,.*} ./ 
rm -rf symfony

The create-project composer command will ask for a few parameters, the only one you need to pay special attention is the database-host parameter.

Running the project

There is a IP address checking in the web/app_dev.php file. To disable this check please remove the following lines

		// This check prevents access to debug front controllers that are deployed by accident to production servers.
		// Feel free to remove this, extend it, or make something more sophisticated.
		if (isset($_SERVER['HTTP_CLIENT_IP'])
			|| isset($_SERVER['HTTP_X_FORWARDED_FOR'])
			|| !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
		) {
			header('HTTP/1.0 403 Forbidden');
			exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
		}

After that add a new run configuration in Menu Run > Run Configurations > New Run Configuration. Select Apache http (PHP, HTML) as a Runner and web/app_dev.php as Command. That’s it after you hit Run your server will start up and you can access your new Symfony project.


Tutorials - Table of Contents
#2

I really wished this worked, but it doesn’t. I’ve tried countless times with no luck.

  1. sudo apt-get update --> works
  2. sudo apt-get install php5-intl --> already current
  3. echo ‘date.timezone = UTC’ --> works
  4. mysql-ctl install --> works
  5. mysql-ctl start --> works
  6. rm README.md php.ini hello-world.php --> works
  7. composer create-project symfony/framework-standard-edition symfony/ “3.1.*” --> works
  8. mv symfony/{,.} ./ --> works
  9. rm -rf symfony --> works
    10 deleting lines from file --> works
  10. setting up the run command --> works

BUT

When I go to actually run it I see:
"Starting Apache httpd, serving https://symfony-myuser.c9users.io/."
“Started apache2”

When I click on “Preview --> Preview Running Application” I just get a file listing. When I click on web I get a 404.


#3

Even when I add in “web/addp_dev.php” into the “Command” field of the run box I get the exact same results.


#4

Same here. Are .htaccess files forbidden in c9.io?


#5

Hola tengo un problema cuando estoy instalando symfony en c9, luego de instalarlo y de quitar la verificación de Ip en config.php y voy a ejecutar https://asignaciones-jdann.c9users.io/web/config.php
me da el siguiente error:


No sé si es porque tengo una version de php anterior, pero no sé como actualizarla.
¿me podéis ayudar?
Gracias


#6

Hello:
May you help me with this error.


#7

Yo tengo el mismo error, ¿Como lo soluciono?


#8

I got symfony project running live, but when I try to look how do website is looking. I can not see the web directory.
Do you know it?


#9

tengo el mismo error y he visto que solo pasa en la versión 3 en adelante


#10

Crear un proyecto de otra versión es así
symfony new asignaciones 2.7
symfony new asignaciones 2.8


#11

When i run https://symfony-myuser.c9users.io/web/app_dev.php I have a 404 (what should i do ?)

do i need to change the permission on the web folder somehow ?


#12

Here is how you can install Symfony successfully:

Follow the official installation documentation here: http://symfony.com/doc/current/setup.html

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

Create a new Symfony project:

symfony new my_project_name

Move content of project directory one level higher and delete that empty directory:

mv my_project_name/* .
rm -rf my_project_name

As Symfony is serving its content from the web directory, we need to modify the apache config using nano (a text editor):

sudo nano /etc/apache2/sites-enabled/001-cloud9.conf

Change the DocumentRoot to the following:

// Change this line
DocumentRoot /home/ubuntu/workspace
// To this
DocumentRoot /home/ubuntu/workspace/web

To save the file, Write Out, Enter, then Close (or press F2, Y, then Enter).

Open web/app.php and toggle your project to production mode:

// Change this line
$kernel = new AppKernel('prod', false);
// To this
$kernel = new AppKernel('prod', true);

Save.

Start your Cloud9 server as usual with the green “Run Project” button.

Happy coding!


#13

An alternative method of installing Symfony, if you are installing it on VPS, is through composer. This method is quick and easy.

A simple command would do:

composer create-project symfony/framework-standard-edition your_project_name "3.0.*"

source: Install Symfony 3


#14

I got the same problem, what can i do?


#15

Thank you, thank you, thank you!!


#16

Still worked great for me at 24/10/2017 using symfony 3.3, thanks a lot