Installing Nginx on CentOS 7.5
*The Base Image for this tutorial is a Digital Ocean CentOs 7.5 Image with 1GB Memory and 25GB Diskspace.
1. Connecting to your Server
You will need a SSH-Client like Putty if you are coming from Windows. On Unix-OS like OSX and Linux you can use terminal.
After connecting to the server you will be greeted by the following screen:
2. If you are logged in as root, it is highly recommended that you create another account and add this account to the wheel group. To achieve this, you have to type the following on the terminal.
adduser <username>
where <username> can be any name you would like to have for the account. For this tutorial, we are going to create the user “corefinity”.
adduser corefinity
After hitting Enter, you need to assign a password to this user, as it won’t be enabled like in Ubuntu without doing so. To achieve this, you need to type
passwd corefinity
and repeat the password twice. You now have created your first user.
Unfortunately, this user doesn’t have any root-permissions yet, but we are going to change this now
As we are still logged in as root, we are now going to add our corefinity-user to the group of wheel.
usermod -aG wheel corefinity
will achieve this. We now have a non-root account, which can install software and updates.
To switch to this user, we need to type
su corefinity
and to exit this user and return to root, we just need to type
exit
and hit enter.
3. The first step you will need to do is updating your base image. Under our newly created corefinity-user, we need to type the following:
sudo yum update -y
and run the command by hitting enter. This will update yum’s packages and look similar to the following screenshot.
4. Now it’s time to install nginx. First we need to install the proper repository to be able to download and install nginx. In this case, we are going to use the CentOS EPEL-repository.
sudo yum install epel-release -y
If this step is finished, we can finally install nginx, by typing
sudo yum install nginx -y
Yum will download the nginx-package and ask for permission to install it.
We now need to enable nginx by typing
sudo systemctl enable nginx
and
sudo systemctl start nginx
After running this command, we can see if we were successful by typing
service nginx status
If everything went well, you will see several rows of text, which might look equal to the following screenshot.
Or you can open a browser and type in your server-ip and should be greeted by a website like this:
Congratulations! You have installed nginx on your CentOs server and fulfilled to first step to your own webserver.