How To Install Magento 2 On Ubuntu 18.04 | How to install Magento 2 with Sample Data

apt-get update

#Install the server.
apt-get install apache2

#Install PHP 7.2 and the required extensions:
add-apt-repository ppa:ondrej/php
apt-get update
apt-get install php7.2 libapache2-mod-php7.2 php7.2-common php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap php-xdebug php-imagick
php -v
sudo subl /etc/php/7.2/apache2/php.ini

Update the following options there..
memory_limit = 2G
max_execution_time = 3600
max_input_time = 1800
upload_max_filesize = 10M
zlib.output_compression = On

Install MySQL 5.7
sudo apt install -y mysql-server mysql-client

Start MySQL:
sudo service mysql start

#Change/Set the root password –

mysql -u root -p
sudo mysql -u root
DROP USER 'root'@'localhost';
CREATE USER 'root'@'%' IDENTIFIED BY '01801'
flush privileges

#To increase the value find “max_allowed_packet” and increase as much you need.
sudo subl /etc/mysql/mysql.cnf

#Install Composer:
sudo apt install composer

#Test the installation:
composer --version

# To add user to www-data group, open terminal by pressing ctrl + T. Use the following code.

sudo usermod -a -G www-data mahmud

# check the user called mahmud and it’s group.
id mahmud
groups mahmud

#To Own the /var/www/html/, use the following code.
sudo chown mahmud:www-data -R /var/www/html
sudo subl /etc/apache2/apache2.conf

#Find the line “AllowOverride None” and replace with “AllowOverride All”

#Open termianl and type..
sudo a2enmod rewrite
sudo service apache2 restart

#Install phpMyAdmin
#Download phpMyAdmin and extract the file on /var/www/html/

#Get magento framework file and extract it on /var/www/html/mage2

#create mage2 database from phpmyadmin and connect and install magento 2..

# Always use the correct way to do setup:upgrade–
sudo -u www-data php bin/magento setup:upgrade
php bin/magento setup:static-content:deploy -f