= Apache Web Server Installation =
=== perfSONAR Installation Options ===
First update the Ubuntu package repository.
{{{
sudo apt update
}}}
Then install the web server.
{{{
sudo apt install apache2
}}}
Check the apache version
{{{
apache2 -v
}}}
Now visit your server through the IP address. http://server_ip_address.
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web1.png)]]
= PHP Installation =
Then install PHP and related modules for apache server and MariaDB.
{{{
sudo apt install php libapache2-mod-php php-mysql
}}}
To test that your system is properly configured for PHP, create a PHP script called info.php. Here we will create at the root directory.
{{{
sudo nano /var/www/html/info.php
}}}
Insert the following command to show the php information.
{{{
}}}
Next go to http://your_IP/info.php URL and you will get page like below,
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web5.png)]]
= MariaDB DBMS Installation =
Here we will choose MariaDB DBMS as our database application. Install this using below command.
{{{
sudo apt install mariadb-server mariadb-client
}}}
Once installed check the version,
{{{
mysql --version
}}}
For mysql there is a script that strengthen the mariaDB server security. It is a series of yes no questions which removes initial weaknesses of the server.
To execute the scripts,
{{{
sudo mysql_secure_installation
}}}
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web2.png)]]
To login MariaDB enter below command and use the password entered above.
{{{
sudo mysql -u root -p
}}}
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web3.png)]]
To exit type,
{{{
exit
}}}
= Apache Virtual Hosting =
Using virtual hosts, one Apache instance can serve multiple websites. Each domain or individual site that is configured using Apache will direct the visitor to a specific directory holding that site’s information. This is done without indicating to the visitor that the same server is also responsible for other sites.
Note: Before creating a virtual host for a web site domain, the particular domain or subdomain should be created. For this please contact your domain manager of your institutional IT department or relevant domain company. Then this domain should be assigned a DNS entry (A or AAAA record) to work on a web browser. In our case DNS entry should be pointed to your server IP.
Presuming you meet the prerequisites below will be the steps to create virtual hosts.
First you need to create a appropriate directory structure for each website hosted under each domain. By default root web directory in a Ubuntu system will be /var/www/html. For our setup we will use below directory structure for each site.
web site for domain 1 - /var/www/your_domain_1/public_html
web site for domain 2 - /var/www/your_domain_2/public_html
web site for domain 3 - /var/www/your_domain_3/public_html
In our example we hope to create three subdomains called web,sales and lms. So the full domain names will be web.your_domain.com, sales.your_domain.com and lms.your_domain.com respectively.
Use these commands, with your own domain names, to create your directories:
{{{
sudo mkdir -p /var/www/web.your_domain/public_html
sudo mkdir -p /var/www/sales.your_domain/public_html
sudo mkdir -p /var/www/lms.your_domain/public_html
}}}
We are going to install moodle under lms subdomain. For other two domains we will create dummy web pages for each.
{{{
sudo nano /var/www/web.your_domain/public_html/index.html
}}}
{{{
Welcome to WEB
Success! WEB home page!
}}}
Also create a similar page for the sales sub-domain.
Once created with a sample web site we have to change ownership of the directories to the web server user.
{{{
sudo chown -R www-data: /var/www/*
}}}
Now we are done with creating web sites and directories. Now we need to do the actual apache server configurations for the virtual hosting.
On Ubuntu systems, Apache Virtual Hosts configuration files are located in /etc/apache2/sites-available directory. They can be enabled by creating symbolic links to the /etc/apache2/sites-enabled directory, which Apache read during the startup. Here we need to create a seperate configuration file for each domain/sub-domain as below.
{{{
sudo nano /etc/apache2/sites-available/web.your_domain.com.conf
}}}
And add the below configurations,
{{{
ServerName web.dhammikalalantha.com
ServerAlias web.dhammikalalantha.com
ServerAdmin webmaster@dhammikalalantha.com
DocumentRoot /var/www/web.dhammikalalantha.com/public_html
Options -Indexes +FollowSymLinks
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/web.dhammikalalantha.com-error.log
CustomLog ${APACHE_LOG_DIR}/web.dhammikalalantha.com-access.log combined
}}}
Similarly do the necessary configurations for the domain sales.
{{{
sudo nano /etc/apache2/sites-available/sales.your_domain.com.conf
}}}
{{{
ServerName sales.dhammikalalantha.com
ServerAlias sales.dhammikalalantha.com
ServerAdmin webmaster@sales.dhammikalalantha.com
DocumentRoot /var/www/sales.dhammikalalantha.com/public_html
Options -Indexes +FollowSymLinks
AllowOverride All
ErrorLog ${APACHE_LOG_DIR}/sales.dhammikalalantha.com-error.log
CustomLog ${APACHE_LOG_DIR}/sales.dhammikalalantha.com-access.log combined
}}}
Once we do the configurations we have to enable the created sites as below,
{{{
sudo a2ensite web.dhammikalalantha.com
sudo a2ensite sales.dhammikalalantha.com
}}}
Once done, test the configuration for any syntax errors with.
{{{
sudo apachectl configtest
}}}
Restart the Apache service for the changes to take effect.
{{{
sudo systemctl restart apache2
}}}
Now that you have your virtual hosts configured, you can test your setup by going to the domains that you configured in your web browser. Below will be the output for the sites we created.
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web4.png)]]
Also check the other site created.
= Moodle Installation =
Now we have setup the web server, PHP and database server. Also we have configured virtual hosting. Now we are going to install Moodle under lms sub domain created above. Before installing the Moodle need to install the prerequisites for Moodle. This includes software and PHP modules that support Moodle’s features and Git for installing Moodle and keeping it up to date.
{{{
sudo apt install graphviz aspell ghostscript clamav php7.4-pspell php7.4-curl php7.4-gd php7.4-intl php7.4-mysql php7.4-xml php7.4-xmlrpc php7.4-ldap php7.4-zip php7.4-soap php7.4-mbstring
}}}
Restart Apache to load the modules.
{{{
sudo systemctl restart apache2
}}}
Then let's download the Moodle using Git repository.
{{{
cd /opt
sudo git clone git://git.moodle.org/moodle.git
cd moodle
}}}
Then get a list of stable releases from below command,
{{{
sudo git branch -a
}}}
Here we are selecting release MOODLE_400_STABLE, track and then check out the branch selected.
{{{
sudo git branch --track MOODLE_310_STABLE origin/MOODLE_310_STABLE
sudo git checkout MOODLE_310_STABLE
}}}
Copy the directory with the Moodle repository into the /var/www/lms.your_domain.com/public_html directory. Then, modify the new Moodle directory’s permissions to grant read, execute, and write access to any user.
{{{
sudo cp -R /opt/moodle/* /var/www/lms.your_domain.com/public_html
sudo chmod -R 0777 /var/www/lms.your_domain.com/public_html
}}}
Then we need to create a directory to hold moodle data in /var/moodledata and make www-data its owner, and modify its permissions to grant all users read, execute, and write access. below will be the steps.
{{{
sudo mkdir /var/moodledata
sudo chown -R www-data /var/moodledata
sudo chmod -R 0777 /var/moodledata
}}}
Moodle uses a database which needs to be created in MariaDB in our case. below are the steps to create the database.
First login the database,
{{{
sudo mysql -u root -p
}}}
Then use the following MySQL command to create a database for Moodle.
{{{
CREATE DATABASE moodle DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
}}}
Next create the user for the database and grant permissions to the database and exit,
{{{
create user 'moodledude'@'localhost' IDENTIFIED BY 'passwordformoodledude';
GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,CREATE TEMPORARY TABLES,DROP,INDEX,ALTER ON moodle.* TO 'moodledude'@'localhost';
quit;
}}}
Now the rest of the installation is done through a web installer. To access that visit the url http://lms.your_domain.com/.
In the installation follow the steps as below.
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web6.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web7.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web8.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web9.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web10.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web11.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web12.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web13.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web14.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web15.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web16.png)]]
[[Image(https://ws.learn.ac.lk/raw-attachment/wiki/Csle2022/Agenda/databaseandweb/web17.png)]]