Skip to content

Servers

Overview Apache, Nginx, PHP
  • A web server is computer software that accepts requests via HTTP (web content network protocol) or its secure variant HTTPS.
  • A web browser makes a request for a web page or other resource using HTTP, and the server responds with the content of that resource.
  • According to W3Techs review of all websites in June 2022, Apache was ranked second at 31.4% and Nginx first at 33.6%, with Cloudflare Server third at 21.6%.

NGINX vs. Apache: Which web server is better for performance and scalability?

  • Since 1995
  • Free and open-source cross-platform web server software (Apache License).
  • Usually installed on Linux (the A in the LAMP stack)
  • So popular it has always been already installed on MacOS.
  • Widely capable by configuring it with additional modules.
  • Apache is process-driven creating a thread per each request.
  • Since 2004. Pronounced “engine x”
  • Free and open-source cross-platform web server software (BSD license) .
  • Newer, and generally considered easier to configure, thus LEMP
  • Can also be used as a reverse proxy, load balancer, mail proxy and HTTP cache.
  • NGINX uses a non-threaded, event-driven architecture to handle multiple requests within a single thread. Thus, can outperform Apache if configured correctly.

Installing Nginx will

  • Let you run any script that requires a server (APIs, imports, PHP, etc.) on localhost, at any time.
  • Give you a development server to test with.
  • Initial installation differs per platform. Do these and go to the next slide:
  1. Install homebrew and run
Terminal window
brew install nginx
brew services start nginx
nginx -v
  1. Go to http://localhost:8080
Terminal window
# location of nginx.conf (Mac)
/opt/homebrew/etc/nginx/nginx.conf
# test the config file
nginx -t
# each time you update nginx.conf file
brew services restart nginx
# to see all services and their status
brew services list
# show log files (location in nginx.conf)
tail /opt/homebrew/var/log/nginx/access.log
tail /opt/homebrew/var/log/nginx/error.log
# open nginx folder for easier editing
cd /opt/homebrew/etc/nginx/
code .
  1. Run brew install php
  2. Edit your nginx.conf to look like my sample: https://gist.github.com/omundy/092d1293349dd1b4f7f5729cf7233463
  3. Restart nginx, start PHP, list services to make sure both are running
Terminal window
brew services restart nginx
brew services start php
brew services list
  1. Create a new file in your root directory: phpinfo.php
  2. Add below text
  3. Go to http://localhost (don’t need 8080 port since we changed to 80 in nginx.conf)
<?php
phpinfo();
?>