简体   繁体   中英

Deploying Laravel site via Nginx Vs. PHP Artisan Serve

Since locally, I did only php artisan serve and it works fine. In my production VM, I am not sure if I should just do the same php artisan serve & so I don't have to install Nginx , configure the document root, and so on.

Are there any disadvantages in doing that?

nginx

  • designed to solve c10k problem
  • performs extremely well, even under huge load
  • is a reverse proxy
  • uses state of the art http parser to check whether request is even valid
  • uses extremely powerful yet simple config syntax
  • comes with plethora of modules to deal with http traffic (auth module, mirror module)
  • can terminate ssl/tls
  • can load balance between multiple php serving endpoints (or any other endpoints that speak http)
  • can be reloaded to apply new config, without losing current connections

php artisan serve

  • designed to quickly fiddle with laravel based website
  • written in php, isn't designed to solve c10k problem
  • will crash once available memory is exceeded (128 mb by default, that gets quickly filled up)
  • isn't a reverse proxy
  • isn't using state of the art http parser
  • isn't stress tested
  • can't scale to other machines the way nginx does
  • doesn't terminate SSL. Even if it did, it would be painfully slow compared to a pure compiled solution
  • isn't event-based or threaded the way php-fpm/nginx are so everything executes in the same process. There's no reactor pattern for offloading to workers to scale across cpu cores and protect against bringing the server down if a piece of code is messed up. This means if you load too much data from MySQL - process goes down, therefore the server too.

Configuring nginx takes about ~30 seconds on average, for experienced person. I'm speaking from experience since it's my daily job. Using automation tools like ansible makes this even easier, you can almost forget about it.

Using a web server designed to fiddle and quickly test a part of your code in production comes with risks. Your site will be slower. Your site will be prone to crashing if any script kiddie decides to run a curl request in a foreach loop.

If you think installing and configuring nginx is a hassle and you want to go with php artisan serve , make sure you run it supervised ( supervisord is my go to tool). If it crashes, it'll boot up back again.

In my opinion, it's worthless to run a php-based server to serve your app. The amount of time spent to configure nginx / php-fpm isn't humongous, even if you're new to it.

Everything comes with risks and gains, but in this particular case - the gain doesn't exist, while there's certainty that something will go wrong.


TL;DR

Don't do it, spend those few minutes configuring nginx. The best software is the one that does the work well to that point you can forget about it. nginx is one of those tools. PHP excels in many areas, but built-in webserver is not one of those things that you should use in production. Go with tools proven in the battle field.

The php artisan serve never should be used on the production environment as it is using the PHP7 built-in server functionality which is designed to development purposes only .

See this page

So, please avoid using in production. Instead, use Apache or Nginx, which both are good choices, depending on your needs. Nginx may be usually faster(not always).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM