Monday, August 3, 2020

How To install LAMP Server With Virtual Hosts On Ubuntu 20.04 LTS

Video Tutorial -

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

LAMP is a well-known abbreviation for Linux, Apache, MySQL, and PHP.

Apache Virtual Hosts allow you to host more than one website on a single server or machine.

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Testing Environment: Ubuntu 20.04 LTS        Hostname - www.yourdomain.com         ip Address - 192.168.1.10

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

apt update ; apt install build-essential net-tools curl git software-properties-common neofetch  apache2 apache2-utils libapache2-mod-php mysql-server mysql-client php-fpm php-cli php-curl php-mysql php-curl php-gd php-mbstring php-pear php-cgi php-imap php-intl php-snmp php-tidy php-zip php-mbstring php-json php-pgsql php-opcache php-mysql php-ldap php-bz2 php-xml phpmyadmin -y


mysql_secure_installation

systemctl enable apache2 php7.4-fpm ; systemctl start apache2 mysql php7.4-fpm

a2enconf php7.4-cgi ; a2enmod rewrite headers


sed -i "s/;date.timezone.*/date.timezone = Asia\/\Kolkata/" /etc/php/*/apache2/php.ini

echo ServerName 127.0.0.1 >> /etc/apache2/apache2.conf


nano /etc/apache2/conf-enabled/security.conf

ServerTokens Prod

nano /etc/apache2/mods-enabled/dir.conf

index.php


nano /etc/apache2/sites-enabled/000-default.conf

<VirtualHost *:80>

    ServerName yourdomain.com

    ServerAlias www.yourdomain.com

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/html/

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


apachectl configtest


echo '<?php phpinfo(); ?>' > /var/www/html/info.php ; echo "This is Test Page on www.yourdomain.com" > /var/www/html/index.html

chown -R $USER:$USER /var/www/html/ ; chmod -R 755 /var/www/html/


mysql -u root -p

create user Test@'localhost' identified by 'StrongPassword';

grant all privileges on *.* to Test@'localhost';

flush privileges;

exit


systemctl restart apache2 php7.4-fpm mysql

http://www.yourdomain.com | http://www.yourdomain.com/info.php  | http://www.yourdomain.com/phpmyadmin/

______________________________________________________________________________________________________________

Set Up Apache VirtualHosts -

______________________________________________________________________________________________________________

mkdir -p /var/www/virtualhost.com/public_html

echo '<?php phpinfo(); ?>' > /var/www/virtualhost.com/public_html/info.php ; echo "This is Test Page on www.virtualhost.com" > /var/www/virtualhost.com/public_html/index.html


chown -R $USER:$USER /var/www/virtualhost.com/public_html ; chmod -R 755 /var/www

nano /etc/apache2/sites-available/virtualhost.com.conf

<VirtualHost *:80>

    ServerAdmin admin@virtualhost.com

    ServerName virtualhost.com

    ServerAlias www.virtualhost.com

    DocumentRoot /var/www/virtualhost.com/public_html

    ErrorLog ${APACHE_LOG_DIR}/error.log

    CustomLog ${APACHE_LOG_DIR}/access.log combined

</VirtualHost>


apachectl configtest ; a2ensite virtualhost.com.conf

echo "192.168.1.10 www.virtualhost.com www" >> /etc/hosts

systemctl restart apache2 mysql php7.4-fpm

http://www.virtualhost.com | http://www.virtualhost.com/info.php


Optional Step -  Download Free Website Templates & Test -

https://freewebsitetemplates.com/templates/page-2

rm -rf /var/www/virtualhost.com/public_html/index.html

rm -rf /var/www/virtualhost.com/public_html/info.php

cp -r /home/ubuntu/Downloads/ecologicalwebsitetemplate/* /var/www/virtualhost.com/public_html/

systemctl restart apache2 mysql php7.4-fpm


http://www.virtualhost.com

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment