Showing posts with label Notes on Apache. Show all posts
Showing posts with label Notes on Apache. Show all posts

Tuesday, July 28, 2020

Virtual or Web Hosting on Ubuntu 18.04 LTS (Bionic Beaver)

The following virtual or web hosting setup intends to:

• Make the Apache2 home directory for the virtual hosts in "/home"
• Virtual hosts will be located in their own directory (e.g., user "rasul" will be located in "/home/rasul") and accessible via remote SSH
• Web pages of each virtual host (e.g., user "rasul") will be located in "/home/rasul/www/html"
• Error pages of Apache2 will be located in "/home/rasul/www/error"
• Access log pages of Apache2 will be located in "/home/rasul/www/access"


My preferred editor in here is "joe", a WordStar-like text editor, but you can use your own preferred editor like "vi", "vim", or "nano". This also assumes that you have made the relevant DNS entries for the web host and pointed to the IP address of the Apache webserver.
Step 1: Edit the "apache2.conf" configuration file and add the following entries that will allow apache2 to enter the "/home" directory:

# cd /etc/apache2
# joe apache2.conf

< Directory /home/ >
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
< Directory >



Step 2: Edit the "000-default.conf" in the subdirectory "/etc/apache2/sites-available" and enter the following entries that will define the web pages directory, error pages, and access logs:

# cd /etc/apache2/sites-available
# joe 000-default.conf

< VirtualHost *:80 >
ServerName www.rasul.ph
ServerAdmin webmaster@rasul.ph
DocumentRoot /home/rasul/www/html
ErrorLog /home/rasul/www/error/error.log
CustomLog /home/rasul/www/log/access.log combined
< VirtualHost >



Step 3: Create the virtual host "username" and the corresponing directories, subdirectories, and files:

# adduser rasul
# mkdir /home/rasul/www
# mkdir /home/rasul/www/html
# mkdir /home/rasul/www/error
# mkdir /home/rasul/www/log
# touch /home/rasul/www/error/error.log
# touch /home/rasul/www/log/access.log


Step 4: Change group of the virtual hosts into "www-data". Ubuntu's Apache uses the username "www-data" and group "www-data".

# cd /home
# chown -R rasul.www-data rasul

Listing the directory should display as:

# ls -l
drwxr-xr-x 2 rasul www-data 4096 Jul 29 10:37 rasul




Step 5: Restart the Apache webserver to load the virtual hosts settings

# systemctl restart apache2

Step 6: Check to see by placing a sample webpage in the html directory of the virtual hosts and viewing it in your browser.

Saturday, July 25, 2020

Installing Apache Webserver with PHP scripting, and MySQL and PostgreSQL PHP connection driver under Ubuntu 18.04 LTS (Bionic Beaver)

Clement L. Rasul 1.  Download and install the Apache webserver software

# apt-get install apache2

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install apache2


2.  Download and install the PHP scripting language

# apt-get install php

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php libapache2-mod-php

3.  Download and install the MySQL database server PHP connection driver.

# apt-get install php-mysql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-mysql


4.  Download and install the PostgreSQL database server PHP connection driver as follows:

# apt-get install php-pgsql

If there are errors displayed during the installation, issue the update command before repeating the installation command.

# apt-get update --fix-missing
# apt-get install php-pgsql



5.  By default, the Apache webserver should be running after installation.  You should restart the Apache webserver in order to load the PHP, MySQL and PostgreSQL support.  Issue the command:

# systemctl restart apache2.service


6. To check if the Apache process is running, issue the command

# ps ax | grep apache2

This should produce a display similar to this if it is running:

23263 ?        Ss     0:00 /usr/sbin/apache2 -k start
23265 ?        S      0:00 /usr/sbin/apache2 -k start
23266 ?        S      0:00 /usr/sbin/apache2 -k start
23267 ?        S      0:00 /usr/sbin/apache2 -k start
23268 ?        S      0:00 /usr/sbin/apache2 -k start
23269 ?        S      0:00 /usr/sbin/apache2 -k start
25621 pts/0    S+     0:00 grep --color=auto apache2

If the apache2 process is not running, the display should just produce this entry:

6433 pts/0    S+     0:00 grep --color=auto apache2

7.  To test if the Apache webserver is running using an Internet browser, type the address where the webserver is running.  On the local machine, the address is 127.0.0.1 (also known as the loopback address).  This should display a page similar to this.


This is the default page of the Apache web server.


8.  To change the default page of the Apache webserver, remove the "index.html" file in the subdirectory "/var/www/html" and create a sample HTML file called "index.html" as follows:

# cd /var/www/html
# rm index.html
# vi index.html


< html >
< head >
< title > My First HTML Page < /title >
< /head >
< body >
Hello World!< /body >
< /html >

