Sunday, May 14, 2017

Install Apache

Contents

1.  Virtual box and Vagrant

2.  Install Apache

3.  Install MySQL

4.  Install Python

5.  Hello World with Python

1. Install Apache

Apache is a software that is used to make a computer a server. Now we have a virtual machine (Cent OS 7) but we need to make it a virtual server, so we will install Apache into the virtual machine.

Do the following command to check information about what Apache is available for our virtual machine:

$ yum info httpd


And the information is displayed. Seems like there is no problem. We will install Apache, so do the following command:

$ sudo yum -y install httpd

Then install will begin. It might take a little time, so wait for a little while.


2. Start Apache (httpd)

We will start Apache (that is also called httpd in Linux) by the following command:
(For CentOS7)
$ sudo systemctl start httpd.service

(For CentOS6 or older)
$ sudo service httpd start

If this doesn't work, maybe the OS doesn't recognize "systemctl" as a command. Such commands are inside /sbin, so do the following command instead:
(For CentOS7)
$ sudo /sbin/systemctl start httpd.service

(For CentOS6 or older)
$ sudo  /sbin/service httpd start

You will be asked password to start httpd. The password is "vagrant".

To check the status of Apache (httpd):
(For CentOS7)
$ sudo systemctl status httpd.service

(For CentOS6 or older)
$ sudo service httpd status

To stop Apache (httpd):
(For CentOS7)
$ sudo systemctl stop httpd.service

(For CentOS6 or older)
$ sudo service httpd stop

To re-start Apache (httpd):
(For CentOS7)
$ sudo systemctl restart httpd.service

(For CentOS6 or older)
$ sudo service httpd restart


3. Start Apache automatically

To start Apache automatically when the virtual machine is started, do the following command:
(For CentOS7)
$ sudo systemctl enable httpd.service

(For CentOS6 or older)
$ sudo chkconfig httpd on

4. Check if the server is working

(Start your Apache at first.) Then we will access to the following link with your browser: http://192.168.33.10/
(Any browser is OK)

If your virtual machine and Apache are working correctly, the following should be displayed in the browser:


This can not be accessed from outside. This is a private network (as defined in Vagrantfile), so this can be accessed only from your PC.

(By the way, if you choose "public network (sharing virtual machine in a local network)" in Vagrantfile, everybody in your LAN network can access to this link, too. But anybody outside your LAN network can not access. If you made this virtual environment at your home and if your co-worker tries to access to this link from your company, he can't access. Because he is outside your LAN network. But if he tries to access at your home, he can because he is in your network. This is because Vagrant is mainly used for development and check if web application works correctly.)

5. Symbolic link

We will make "Symbolic link" because it is useful. If we make symbolic link from /vagrant to /var/www/html, everything inside the share folder (/vagrant) is instantly copied to the Apache folder (/var/www/html) so that anything updated in the share folder is also instantly updated in the Apache folder too.

Do these commands:

$ sudo rm -rf /var/www/html 
$ sudo ln -fs /vagrant /var/www/html

We will check if symbolic link is correctly created:

$ ls /var/www/html



If all files inside the vagrant's share folder are displayed, you made it successfully. If not, you have made any mistake.

And we will install vim (an editor):

$ sudo yum install vim-enhanced