::: For Apache2 :::
Create Virtual Host
Login with sudo command in the terminal by typing
sudo -s
Create a virtual host file.
sudo touch /etc/apache2/sites-available/<site-name>.conf
sudo nano /etc/apache2/sites-available/<site-name>.conf
Paste Below Code into it.
Change php version and domain name as per the requirement + verify the directories.
<VirtualHost *:80>
ServerAdmin admin@<domain-name>
ServerName domain-name
ServerAlias www.domain-name
ServerAdmin webmaster@domain-name
DocumentRoot /var/www/html/domain-name/pub
<Directory /var/www/html/domain-name>
Options -Indexes +FollowSymLinks
AllowOverride All
</Directory>
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php<php-version>-fpm.sock|fcgi://localhost"
</FilesMatch>
</VirtualHost>
Hit below commands over the terminal
sudo a2ensite <site-name>.conf
sudo apachectl configtest
sudo systemctl restart apache2
Make an entry of the domain name.
nano /etc/hosts
Paste this right at the bottom
127.0.0.1 <site-name>
To Disable Site Configuration
sudo a2dissite <site-name>.conf
sudo systemctl restart apache2
:::: ::::
::: For Nginx :::
Create Virtual Host
Login with sudo command in the terminal by typing
sudo -s
Create a virtual host file.
sudo touch /etc/nginx/sites-available/<site-name>.conf
sudo nano /etc/nginx/sites-available/<site-name>.conf
Paste Below Code into it.
upstream fastcgi_backend {
server unix:/run/php/php7.4-fpm.sock;
}
server {
listen 80;
server_name <site-name> www.<site-name>;
set $MAGE_ROOT /var/www/html/<site-name>;
include /var/www/html/<site-name>/nginx.conf.sample;
}
Fire below command on terminal and restart nginx. It’ll be working then.
sudo ln -s /etc/nginx/sites-available/<site-name>.conf /etc/nginx/sites-enabled/
::: :::
::: Setup Permissions :::
Always Remember to look at the directory first and then fire below commands.
cd <magento-root-dir>
chmod -R uog-rwxs .
chown -R <file-owner> .
chgrp -R <apache-running-user-group> .
find . -type f -exec chmod 644 {} +
find . -type d -exec chmod 755 {} +
find var/ pub/static pub/media app/etc generated/ -type f -exec chmod g+w {} +
find var/ pub/static pub/media app/etc generated/ -type d -exec chmod g+ws {} +
chmod 640 app/etc/env.php
chmod -R g+s .
<apache-running-user-group>
will be most probably www-data
To see by which user and group apache2 is running, type below command on the terminal.
apachectl -S
If XDebug is not working, one may try changing below configuration
nano /etc/php/7.4/fpm/pool.d/www.conf
& Update below configuration as per above screenshot you achieved.
user = <file-owner>
group = www-data
listen.owner = <file-owner>
listen.group = www-data
::: :::