My assumption here is, you are familiar with using the vi text editor in Linux.  You may use your own preferred text editor to create the HTML file.  After refreshing your browser, the display should look like this.




9.  To test if the Apache webserver has PHP scripting support, create the following "test.php" file and place it in the subdirectory "/var/www/html".

# cd /var/www/html
# vi test.php

< ?php 
phpinfo();
? >

Type in the address bar of the browser "http://127.0.0.1/test.php", the browser should display a page similar to this.




10.  To know if the MySQL database PHP connection driver is installed, you should see and entry in the PHP test page similar to this:




11.  Likewise, to know if the PostgreSQL database PHP connection driver is installed, you should see an entry in the PHP test page similar to this:



12.  Should there be a need to uninstall the Apache webserver, shut down the running apache2 process first before uninstalling.

# systemctl stop apache2.service
# apt-get remove apache2



Friday, February 22, 2019

Creating Self-Signed Certificates for the Apache Web Server

Use the OpenSSL package.  Issue the following commands in the Linux terminal:

# openssl req -new > ca.csr

# openssl rsa -in privkey.pem -out ca.key

# openssl x509 -in ca.csr -out ca.crt -req -signkey ca.key -days 720

These commands creates the SSL certificates good for 720 days with the files ca.csr, ca.crt, and ca.key.  Copy these files to the SSL directory of your Apache web server.  In my Linux system, this is located in /etc/apache2/ssl

# cp ca.* /etc/apache2/ssl

Then, restart the Apache webserver for the new certificates to take effect.

# service apache2 restart

Wednesday, April 15, 2009

Installing Apache on Ubuntu

Ubuntu is one of the Linux distributions that grew out of the Debian Linux distribution. Unlike the RedHat-based distributions (RedHat, Fedora, CentOS and Mandrake), installation under Ubuntu does not use the "yum" command. Instead it uses the "apt-get" command. Variation also exists between the package names under Ubuntu and those of the RedHat-based distributions.

Installing the Apache web server under Ubuntu uses the following command:

#apt-get install apache2

As you may have noticed, the package name for the Apache web server is "apache2" instead of "httpd" under RedHat-based distributions.

You can also install the accompanying PHP scripting engine by issuing the following commands:

#apt-get install php5
#apt-get install libapache2-mod-php5

The home directory of the Apache web server is located in "/var/www" directory instead of "/var/www/html" directory under RedHat-based distributions.

I've tested the above procedure under Ubuntu 8.10.

Tuesday, February 17, 2009

PHP Support in the Apache Webserver

The following are my notes on PHP support in the Apache Webserver. The Linux box I am using runs on CentOS 5.0 operating system. The following steps assumes that the Linux box is connected to the Internet:


# yum install httpd
# yum install php
# yum install php-mysql
# yum install php-pgsql
# yum install php-mbstring
# yum install php-xmlrpc
# yum install php-gd


Among others, the above commands installs Apache and PHP with support for the MySQL and PostgreSQL databases.

Virtual Hosting in Apache

Virtual hosting is the ability of webserver to host more than one domain. The Apache webserver supports virtual hosting. Here are the steps on how to do it.

Considerations:
The web pages will be stored in the home folder of the user such as "/home/bse/www/html". Normally, Apache locates the web pages under the directory "/var/www/html".

I am using CentOS 5.0 (http://www.centos.org) as my operating system of choice.

This setup assumes that you are connected to the Internet.

Here are the steps...

Step 1:
Download the Apache software as follows:


#yum install httpd


Step 2:
Create the virtual file "virtual.conf" under the directory "/etc/httpd/conf.d". The "virtual.conf" file should read as follows:



ServerName idep01.bse.deped.gov.ph

< Directory /home >
Order Deny,Allow
Allow from all
DirectoryIndex index.html index.htm index.php index.phtml
< /Directory >

NameVirtualHost *:80

< VirtualHost *:80 >
ServerName www.bse.deped.gov.ph
DocumentRoot /home/bse/www/html
ErrorLog /home/bse/www/logs/error_log
TransferLog /home/bse/www/logs/access_log
< /VirtualHost >



Step 3:
Create the user and folders for the web pages as follows:


# adduser bse
# mkdir /home/bse/www
# mkdir /home/bse/www/html
# mkdir /home/bse/www/logs
# touch /home/bse/www/logs/error_log
# touch /home/bse/www/logs/access_log


Step 4:
Change the ownership and permissions of the "bse" user and its home folders. I assume that Apache is owned by the user "apache" and group "apache". Here are the commands:


# chown -R bse.apache /home/bse
# chmod -R 755 /home/bse


Step 5:
Copy a test page with the filename "index.html" to the directory "/home/bse/www/html".

Step 6:
Start the Apache web server as follows:


# /etc/rc.d/init.d/httpd start


Verify if you got it right by pointing your browser to the web address of the Apache webserver.