This blog post will contain useful information for those, who want to start developing in Symfony without setting up a server (like apache or nginx) or installing docker.
PHP from version 5.4 has built in server. You can run it by executing in console php -S 127.0.0.1:8000 in your projects directory. When you go to this address (of course you can change the port and 127.0.0.1 to localhost) you’ll see the main page of your project.
How to start?
Let’s do a simple test.
1. check your PHP version php -v (it must be greater than 5.4.0)
2. create empty directory for the test mkdir ~/php_test && cd ~/php_test
3. create simple file echo “<?php phpinfo();” > index.php
4. run the server php -S 127.0.0.1:8000
You should see something like this:
Ok, your server is running. So we can try to run Symfony using build in server
I’m using in this example Symfony installer for installing the framework. It’s the simplest way to do it. You may find information about it here. If you don’t want to install the installer you may find other ways on that link.
1. create new Symfony installation: cd ~ && symfony new symfony_test
2. install composer dependencies: cd symfony_test && composer install
3. run the serv… oh, wait a minute 😉
Symfony build in server
You can run PHP build in the server in the projects directory: php -S 127.0.0.1:8000. But on that url, you’ll see nothing because Symfony uses `/web/app_dev.php` file as an index. To see the site you must go to http://127.0.0.1:8000/web/app_dev.php
But Symfony has its own build in the server, based on the PHP’s one. Thanks to it you can skip the `/web/app_dev.php` part and go directly to http://127.0.0.1:8000.
To run it just execute bin/console server:run. Go to your browser, type http://127.0.0.1:8000 and enjoy your fresh Symfony installation.
That’s it. It’s really that simple. Now, go to your project, change something and have fun with Symfony 🙂
Don’t forget to check out other PHP related posts!
- Adding a new Logger to Laravel
- [Edit] How to deploy Symfony app with Capistrano 3 on cheap OVH VPS
- How to make cool progressbar in Symfony command?
- Using PHP5.6 and PHP7.1 at the same time on OS X!
- First attempt to Selenium and PHPUnit
- How to start developing in Symfony with only PHP installed?
- PHPyths Buster: A great string performance test! (updated)
- PHPyths Buster: Single quotes are faster than double quotes
- PHPyths Buster: The power of simple CLI modes
- PHPyths Buster: Annotations