Helpful Commands for New LAMP Stack Developers — Part 1 Linux

Javonwebster
4 min readDec 29, 2020

--

Getting started as a new developer can be challenging and intimidating, especially for those of us fresh out of university (college) or are simply self-taught. I‘ll be creating a series of articles where I will highlight a few widely used scripts and commands that could aid new junior developers in conquering those initial hurdles that you will inevitably face in your first job as a LAMP stack developer. I won’t be going into great detail in these articles, but I will be providing useful links to more detailed articles and how-tos.

First things first, “LAMP” stands for Linux, Apache, MySQL, PHP, and is one of the many development environments that are used to create websites and web applications.

LINUX

Linux is our server’s operating system and like with Windows and MacOS, we can run commands through a command line or terminal. If you are familiar with MacOS a lot of these commands would already be familiar to you.

The list command

List all files and folders in a directory

ls

The list command also has a set of “options” that will allow you to get more information. You can see a few examples here.

The cat command

This command has a lot of uses, but it is primarily used to view the text contents of a file.

cat fileName.php

You can find a few more useful examples here. Also, take a look at the touch command.

  • Text editors- there are few text editors that are available in Linux, such as nano and vim. The main difference between the two is that vim has a “mode” setting that allows you to switch between read-only and editing mode, whereas nano is only editing. Each has an extensive list of commands and shortcuts and I strongly recommend learning to use both.
Example of the Nano editor
Example of Vim editor

The Copy (cp) and Move (mv) commands

These commands are self-explanatory.

cp sourceFile.txt destinationFile.txt
mv sourceFile.txt destinationFile.txt

A quick note; the move command can also be used to rename a file by specifying the same directory for the destination as the source file.

As you can guess, there are once again a ton of options for each. Follow the links to options for copy and move.

Changing file Permissions and Ownership.

I cannot begin to tell you how many times I’ve run into issues where stuff randomly breaks and it was simply because file permissions got messed up. For example, if there is a script that we need to run, we need to ensure that the user running that script has permissions to run that script or in the case of a web application, the file being served to a user can be read by said user. These commands are also extremely useful when restricting access to content.

chmod 764 fileName.txt

chmod allows us to set the read, write, and execute permissions for all users. In the example above each number represents the permissions that will be granted to each group. Reading from left to right the first group is the file owner, followed by the group members, and finally, everyone else who doesn’t fall into the first two categories. Below is a table that will highlight what the numbers themselves mean.

Table with Linux permissions

Therefore from our example, we can deduce that for the file fileName.txt the permissions are as follows:

  1. the file owner- 7 — read, write and execute
  2. the group- 6 — read and write
  3. everyone else- 4 — read-only

Here are a few links that go into greater detail:

chown will allow you to change the ownership of a file or directory.

chown myuser fileName.txt

The above command changes the ownership of the file to “myuser”.

chown myuser:mygroup file1

Whereas this command does the same thing but also changes the group ownership.

Here are a few links that go into greater detail:

Zipping and unzipping files

The ability to archive files is extremely important. For that, we have the tar command.

tar cvf pages_backup.tar views/pages

The above command zips the contents of “views/pages” and creates a tar file called “pages_backup.tar”.

tar xvf pages_backup.tar

This command unzips the tar file for us.

Another very useful option is the “exclude” when zipping. Sometimes we don’t want to zip everything in a directory. So we would run something like:

tar cvf pages_backup.tar — exclude='views/pages/old/*’ views/pages

This command will zip everything in the “pages” directory and exclude the files in the “old” directory. You can see more useful options here.

--

--