How To Install Linux, Apache, MySQL, PHP (LAMP)


Setting up Apache Web Server

Install Apache

First thing first install Apache2 using the following command :

sudo apt-get install apache2
?
Testing Apache

You can test if the installation successfully by visiting http://locahost/ from the machine itself or the local ip of the machine.

Changing The Default Web Page

You can nano -> /var/www/html/index.html to change the default page using the following code :

nano /var/www/html/index.html

Once you are done Ctrl+X and Enter to save your work.

Install PHP

Install the PHP and Apache packages with the following command:

sudo apt-get install php5 libapache2-mod-php5 -y
Test PHP

You can test if the PHP installation went correctly by creating a PHP file and visit it using the following :

cd /var/www/html/

sudo rm index.html

nano ./index.php
?

Once it is open paste this code :

<?php echo "Hello World"; ?>

Save your work using Ctrl+x hit Enter. Write the following code :

sudo service apache2 restart

Then from the machine itself navigate to http://localhost/index.php OR use the machine local IP instead of localhost. If you can see the message Hello World then PHP is running correctly.

Install MySQL

Install the MySQL Server and PHP-MySQL using the following command :

sudo apt-get install mysql-server php5-mysql -y

When installing MySQL you will be asked for a root password. You’ll need to remember this to allow your website to access the database.

Now restart Apache:

sudo service apache2 restart

And that that is it for today, Now you a fully functioning LAMP server that you can access internally.

7 Important Linux Commands


Here are 7 important Linux commands to use during your SSH session.

Move Command:

Move command is used to move files around or even rename files, here’s the generic form:

“ mv [options] SOURCE DESTINATION “

Let’s say we want to move FILE1 to the previous FOLDER

“ mv FILE1.TXT .. “

or we want to rename FILE1 to X

“ mv FILE1.TXT ./X.TXT

ok let’s make it even harder and let’s say we want to move everything to the previous folder:

“ mv * ../ “

NOTE: * mean everything in this particular example it meant everything in this folder.

Change Directory:

cd is a simple command to change directory, Here’s the generic form:

“ cd DESTINATION “

For example, we want to move to /home/var/www

“ cd /home/var/www “

ok now let say we want to move to a folder inside the current folder:

“ cd ./FOLDER-NAME “

or even move to the previous folder simply write:

“ cd .. “

Simple ! huh ?

Remove File Or Directory:

rm command is used to remove files, and in order to remove folders you have to include -rf for example :

“ rm * “

The previous command will actually remove all files if the current folder contains folders as well you need to do the following

“ rm -rf * “

This command will result in removing everything in the current folder. Keep in mind you can also remove the and specify a folder name instead.

NOTE: In some cases, you might need to use SUDO to be able to execute this command.

List Directory Content:

ls is used to list all files and folders inside the current folder.

“ ls “

we are not going to go into the details of this command since it is mostly used as demonstrated above.

Change Mode Command:

CHMOD or Change mode command is used to change permissions of files or folder “Directory”. It is crucial if you want to give a system a power to do things or even restrict it.

“ chmod XXX NAME-HERE “

you replace XXX with the permission number. There is also another variation for changing the mode recursively as following

“ chmod -R XXX FOLDER-NAME “

Web Get :

Web Get or wget command is used to download stuff from the internet directly to your machine instead of using FTP or SFTP. In some cases, you need to install it using your package manager depending on your OS. For Ubuntu or other Debian based distribution you can install it using the following command:

“ sudo apt-get install wget “

After that, you are ready to go. Here are some examples:

“ wget URL “

It is preferred to be a compressed file Like .ZIP So you can unzip it easily. It is used for example to download WordPress files for any other purpose.

UNZIP Command:

UNZIP command it’s simply a command to “unzip” or uncompress files from a ZIPPED file. Let’s say you got a file from wget command and you want to unzip in the current folder you do the

following:

“ unzip FILE-NAME.ZIP “

If you don’t know the file name you just use the command above “ ls “. You can also specify the destination using:

“ unzip FILE-NAME.ZIP -d DESTINATION “

NOTE: In some cases, you need to install it using your package manager depending on your OS. For Ubuntu or other Debian based distribution, you can install it using the following

command:

“ sudo apt-get install unzip “

Finally, I would like to note that some commands mentioned above have some other options or variations. This is just a basic guide to get you started with your VPS or SERVER.

4 essential tools for Linux

Rsync

Rsync is an open source bandwidth-friendly utility tool for performing swift incremental file transfers and it is available for free.

$ rsync [OPTION...] SRC... [DEST]
?

Install Rsync on Ubuntu and Debian, using the following commands.

$ sudo apt-get install rsync
$ sudo apt update

Vim

Vim is an open source clone of vi text editor developed to be customizable and able to work with any type of text.

Install Vim on Ubuntu and Debian, using the following commands.

$ sudo add-apt-repository ppa:jonathonf/vim
$ sudo apt update
$ sudo apt install vim

GNOME

GNOME is a Desktop Environment comprised of several free and open-source applications and can run on any Linux distro and on most BSD derivatives.

Install Gnome desktop on Ubuntu and Debian, using the following commands.

$ sudo apt install tasksel
$ sudo apt update
$ sudo tasksel install ubuntu-desktop

Screen Linux

screen command in Linux provides the ability to launch and use multiple shell sessions from a single ssh session. When a process is started with ‘screen‘, the process can be detached from session & then can reattach the session at a later time.

Install Screen desktop on Ubuntu and Debian, using the following commands.

$ sudo apt install screen
$ sudo apt update