Created
October 13, 2020 10:49
-
-
Save amanjuman/ebb67f1a9d2112aafad0721b3909819e to your computer and use it in GitHub Desktop.
Comple Installation OpenCart with Nginx and Let's Encrypt on Ubuntu 18.04
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sudo add-apt-repository ppa:ondrej/php -y | |
sudo add-apt-repository ppa:certbot/certbot -y | |
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get autoremove -y | |
sudo apt-get install nginx python3-certbot-nginx mariadb-server php7.4-common php7.4-cli php7.4-fpm php7.4-opcache php7.4-gd php7.4-mysql php7.4-curl php7.4-intl php7.4-xsl php7.4-mbstring php7.4-zip php7.4-bcmath php7.4-soap unzip git -y | |
sudo update-alternatives --set php /usr/bin/php7.4 | |
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/max_execution_time = 30/max_execution_time = 120/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/post_max_size = 8M/post_max_size = 1024M/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 512M/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/max_input_time = 60/max_input_time = 120/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/max_input_vars = 1000/max_input_vars = 5000/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/zlib.output_compression = Off/zlib.output_compression = On/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/;opcache.enable=1/opcache.enable=1/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/;opcache.save_comments=1/opcache.save_comments=1/g' /etc/php/7.4/fpm/php.ini | |
sudo sed -i 's/;date.timezone.*/date.timezone = UTC/' /etc/php/7.4/fpm/php.ini | |
sudo mysql -u root -p | |
SET GLOBAL innodb_fast_shutdown = 0; | |
UPDATE mysql.user SET plugin = 'mysql_native_password' WHERE User = 'root'; | |
FLUSH PRIVILEGES; | |
CREATE DATABASE opencartdb; | |
CREATE USER 'opencartuser'@'%' IDENTIFIED BY 'Password'; | |
GRANT ALL ON opencartdb.* TO 'opencartuser'@'%' IDENTIFIED BY 'Password'; | |
FLUSH PRIVILEGES; | |
EXIT; | |
cd /var/www/ | |
sudo wget https://github.com/opencart/opencart/releases/download/3.0.3.6/opencart-3.0.3.6.zip | |
sudo unzip opencart-3.0.3.6.zip -d opencart | |
sudo mkdir -p /var/www/example.com | |
sudo mv /var/www/opencart/upload/* /var/www/example.com/ | |
sudo cp /var/www/example.com/config-dist.php /var/www/example.com/config.php | |
sudo cp /var/www/example.com/admin/config-dist.php /var/www/example.com/admin/config.php | |
sudo chown -R www-data:www-data /var/www/example.com/ | |
sudo chmod -R 775 /var/www/example.com/ | |
sudo certbot --nginx -d example.com -d www.example.com --register-unsafely-without-email | |
sudo nano /etc/nginx/sites-available/example.com.conf | |
server | |
{ | |
# Listen | |
listen 80; | |
listen [::]:80; | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
# Directory & Server Naming | |
root /var/www/example.com; | |
index index.php index.html; | |
server_name example.com www.example.com; | |
http2_push_preload on; | |
large_client_header_buffers 4 16k; | |
# HTTP to HTTPS redirection | |
if ($scheme != "https") | |
{ | |
return 301 https://$host$request_uri; | |
} | |
# SSL | |
ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; | |
ssl_trusted_certificate /etc/letsencrypt/live/example.com/fullchain.pem; | |
# Disable Hidden FIle Access Except Lets Encrypt Verification | |
location ~ /\.well-known | |
{ | |
allow all; | |
} | |
# Nginx Logging | |
access_log /var/log/nginx/example.com-access.log; | |
error_log /var/log/nginx/example.com-error.log warn; | |
# Max Upload Size | |
client_max_body_size 100M; | |
# Permalink Support | |
location / { | |
try_files $uri $uri/ /index.php?$args; | |
} | |
# PHP Upsteam | |
location ~ \.php$ | |
{ | |
include snippets/fastcgi-php.conf; | |
## For PHP 7.2 | |
#fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; | |
## For PHP 7.4 | |
fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# 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; | |
} | |
# OpenCart Cache | |
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ | |
{ | |
expires 7d; | |
add_header Cache-Control "public, no-transform"; | |
log_not_found off; | |
access_log off; | |
} | |
} | |
sudo ln -s /etc/nginx/sites-available/example.com.conf /etc/nginx/sites-enabled/ | |
sudo nano /etc/nginx/sites-available/default | |
server | |
{ | |
listen 80 default_server; | |
listen [::]:80 default_server; | |
#listen 443 ssl http2 default_server; | |
#listen [::]:443 ssl http2 default_server; | |
server_name _; | |
return 444; | |
} | |
sudo service nginx restart | |
sudo certbot renew --dry-run | |
sudo rm -rf /var/www/example.com/install/ | |
sudo mv /var/www/example.com/system/storage/ /var/www/storage/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment