Warming up with LAMP

My studies with Linux continue and our first assignment was executing an old exam from the basic course (Työasemat ja tietoverkot, Linux).

I chose this exam from beginning of spring in 2012. http://terokarvinen.com/2012/linux-koe-tyoasemat-ja-tietoverkot-25
This exercise was made by using Xubuntu's 14.04 version.

Installing Apache


sudo apt-get update
First things first. I wanted to have the latest packages available.
sudo apt-get install apache2
I changed the location to user's directory and restarted Apache.

After the installation I tested if Apache is running by writing localhost to the web browser's address bar. "It works!" -page appeared.


Installing MySql


sudo apt-get install mysql-server
After a moment the console asked me to define root's new password. I did this and continued the installation.

sudo apt-get install phpmyadmin
Now when I had mySql I could connect it with phpmyadmin. In package configuration I selected Apache2. 

The installation was successful and phpMyAdmin appeared to localhost/phpmyadmin.



Installing PHP


sudo apt-get install libapache2-mod-php5
I ran the installation command for PHP module and navigated to /apache2/mods-enabled. I would need to modify a file called php5.conf in order to get the module actually working.

sudoedit php5.conf
I commented the whole Running PHP scripts in user directories is disabled by default with ### and saved the file.



php5.conf after being modified

Installation and management of SSH


sudo apt-get install openssh-server

After the installation was complete I created accounts for Einari Vähäkäähkä, Pekka Winha, Åke Andersson ja Leila Laila. 

sudo adduser einavaha
sudo adduser pekkwinh
sudo adduser akeande 
sudo adduser leillail

Each command was followed by information form where I entered the user's full name and password.

Creating a webpage and testing PHP

ssh leillail@localhost
mkdir public_html
nano index.html

I logged into Leila's profile, made a new folder for the webpage and created there index.html
I wrote a small sample code for her page and it appeared in localhost/~leillail.




I still needed to test if the PHP module was working so I signed out from Leila's profile and got in this time as Pekka Winha. Once again I made a new directory public_html but this time instead of html I created a simple php file. 

And it worked! localhost/~pekkawinh/foo.php showed up as it should. 

Creating a Shell Script



The final goal was creating a shell script that could show the free disc space and IP.


nano mystatus.sh
First I created the file. Notice that .sh wouldn't be required but it is just something I have used to do to clarify things. The script would work perfectly fine without it too. 

I wrote the needed commands ( df -h and /sbin/ifconfig eth0 | grep 'inet addr:' | cut -d: -f2) inside the file and saved it.

chmod +x mystatus.sh
I gave the rights for all users being able executing this command.

sudo cp mystatus.sh/usr/local/bin
The last step was to copy the script into this location so it would be able to run.



Sources: Lectures by Tero Karvinen,  https://scottlinux.com/2013/04/30/centos-linux-or-ubuntu-linux-get-list-of-ip-addresses-on-server/

Based on Linux course by Tero Karvinen (http://terokarvinen.com)

Comments

Popular Posts