Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Sometimes you need both apache2 and nginx on your development environment, and for debugging purposes or because of your totally normal laziness or for other reasons if you want to make only one of them working and listening on port 80, you can use this bash script.
This will check which proxy server is currently running, kill it, and turn on the other.
Just as simple as that. Enjoy:)
#!/bin/bash
# by Valery Kotlarov @ www.webdesignpatterns.org
echo "Do I have the right privileges?"
if [ "$(whoami &2>/dev/null)" != "root" ] && [ "$(id -un &2>/dev/null)" != "root" ] ; then
echo " NO!
Error: Can't execute this. Try with sudo, sudo -i or su etc...
Enter
sudo su
"
exit 1
fi
echo " OK";
echo $(/etc/init.d/apache2 status | awk '{print $3}');
if [ "$(/etc/init.d/apache2 status | awk '{print $3}')" == "running" ] ; then
/etc/init.d/apache2 stop
sleep 2
/etc/init.d/nginx start
else
/etc/init.d/nginx stop
sleep 1
/etc/init.d/apache2 start
fi
echo "Done switching!!"