Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Last active April 10, 2021 19:44
Show Gist options
  • Save amanjuman/d546965f49c18028274b14bbfc56d2a9 to your computer and use it in GitHub Desktop.
Save amanjuman/d546965f49c18028274b14bbfc56d2a9 to your computer and use it in GitHub Desktop.
Complete Magento 2.3 LEMP on Ubuntu 18.04
## MariaDB Source
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8
sudo add-apt-repository "deb [arch=amd64,arm64,ppc64el] http://mariadb.mirror.liquidtelecom.com/repo/10.4/ubuntu $(lsb_release -cs) main"
## PHP, Nginx and Lets Encrypt Source
nginx=stable
add-apt-repository ppa:nginx/$nginx
sudo add-apt-repository ppa:ondrej/php -y
sudo add-apt-repository ppa:certbot/certbot -y
## Required Packet Install
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get autoremove -y
sudo apt install wget curl zip unzip nginx-full mariadb-server python3-certbot-nginx php7.2-fpm php7.2-common php7.2-curl php7.2-cli php7.2-mysql php7.2-gd php7.2-xml php7.2-json php7.2-intl php-pear php7.2-dev php7.2-common php7.2-mbstring php7.2-zip php7.2-soap php7.2-bcmath php7.2-opcache -y
sudo curl -sS https://getcomposer.org/installer | sudo php -- --install-dir=/usr/bin --filename=composer
## MySQl Optimization
sudo mysql -u root -p
SET GLOBAL max_allowed_packet=1073741824;
use mysql;
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root';
FLUSH PRIVILEGES;
EXIT;
## Adjust PHP Config
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=1/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/max_execution_time = 30/max_execution_time = 300/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/post_max_size = 8M/post_max_size = 1024M/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 512M/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/max_input_time = 60/max_input_time = 300/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/max_input_vars = 1000/max_input_vars = 5000/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/zlib.output_compression = Off/zlib.output_compression = On/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/;opcache.enable=1/opcache.enable=1/g' /etc/php/7.2/fpm/php.ini
sudo sed -i 's/;opcache.save_comments=1/opcache.save_comments=1/g' /etc/php/7.2/fpm/php.ini
sudo update-alternatives --set php /usr/bin/php7.2
sudo service php7.2-fpm restart
## Create Database
sudo mysql -u root -p
CREATE DATABASE magentodb;
CREATE USER 'magentouser'@'%' IDENTIFIED BY 'password';
GRANT ALL ON magentodb.* TO 'magentouser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
FLUSH PRIVILEGES;
## Download Magento
cd /var/www/
wget -q https://github.com/magento/magento2/archive/2.3.5.tar.gz && tar -xf 2.3.5.tar.gz && rm 2.3.5.tar.gz
mv magento2-*/ yourdomain.tld/
cd /var/www/yourdomain.tld/ && sudo composer install
## Configure Magento Permission
cd /var/www/yourdomain.tld/
find var generated vendor pub/static pub/media app/etc -type f -exec chmod g+w {} +
find var generated vendor pub/static pub/media app/etc -type d -exec chmod g+ws {} +
chown -R :www-data .
chmod u+x bin/magento
## Issue SSL
sudo certbot --nginx --agree-tos --register-unsafely-without-email -d yourdomain.tld -d www.yourdomain.tld
## Create Nginx Config
nano /etc/nginx/conf.d/yourdomain.tld.conf
upstream fastcgi_backend
{
server unix:/run/php/php7.2-fpm.sock;
}
server
{
listen 80;
listen [::]:80;
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name yourdomain.tld www.yourdomain.tld;
index index.php;
http2_push_preload on;
# HTTP to HTTPS redirection
if ($scheme != "https")
{
return 301 https://$host$request_uri;
}
# Max Upload Size
client_max_body_size 1024M;
ssl on;
ssl_certificate /etc/letsencrypt/live/yourdomain.tld/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/yourdomain.tld/privkey.pem;
ssl_trusted_certificate /etc/letsencrypt/live/yourdomain.tld/fullchain.pem;
set $MAGE_ROOT /var/www/yourdomain.tld;
set $MAGE_MODE production;
# fastcgi_split_path_info ^(.+?\.php)(/.*)$;
include /var/www/yourdomain.tld/nginx.conf.sample;
# Nginx Logging
access_log /var/log/nginx/yourdomain.tld-access.log;
error_log /var/log/nginx/yourdomain.tld-error.log warn;
# Disable Hidden FIle Access Except Lets Encrypt Verification
location ~ /\.well-known
{
allow all;
}
# Robot Text Logging Off
location = /robots.txt
{
allow all;
log_not_found off;
access_log off;
}
# Fav ICON Disable
location = /favicon.ico
{
log_not_found off;
access_log off;
}
}
sudo service nginx restart
## Configure Cron Job
export PATH=$PATH:/var/www/yourdomain.tld/bin/
cd /var/www/yourdomain.tld
sudo php /var/www/yourdomain.tld/bin/magento indexer:reindex
sudo php /var/www/yourdomain.tld/bin/magento cache:flush
sudo php /var/www/yourdomain.tld/bin/magento cron:install --force
sudo php /var/www/yourdomain.tld/bin/magento cron:install --non-optional
sudo crontab -l
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment