Home  >  Article  >  Backend Development  >  Install and use symfony, symfony2 installation_PHP tutorial

Install and use symfony, symfony2 installation_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:06:42911browse

Symfony installation and use, symfony2 installation

Symfony is a powerful framework with DI features. The currently popular PHP development frameworks Drupal and Laravel all use symfony at the bottom. Think about it Learn more about symfony, portal

Installing symfony is very simple, there are generally two ways, you can choose at will

1. Use symfony installer to install directly (recommended)

According to different operating systems, the installation is slightly different

1.Linux/Mac OS

Execute the following command on the console:

$ <span>sudo</span> curl -LsS http:<span>//</span><span>symfony.com/installer -o /usr/local/bin/symfony</span>
$ <span>sudo</span> <span>chmod</span> a+x /usr/local/bin/symfony

Will create a global command symfony

in your operating system

2.Windows (can be skipped)

Execute the following command on the console:

c:\> php -r <span>"</span><span>readfile('http://symfony.com/installer');</span><span>"</span> > symfony

Move the downloaded symfony file to your project directory, and then execute the following command:

c:\><span> move symfony c:\projects
c:\projects\</span>> php symfony

3. Create a symfony application

Use new command to create the first symfony application

<span># Linux, Mac OS X
$ symfony new my_project_name

# Windows
c:\</span>> cd projects/<span>
c:\projects\</span>> php symfony new my_project_name

2. Use composer to install symfony

If your PHP version is lower than 5.4, the first method is not suitable for you. You can consider upgrading the PHP version and continue to use the first method. You can also consider using composer to install it.

What is composer?

If you are familiar with java’s maven, ruby’s gem, python’s pip, and nodejs’ npm, you will of course understand it at a glance.

Yes, composer is a dependency management tool tailored for the PHP language. If you want to quickly learn about composer, use the portal

1. Install composer

Composer requires php5.3.2 to run

Linux/Mac

$ curl -sS https:<span>//</span><span>getcomposer.org/installer | php</span>

It is recommended to execute the following command

$ <span>mv</span> composer.phar /usr/local/bin/composer

In this way, composer becomes a global command and can be executed anywhere and input composer

Windows

Quick automatic installation

Download and run the composer-setup.exe program, next step, you know. Finally, don’t forget to set the path

2. Use the create-project command to create a symfony application

$ composer create-project symfony/framework-standard-edition my_project_name

If you want to specify the symfony version to install, add a parameter at the end of the command

e.g

$ composer create-project symfony/framework-standard-edition my_project_name <span>"</span><span>2.3.*</span><span>"</span>

Okay

symfony installed successfully

Let’s visit the welcome page!

symfony has an internal test server. You can start the server by executing the following command

$ cd my_project_name/<span>
$ php app</span>/console server:run

After the server is started, enter localhost:8000 in the address bar, and you will see the welcome to symfony interface.

Finally you want to stop the server, then just do this

$ php app/console server:stop

Possible questions:

If you get an error when executing php app/console server:run

You only need to find the AppKernel.php file under the app folder and add a method at the end of the file:

<span>    public</span> <span>function</span><span> init()
    {
        date_default_timezone_set( </span>'Europe/Paris'<span> );
        parent</span>::<span>init();
    }</span>

After saving, restart the server (php app/console server:run) and you are done.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1063521.htmlTechArticleSymfony installation and use, symfony2 installation symfony is a powerful framework with DI features, currently a popular PHP development framework Both Drupal and Laravel use symfony at the bottom. I want to know more about s...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn