You often need to restart apache 2 or restart nginx web server Maybe you may have increased the php max upload file size limit but still, your changes have not come to action so you need to restart the web server so that it will load the updated configuration files. Therefore today I will tell you all that you need to know about restarting Apache 2 and Nginx.
Firstly for restarting web server you either need access via SSH or need have physical access to the machine. Basically, you need to have access to the server terminal so that you can run the required commands. So if you don’t have access to your server’s terminal and then it would not be a great idea to read this post any further get access to the terminal and come back here so that you can follow the instructions further and restart your web server.
Okay, so now that you are reading further I believe that you have access to the terminal and all set for restarting your Apache 2 or Nginx web server.
Let’s start with the most popular web server which is Apache 2.
Restart Apache 2
Every Operating system has a different command for restarting apache 2 so I will tell you all the commands for each operating system and you select the command according to your servers operating system.
Restarting Apache 2 On Debian Version 8.x+ And Ubuntu Version 15.04+
Mostly All of you might be using Ubuntu 15.04+ or Debian 8.x+ therefore for all those who want to restart the Apache 2 and are using the above given or newer versions of Ubuntu you can do it using the command given below.
systemctl restart apache2.service
Other Debian/Ubuntu Specific Linux Commands
These commands will work on Ubuntu Linux version 14.10 and Debian Linux version 7.x or below.
Commands To Restart Apache 2
sudo /etc/init.d/apache2 restart
Restart Apache 2 Using Service Instead Of /etc/init.d/apache2
You may use service instead of /etc/init.d/ in the commands which I have told you below.
service apache2 restart
sudo service apache2 restart
CentOS/Red Hat (RHEL) Linux Commands
CentOS or Red Hat (RHEL) version 7.x users can use the following command for restarting your Apache 2 web server.
systemctl restart httpd.service
CentOS/Red Hat (RHEL) Linux Version 6.x Or Older Commands
If you are one of those rare people who still hasn’t upgraded to their Linux version then you may use these commands for restarting apache 2.
service httpd restart
NOTE: I would recommend you to upgrade your operating systems to the latest version if you are using the older versions.
For restarting Nginx web server you can simply use one of the commands given below. Just type in the command and press enter.
Restart Nginx On Debian/Ubuntu/Red Hat (RHEL)/ CentOS Linux
Unlike Apache 2 Nginx does not have the different commands for different operating systems. Nignix has a few commands which can be used on Debian, Ubuntu, Red Hat (RHEL), CentOS, etc.
These are the commands which you may use.
service nginx restart
Nignx Restart On systemd Based Linux Systems
In case if you are using a systemd based Linux system then you may use the following command for restarting nginx system.
sudo systemctl restart nginx
If you dont know twhat systemd is you can read about it over here.
Restarting Nginx Binary
If you are one of those rare people who is using the Nginx Binary i.e if you have compiled nginx from the source then you shall enter this command. You need to enter the path where Nginx is installed like this in the command-
/usr/local/nginx/sbin/nginx -s reload
Did you successfully restart apache 2 or restart Nginx? I hope you did. Let me know in the comments section below and also if you have faced any issues while restarting the web server don’t hesigitate to ask me in the comments I would be glad to hear you and reply to your comments.
And one more thing don’t forget to share it with your other web developer friends on facebook, twitter, google plus, etc.