Nginx Setup: Migrating Your WordPress Site from Apache to Nginx
What Will You Learn in This Guide?
In this guide, you will learn how to migrate a WordPress site running on Apache to Nginx and PHP-FPM architecture.
The aim is to achieve lower resource usage and high traffic endurance.
🧠 Technical Summary
Main Technical Topic:
Migrating WordPress from Apache to Nginx on Ubuntu server.
Solved Problem:
Apache's increased resource consumption under high traffic.
Steps Followed:
- Nginx and PHP-FPM installation
- PHP-FPM security settings
- Nginx server block configuration
- Disabling Apache service
1️⃣ Nginx and PHP-FPM Installation
sudo apt-get update
sudo apt-get install nginx php5-fpm
- This command installs the Nginx web server and PHP handler.
2️⃣ PHP-FPM Security Configuration
sudo nano /etc/php5/fpm/php.ini
- This file is opened to edit PHP execution behavior.
cgi.fix_pathinfo=0
- This setting prevents incorrect PHP files from being executed.
sudo nano /etc/php5/fpm/pool.d/www.conf
- This file determines the connection method of PHP-FPM with Nginx.
listen = /var/run/php5-fpm.sock
- This setting allows PHP-FPM to communicate faster over the socket.
sudo service php5-fpm restart
- This command activates PHP-FPM configuration changes.
3️⃣ Creating an Nginx Server Block
sudo nano /etc/nginx/sites-available/default
- This file opens Nginx's default site configuration.
server {
listen 80;
root /var/www;
index index.php index.html index.htm;
server_name ornek.com www.ornek.com;
location / {
try_files $uri $uri/ /index.php?q=$uri&$args;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
}
location ~ /\. {
deny all;
}
}
- This configuration defines secure and optimized Nginx rules for WordPress.
4️⃣ Migrating from Apache to Nginx
1. Nginx cannot use port 80 while Apache is running.
sudo service apache2 stop
sudo service nginx start
- This command stops Apache and starts Nginx.
5️⃣ Uninstalling Apache Packages (Optional)
sudo apt-get remove apache2*
- This command removes Apache and associated packages from the system.
sudo apt-get autoremove
- This command cleans up dependencies that are no longer used.
❓ Frequently Asked Questions (FAQ)
1. Will my site speed up when I switch to Nginx? It provides a significant performance increase in high concurrent traffic.
2. Do .htaccess files work? No, the rules must be moved to the Nginx configuration.
3. Why does PHP-FPM use socket? Provides lower processing load on local connections.
4. What if I get a 502 Bad Gateway error? Check that the PHP-FPM socket path and Nginx settings match.
🎯 Result
Your WordPress site now runs more stable and efficiently on Nginx. This transition provides a serious advantage in high-traffic projects. You can safely use this architecture on the GenixNode infrastructure 🚀

