@webydevyguy
Always happy to help!
When using apt-get
, you’ll mainly be working with a few commands.
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install
sudo apt-get purge
sudo apt-get remove
sudo apt-get autoremove
apt-get update
basically synchronizes your server with upstream repositories which ensures that you’re able to install the latest package versions. It won’t make any major changes or effect existing software installations.
apt-get upgrade
will automatically upgrade all existing software packages where possible. This is where you really want to make backups of configuration prior to execution. A snapshot will work as a method of backup, though you really would benefit more from knowing what to backup.
apt-get install
is what you’ll use to install software packages, such as additional PHP modules, or similar. Keeping your web server as lean as possible is the goal, so only install what you absolutely need for your setup.
apt-get remove
is how you’ll delete a package, or remove it from your server. It doesn’t always remove configuration files when ran, so that’s what the next function is for.
apt-get purge
is for when you absolutely want to remove most all traces of a piece of software.
sudo apt-get autoremove
removes packages that are installed but not currently being used by any existing software that has been installed. This is more of a cleanup utility command and its safe to run without effecting current installations or configuration.
Backups
When it comes to creating backups, a snapshot will work as one method as it will store the current state of the machine to an image that can be restored at a later date. One thing to keep in mind is that if you simply restore from a snapshot, it will overwrite everything on your server (including website data, thus you will lose any work you’ve done from the time you took the snapshot to the time you restore it).
The best course of action is to know what files you need to keep copies of and which ones you don’t.
For example, if you run apt-get upgrade
and NGINX is on the list, you’d want to make a backup of the core NGINX directory which is /etc/nginx
.
If PHP is on the list, you should make a backup of /etc/php
. Exact version data for PHP will be below this folder, but it’s safe to backup the entire directory.
Files, Permissions, etc
When you change over to a directory using cd
, you can run a list command to view directory info. That info will tell you the current CHMOD as well as what user & group owns the file.
You DO NOT want to randomly go around changing file permissions unless you know what you are doing as many files require root to be the owner.
You only want to change ownership of files that you will be allowing the public to access. In most all cases, this will be files in your users /home/
directory.
For example, we can create a new user directory by running:
sudo mkdir -p /home/example
Then we can create a new user:
sudo useradd -d /home/example example
The above command creates a new user named example
, a new group named example
and sets the home directory for the user to /home/example
.
We would then proceed to create any additional directories that are needed for the account. For me I normally create a few more structures, such as:
sudo mkdir -p /home/example/htdocs/{public,private,logs}
The {public,private,logs}
allows me to create multiple directories below htdocs
using expansion, so we’ll end up with:
/home/example/htdocs/public
/home/example/htdocs/private
/home/example/htdocs/logs
At this point, all of these directories are owned by root, so we now need to change that by changing the ownership. This is done by using chown
(ch = change, own = ownership).
chown -R example:example /home/example
The above command will recursively change ownership on /home/example
and all of the directories we just created above.
Of course, this is just the basics. We can get even more detailed and even more in-depth, though this gives you an idea of how we go about getting things setup. It’s all one step at a time.