Welcome dear reader, today you will learn how to host a web application with the two most popular open-source web servers: Apache2 and Nginx. Your web server is the front door of your application — it receives every HTTP request, serves your static files, and hands dynamic requests to your code. Let’s set up both, so you can pick your favorite.
Table of contents
- What is the Difference Between Apache2 and Nginx?
- How to Host a Site with Apache2
- How to Host a Site with Nginx
- Which One Should You Choose?
- Conclusion
What is the Difference Between Apache2 and Nginx?
Apache2 has been around since 1995 and processes requests with an embedded interpreter: the web server itself runs your PHP through a module such as mod_php. Nginx, by contrast, is built as an event-driven server — it excels at serving static files and forwarding dynamic work to a separate process, typically PHP-FPM.
In practice, both handle PHP applications perfectly well; they differ in configuration style and how they share the workload. If you already followed our guide on installing WordPress on a VPS server, you have seen Apache2 in action with its virtual hosts.
How to Host a Site with Apache2
Install Apache2, then create a virtual host file in /etc/apache2/sites-available/myapp.conf:
<VirtualHost *:80>
# (1) The domain this site answers for
ServerName example.com
# (2) The document root of your application
DocumentRoot /var/www/myapp/public
# (3) Allow .htaccess overrides for URL rewriting
<Directory /var/www/myapp/public>
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Enable the site and reload the server:
# Enable the site and rewrite module sudo a2ensite myapp && sudo a2enmod rewrite sudo systemctl reload apache2
Apache picks up PHP automatically through its module — that is the zero-configuration charm.
How to Host a Site with Nginx
With Nginx, create a server block in /etc/nginx/sites-available/myapp:
server {
# (1) The domain this site answers for
server_name example.com;
# (2) The document root of your application
root /var/www/myapp/public;
index index.php;
# (3) Forward PHP to PHP-FPM over a socket
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.2-fpm.sock;
}
}
Enable it with a symbolic link and reload:
# Enable the site and test the configuration sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/ sudo nginx -t && sudo systemctl reload nginx
Note the extra php8.2-fpm service that must be running — that’s the separate interpreter model in action. For a deeper dive into performance and security options, read our Nginx configuration best practices.
Which One Should You Choose?
Choose Apache2 for maximum compatibility — every shared host supports it, .htaccess rewrites work out of the box, and WordPress feels at home. Choose Nginx when you serve lots of static assets, need a reverse proxy, or run high-traffic sites where its memory efficiency shines. Both are battle-tested; the “wrong” choice is staying undecided while your application waits.
Conclusion
That’s already it to host your web application with either server. Apache2 offers embedded simplicity and .htaccess, Nginx offers event-driven speed and proxying — and both host your code in a handful of configuration lines. Leave a comment below with the web server you picked for your stack, and why!
At re:Software S.L., we create innovative solutions for businesses that aim to digitize their processes and routines, and we have often come to choose between nginx and apache2 depending on the use case.

