In this video, find out how to manually start and stop the web server, and how to ensure the web server starts automatically at boot. Learn how to check the status of the server.
- [Instructor] I've got the web server installed and for this part of the course, I'll be accessing it using the server's IP Address. Let's get that with ip -4 a. I'll be viewing this site from another computer. Here's my IP Address, and I'll copy that, so I can paste it on another computer. That's where I'll be viewing the site from, but if you want to work locally, you can view the site from a desktop browser on the server, or with curl at the command line. Because my server is live on the internet, I need to be sure that my firewall is up and going.
I can check that out with sudo systemctl status firewalld, and it looks like mine's running. If it's not running, I better start it up. It's a good idea to have a firewall going, even if your system is an internally-focused one. To make the server accessible to the outside world, you'll need to allow the web service through the firewall, which here on CentOS 7 is controlled by firewalld. In the terminal, I'll type sudo firewall-cmd - -zone=public, which is my public firewall zone, - -add service=http, which will add an opening on port 80 for the TCP protocol, and --permanent, which will make this rule permanent, so that it survives through restarts of the system.
So I've got a typo there. That should be zone=public. All right. Now I'll write sudo firewall cmd --reload, to restart the firewall and load my change. If we don't allow an opening in the firewall for this HTTP service, we might be able to view the site locally, but we wouldn't be able to see it from another computer. Now let's go over to a browser and try to view our website. I'll paste in the IP Address that I got from the IP Command, and, well, that didn't work.
Even though nothing is standing between us and Port 80 on the web server, there's nothing there listening for our requests. The web server software has been installed, but it's not yet running on our system. Back in the terminal, let's check out the status of our web server, with the systemctl command. To do that, I'll write sudo systemctl status httpd. I can see that it's been loaded and it's inactive. The software's there, but it's not running.
I can bring up the server with sudo systemctl start httpd, and that starts up the software. If you're on an older system, you can start it up with service httpd start, or of course, substitute Apache 2 in there for httpd, if you're on Debian, and it can verify that it's started by checking out the status again. I'll write sudo systemctl status httpd, and now it's running, but I still see that it's disabled here.
That means that when I restart the system, the web server won't start up automatically. I want it to be up and running after I reboot, so I can enable the service for automatic starting with sudo systemctl enable httpd, and now, checking the status again, I can see that it's enabled. Now that our web server's running, let's switch back over to the browser and try again. And now it works. I can see the placeholder page that Apache displays when there's no index file to serve from the site's document route.
At this point, our web server is basically good to go. Soon, we'll add some actual files to host and make changes to the configuration. If you do make changes to the configuration, you need to reload the web service. I'll show you how to do that now, so you'll know how to reload as we go along. I'll clear the screen, and here on the terminal, I'll write sudo systemctl restart httpd. That re-reads the configuration file and re-initializes the server.
It'll interrupt anyone browsing the site or downloading a file, so be sure to reload sparingly if you're working with an active site, and, if for some reason you need to stop the web server, you can do that with sudo systemctl stop httpd. I'll cancel that now with Ctrl+C. Or, to disable the server, making the server not start up automatically at boot, you use sudo systemctl disable httpd. I'll cancel that, too, because I want my server to keep running.
- Starting up and shutting down a web service
- Configuring logging on Apache
- Adding modules to extend Apache
- Using virtual hosts
- Securing access with SSL
- Adding an SSL certificate to your site
- Protecting a site with .htaccess files