In our recent series of posts, we have explained a lot of things about Linux web servers. The three main Linux web servers that we introduced were Nginx, Apache, and Lite Speed. We said some pros and cons for each of them. We also mentioned that Apache is the most commonly used web server all over the world. For any reason, you may choose a web server and then decide to change it later. In this post, we are going to show you how you can switch your web server from Apache to Nginx.
Switch from Apache to Nginx Web Server
The first thing you need to do is establishing an SSH connection to your server using Softwares like PuTTY. You need to have root access to your server. So, if your service is anything that doesn’t give you the root access, you need to ask your hosting provider to switch the webserver for you.
After logging into the server using PuTTY, you need to check the version of your control panel‘s “Custombuild”. Use the commands below to check and upgrade.
Check the Version:
cd /usr/local/directadmin/custombuild ./build version
Upgrade the Version:
cd /usr/local/directadmin mv custombuild custombuild_1.x wget -O custombuild.tar.gz http://files.directadmin.com/services/custombuild/2.0/custombuild.tar.gz tar xvzf custombuild.tar.gz cd custombuild ./build
Now we can simply use this command to switch from Apache to Nginx:
cd /usr/local/directadmin ./build set webserver nginx
This is what you are going to see at the end of the process:
After this, you need to change the PHP handler. We’ve already explained that every webserver has its own ph handler. Apache supports almost all of PH handles. So here we need to change the PHP handler to PHP-FPM.
/build set php1_mode php-fpm
Now copy and paste these commands in turn:
./build update
./build all d
*This Process may take more or less than 20 minutes depending on the server’s RAM.*
Let’s finish the installation:
./build rewrite_confs
As the last step, restart Nginx to finish the process:
/sbin/service nginx restart
You have successfully switched your webserver from Apache to Nginx!
Hope you enjoyed this post if you did, you can visit our blog for more!