Servers
Overview Apache, Nginx, PHP
Web Server Software
Section titled “Web Server Software”- 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?
Apache HTTP Server
Section titled “Apache HTTP Server”- 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.
Install Nginx
Section titled “Install Nginx”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:
- Install homebrew and run
brew install nginxbrew services start nginxnginx -v- Go to http://localhost:8080
- Follow either official or these instructions for installation
- Confirm
nginx -v - Go to http://localhost:8080
Nginx Tips
Section titled “Nginx Tips”# location of nginx.conf (Mac)/opt/homebrew/etc/nginx/nginx.conf
# test the config filenginx -t
# each time you update nginx.conf filebrew services restart nginx
# to see all services and their statusbrew services list
# show log files (location in nginx.conf)tail /opt/homebrew/var/log/nginx/access.logtail /opt/homebrew/var/log/nginx/error.log
# open nginx folder for easier editingcd /opt/homebrew/etc/nginx/code .Install PHP (Nginx)
Section titled “Install PHP (Nginx)”- Run
brew install php - Edit your nginx.conf to look like my sample: https://gist.github.com/omundy/092d1293349dd1b4f7f5729cf7233463
- Restart nginx, start PHP, list services to make sure both are running
brew services restart nginxbrew services start phpbrew services listPHP Test
Section titled “PHP Test”- Create a new file in your root directory: phpinfo.php
- Add below text
- Go to http://localhost (don’t need 8080 port since we changed to 80 in nginx.conf)
<?php phpinfo();?>