# Apache

# Host Multiple Websites On One Apache Server On Ubuntu

#### <span id="bkmrk-1.-install-apache-we-0">**1. Install Apache Web Server**</span>

If you don’t have an Apache server installed refer to post: [**How To Install Apache On Ubuntu 20.04**](https://www.magetop.com/blog/install-apache-on-ubuntu-20-04/).

#### <span id="bkmrk-2.-create-the-direct-0">**2. Create the Directory Structure**</span>

First, create a document root directory for both websites by commands:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-mkdir-%2Fvar%2Fww"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-mkdir-%2Fvar%2Fww-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo mkdir /var/www/html/example.com`</div></div></td></tr></tbody></table>

</div></div></div><div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-mkdir-%2Fvar%2Fww-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-mkdir-%2Fvar%2Fww-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo mkdir /var/www/html/example1.com`</div></div></td></tr></tbody></table>

</div></div></div>Next, create an **index.html** page to be track the results.

Create an **index.html** page for site `example.com`.

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-nano-%2Fvar%2Fwww"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-nano-%2Fvar%2Fwww-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo nano /var/www/html/example.com/index.html`</div></div></td></tr></tbody></table>

</div></div></div>Copy and paste below content to file.

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-2-3-4-5-6-7-8-%3Chtm"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-2-3-4-5-6-7-8-%3Chtm-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`<html>`</div><div class="line number2 index1 alt1">`<head>`</div><div class="line number3 index2 alt2">`    ``<title>example.com</title>`</div><div class="line number4 index3 alt1">`</head>`</div><div class="line number5 index4 alt2">`<body>`</div><div class="line number6 index5 alt1">`    ``<h1>Welcome to example.com website</h1>`</div><div class="line number7 index6 alt2">`</body>`</div><div class="line number8 index7 alt1">`</html>`</div></div></td></tr></tbody></table>

</div></div></div>Next, create an **index.html** page for site `example1.com`.

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-nano-%2Fvar%2Fwww-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-nano-%2Fvar%2Fwww-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo nano /var/www/html/example1.com/index.html`</div></div></td></tr></tbody></table>

</div></div></div>Copy and paste below content to file.

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-2-3-4-5-6-7-8-%3Chtm-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-2-3-4-5-6-7-8-%3Chtm-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`<html>`</div><div class="line number2 index1 alt1">`<head>`</div><div class="line number3 index2 alt2">`    ``<title>example1.com</title>`</div><div class="line number4 index3 alt1">`</head>`</div><div class="line number5 index4 alt2">`<body>`</div><div class="line number6 index5 alt1">`    ``<h1>Welcome to example1.com website</h1>`</div><div class="line number7 index6 alt2">`</body>`</div><div class="line number8 index7 alt1">`</html>`</div></div></td></tr></tbody></table>

</div></div></div>#### <span id="bkmrk-3.-grant-permissions-0">**3. Grant Permissions**</span>

Grant permissions of `example.com` and `example1.com` directory by commands:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-chown--r-www-data%3A"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-chown--r-www-data%3A-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`chown -R www-data:www-data /var/www/html/example.com`</div></div></td></tr></tbody></table>

</div></div></div><div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-chown--r-www-data%3A-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-chown--r-www-data%3A-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`chown -R www-data:www-data /var/www/html/example1.com`</div></div></td></tr></tbody></table>

</div></div></div>#### <span id="bkmrk-4.-create-a-virtual--0">**4. Create a Virtual Host Configuration File**</span>

Create an Apache virtual host configuration file for `example.com`:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-nano-%2Fetc%2Fapa"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-nano-%2Fetc%2Fapa-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo nano /etc/apache2/sites-available/example.com.conf`</div></div></td></tr></tbody></table>

</div></div></div>Add the following lines:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-2-3-4-5-6-7-8-%3Cvir"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-2-3-4-5-6-7-8-%3Cvir-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`<VirtualHost *:80>`</div><div class="line number2 index1 alt1">`    ``ServerAdmin webmaster@localhost`</div><div class="line number3 index2 alt2">`    ``ServerName example.com`</div><div class="line number4 index3 alt1">`    ``ServerAlias www.example.com`</div><div class="line number5 index4 alt2">`    ``DocumentRoot /var/www/html/example.com`</div><div class="line number6 index5 alt1">`    ``ErrorLog ${APACHE_LOG_DIR}/error.log`</div><div class="line number7 index6 alt2">`    ``CustomLog ${APACHE_LOG_DIR}/access.log combined`</div><div class="line number8 index7 alt1">`</VirtualHost>`</div></div></td></tr></tbody></table>

</div></div></div>Create an Apache virtual host configuration file for `example1.com`:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-nano-%2Fetc%2Fapa-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-nano-%2Fetc%2Fapa-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo nano /etc/apache2/sites-available/example1.com.conf`</div></div></td></tr></tbody></table>

</div></div></div>And add the following lines:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-2-3-4-5-6-7-8-%3Cvir-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-2-3-4-5-6-7-8-%3Cvir-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`<VirtualHost *:80>`</div><div class="line number2 index1 alt1">`    ``ServerAdmin webmaster@localhost`</div><div class="line number3 index2 alt2">`    ``ServerName example1.com`</div><div class="line number4 index3 alt1">`    ``ServerAlias www.example1.com`</div><div class="line number5 index4 alt2">`    ``DocumentRoot /var/www/html/example1.com`</div><div class="line number6 index5 alt1">`    ``ErrorLog ${APACHE_LOG_DIR}/error.log`</div><div class="line number7 index6 alt2">`    ``CustomLog ${APACHE_LOG_DIR}/access.log combined`</div><div class="line number8 index7 alt1">`</VirtualHost>`</div></div></td></tr></tbody></table>

</div></div></div>Then, enable the virtual host configuration file with the following commands:

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-a2ensite-exam"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-a2ensite-exam-1"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo a2ensite example.com.conf`</div></div></td></tr></tbody></table>

</div></div></div><div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-a2ensite-exam-0"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-a2ensite-exam-2"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo a2ensite example1.com.conf`</div></div></td></tr></tbody></table>

</div></div></div>Restart Apache for the changes to take effect.

<div class="wp-block-syntaxhighlighter-code " id="bkmrk-1-sudo-systemctl-res"><div><div class="syntaxhighlighter  plain" id="bkmrk-1-sudo-systemctl-res-0"><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2">`sudo systemctl restart apache2`</div></div></td></tr></tbody></table>

</div></div></div>#### <span id="bkmrk-5.-test-your-results-0">**5. Test your Results**</span>

Visit the website with the path `http://example.com` you will see results like this:

<figure class="wp-block-image size-full is-resized" id="bkmrk-">![Result of example](https://i0.wp.com/www.magetop.com/blog/wp-content/uploads/2021/07/Result-of-example.jpg?resize=800%2C36&ssl=1)</figure>And visit the website with the path `http://example1.com` you will see results like this:

<figure class="wp-block-image size-full" id="bkmrk--0">![Result of example1](https://i0.wp.com/www.magetop.com/blog/wp-content/uploads/2021/07/Result-of-example1.jpg?resize=800%2C36&ssl=1)</figure>Thank you for reading!

</body></html>

# phpMyAdmin

# plugin\_interface.lib.php error

sudo vim /usr/share/phpmyadmin/libraries/plugin\_interface.lib.php

if ($options != null &amp;&amp; count($options) &gt; 0) {

if ($options != null &amp;&amp; count((array)$options) &gt; 0) {

# Secure PhpMyAdmin Login Interface

1\. Change Default PhpMyAdmin Login URL

2\. Enable HTTPS on PhpMyAdmin

3\. Password Protect on PhpMyAdmin

4\. Disable root Login to PhpMyAdmin

\# vim /opt/lampp/etc/extra/httpd-xampp.conf

Alias /db "/opt/lampp/phpmyadmin"

/opt/lampp/lampp restart

[http://localhost/db/index.php](http://localhost/db/index.php)

vim /etc/php/7.2/cli/php.ini -&gt; for database upload limit

vim /opt/lampp/phpmyadmin/config.inc.php -&gt; for set root password

vim /opt/lampp/etc/extra/httpd-ssl.conf -&gt; for ssl entry

vim /opt/lampp/etc/original/httpd.conf -&gt; for apache configure

# error phpmyadmin

sudo vim /usr/share/phpmyadmin/libraries/sql.lib.php

 || (count($analyzed\_sql\_results\[‘select\_expr’\] == 1)

|| (count($analyzed\_sql\_results\[‘select\_expr’\]) == 1

# root access denied phpMyAdmin

sudo nano /opt/lampp/etc/my.cnf

Skip-grant-tables

# How to increase phpMyAdmin upload file size

**Step - 1: open php.ini of the appropriate PHP version(s).**

For PHP v5.0

sudo vim /etc/php5/apache2/php.ini

For PHP v7.2

sudo vim /etc/php/7.2/apache2/php.ini

**Step - 2: Now need to increase below parameters in the php.ini file.**

memory\_limit = 1500M

post\_max\_size = 1500M

upload\_max\_filesize = 1500M

**Step - 3: Now you need to restart your apache server to effect changes.**

sudo service apache2 restart

# increase import database size

# nano /etc/php/7.2/apache2/php.ini

 memorylimit 128M

postmaxsize 12M

**uploadmaxfilesize 10M**

# Downgrade PHP8.1 to PHP8.0 or PHP7.4 on Ubuntu 22.04

Ubuntu 22.04 comes with `PHP 8.1`. This article describes how to change this and install and set as default the version `8.0` or `7.4`.

# Install PHP Version

Install the required dependencies.

```
sudo apt install software-properties-common ca-certificates lsb-release apt-transport-https
```

<div class="open_grepper_editor" id="bkmrk-" title="Edit & Save To Grepper">  
</div>Add the required PPA

```
LC_ALL=C.UTF-8 sudo add-apt-repository ppa:ondrej/php
```

<div class="open_grepper_editor" id="bkmrk--0" title="Edit & Save To Grepper">  
</div>Update the Apt package manager

```
sudo apt update
```

<div class="open_grepper_editor" id="bkmrk--1" title="Edit & Save To Grepper">  
</div>Install PHP 8.0 and all the PHP modules for Drupal 9.

```
sudo apt install php8.0<br></br>sudo apt install php8.0-mysql php8.0-mbstring php8.0-xml php8.0-curl php8.0-gd
```

<div class="open_grepper_editor" id="bkmrk--2" title="Edit & Save To Grepper">  
</div># Switch PHP versions and enable PHP 8.0

Set 8.09 as the default PHP version for CLI and Apache.

## **Command Line PHP**

```
sudo update-alternatives --config php
```

<div class="open_grepper_editor" id="bkmrk--3" title="Edit & Save To Grepper">  
</div>Select php8.0 from the list with the available options:

```
There are 2 choices for the alternative php (providing /usr/bin/php).Selection    Path             Priority   Status<br></br>------------------------------------------------------------<br></br>  0            /usr/bin/php8.1   81        auto mode<br></br>* 1            /usr/bin/php8.0   80        manual mode<br></br>  2            /usr/bin/php8.1   81        manual modePress <enter> to keep the current choice[*], or type selection number:
```

<div class="open_grepper_editor" id="bkmrk--4" title="Edit & Save To Grepper">  
</div>## **Apache PHP**

Disable PHP 8.1

```
sudo a2dismod php8.1<br></br>sudo systemctl restart apache2
```

<div class="open_grepper_editor" id="bkmrk--5" title="Edit & Save To Grepper">  
</div>Enable PHP 8.0

```
sudo a2enmod php8.0 <br></br>sudo systemctl restart apache2
```

<div class="open_grepper_editor" id="bkmrk--6" title="Edit & Save To Grepper">  
</div>## Verify PHP Version

```
php -vOutput<br></br>PHP 8.0.18 (cli) (built: May  1 2022 04:42:09) ( NTS )<br></br>Copyright (c) The PHP Group<br></br>Zend Engine v4.0.18, Copyright (c) Zend Technologies<br></br>    with Zend OPcache v8.0.18, Copyright (c), by Zend Technologies
```

<div class="open_grepper_editor" id="bkmrk--7" title="Edit & Save To Grepper">  
</div>For verifying the PHP version Apache uses, specify the configururation `.ini` file.

```
php -c /etc/php/apache2/php.ini -v
```