Last active
November 17, 2024 21:18
-
-
Save amanjuman/82a68a6de265a1ad806f40995cb90cd5 to your computer and use it in GitHub Desktop.
Install MailWizz on Ubuntu 22.04 using LEMP (Nginx)
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
## System Update and Install required softwares | |
sudo apt-get update && sudo apt-get -y upgrade && sudo apt-get autoremove -y && sudo add-apt-repository ppa:ondrej/php -y && add-apt-repository ppa:nginx/stable -y | |
sudo apt-get install curl cron nano nginx mariadb-server unzip zip python3-certbot-nginx php-pear php8.0-{curl,fpm,imap,gd,memcache,mbstring,mysql,pspell,sqlite3,tidy,xsl,xml,xmlrpc,zip} -y | |
sudo update-alternatives --set php /usr/bin/php8.0 | |
## Create DATABASE | |
sudo mysql_secure_installation | |
mysql -u root -p | |
Enter Password: | |
CREATE DATABASE wizzdb; | |
CREATE USER 'wizzuser'@'%' IDENTIFIED BY 'password'; | |
// MySQL 5.7 | |
GRANT ALL ON wizzdb.* TO 'wizzuser'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION; | |
// MariaDB 10 Up | |
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES, CREATE VIEW, EVENT, TRIGGER, SHOW VIEW, CREATE ROUTINE, ALTER ROUTINE, EXECUTE ON `wizzdb`.* TO 'wizzuser'@'%'; | |
FLUSH PRIVILEGES; | |
EXIT; | |
## Adjust PHP INI | |
sudo sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/max_execution_time = 30/max_execution_time = 120/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/memory_limit = 128M/memory_limit = 512M/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/post_max_size = 8M/post_max_size = 1024M/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 512M/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/max_input_time = 60/max_input_time = 120/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/max_input_vars = 1000/max_input_vars = 5000/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/short_open_tag = Off/short_open_tag = On/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/zlib.output_tldpression = Off/zlib.output_tldpression = On/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/;opcache.enable=1/opcache.enable=1/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/;opcache.save_tldments=1/opcache.save_tldments=1/g' /etc/php/8.0/fpm/php.ini | |
sudo sed -i 's/;date.timezone.*/date.timezone = UTC/' /etc/php/8.0/fpm/php.ini | |
## Get Lets Encrypt SSL | |
sudo certbot --nginx --agree-tos --register-unsafely-without-email --no-redirect -d subdomain.domain.tld | |
## Nginx Hardening (Optional) | |
sudo openssl dhparam -dsaparam -out /etc/ssl/dhparam.pem 2048 | |
sudo wget -q https://gist.githubusercontent.com/amanjuman/8ee772b38bc1a14cecf30546d0e53b73/raw/696eb10ae462d0603290a4f23120592b0de4f669/nginx.conf -O /etc/nginx/nginx.conf | |
sudo wget -q https://gist.githubusercontent.com/amanjuman/8ad9e374cb970a352d08b950e3d3dbef/raw/ddf53d463c80dfe76f7594b3bb3a58df63cd2aad/default -O /etc/nginx/sites-available/default | |
## Upload MailWizz and Extract | |
cd /tmp | |
sudo unzip mailwizz.zip | |
cd mailwizz-* && mv latest/ subdomain.domain.tld | |
mv subdomain.domain.tld /var/www/ | |
## Setup File and Folder Permission | |
sudo chmod -R 775 /var/www/subdomain.domain.tld/ | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/apps/common/config | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/apps/common/runtime | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/backend/assets/cache | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/customer/assets/cache | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/frontend/assets/cache | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/frontend/assets/files | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/frontend/assets/gallery | |
sudo chmod -R 777 /var/www/subdomain.domain.tld/apps/extensions | |
## Create MailWizz Nginx Config | |
sudo nano /etc/nginx/sites-available/subdomain.domain.tld.conf | |
# HTTP | |
server | |
{ | |
# Listen | |
listen 80; | |
listen [::]:80; | |
server_name subdomain.domain.tld; | |
# HTTP to HTTPS redirection | |
return 301 https://$server_name$request_uri; | |
} | |
#HTTPS | |
server | |
{ | |
# Listen | |
listen 443 ssl http2; | |
listen [::]:443 ssl http2; | |
# Directory & Server Naming | |
server_name subdomain.domain.tld; | |
root /var/www/subdomain.domain.tld; | |
index index.php index.html; | |
large_client_header_buffers 4 16k; | |
add_header X-Robots-Tag "noindex, nofollow, nosnippet, noarchive"; | |
# SSL | |
ssl_certificate /etc/letsencrypt/live/subdomain.domain.tld/fullchain.pem; | |
ssl_certificate_key /etc/letsencrypt/live/subdomain.domain.tld/privkey.pem; | |
ssl_trusted_certificate /etc/letsencrypt/live/subdomain.domain.tld/fullchain.pem; | |
# MailWizz URLs | |
location / | |
{ | |
location ~* ^.+\.(css|cur|eot|gif|ico|js|jpg|jpeg|mp3|mp4|ogg|ogv|otf|png|svg|swf|ttf|txt|wav|webm|woff|woff2)$ | |
{ | |
expires 30d; | |
add_header Cache-Control "public"; | |
add_header Access-Control-Allow-Origin *; | |
access_log off; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?api/.*$ /api/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?customer/.*$ /customer/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?backend/.*$ /backend/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(.*)$ /index.php; | |
} | |
index index.html index.htm index.php; | |
#try_files \$uri \$uri-404 /index.html index.php; | |
} | |
# PHP Upsteam | |
location ~ \.php$ | |
{ | |
include snippets/fastcgi-php.conf; | |
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Disable Hidden FIle Access Except Lets Encrypt Verification | |
location ~ /\.well-known | |
{ | |
allow all; | |
} | |
# Nginx Logging | |
access_log /var/log/nginx/subdomain.domain.tld-access.log; | |
error_log /var/log/nginx/subdomain.domain.tld-error.log warn; | |
# 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; | |
} | |
} | |
## Enable Nginx Config | |
sudo ln -s /etc/nginx/sites-available/subdomain.domain.tld.conf /etc/nginx/sites-enabled/ | |
## Create Tracking Domain Config | |
sudo nano /etc/nginx/conf.d/tracker.conf | |
server | |
{ | |
listen 80; | |
listen [::]:80; | |
# Directory & Server Naming | |
root /var/www/subdomain.domain.tld; | |
index index.php index.html; | |
server_name tracker.domain1.tld tracker.domain2.tld tracker.domain3.tld tracker.domain4.tld; | |
large_client_header_buffers 4 16k; | |
# MailWizz URLs | |
location / | |
{ | |
location ~* ^.+\.(css|cur|eot|gif|ico|js|jpg|jpeg|mp3|mp4|ogg|ogv|otf|png|svg|swf|ttf|txt|wav|webm|woff|woff2)$ | |
{ | |
expires 30d; | |
add_header Cache-Control "public"; | |
add_header Access-Control-Allow-Origin *; | |
access_log off; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?api/.*$ /api/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?customer/.*$ /customer/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(/)?backend/.*$ /backend/index.php; | |
} | |
if (!-e $request_filename) | |
{ | |
rewrite ^(.*)$ /index.php; | |
} | |
index index.html index.htm index.php; | |
#try_files \$uri \$uri-404 /index.html index.php; | |
} | |
# PHP Upsteam | |
location ~ \.php$ | |
{ | |
include snippets/fastcgi-php.conf; | |
## For PHP 8.0 | |
fastcgi_pass unix:/var/run/php/php8.0-fpm.sock; | |
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; | |
include fastcgi_params; | |
} | |
# Disable Hidden FIle Access Except Lets Encrypt Verification | |
location ~ /\.well-known | |
{ | |
allow all; | |
} | |
# Nginx Logging | |
access_log /var/log/nginx/tracker-access.log; | |
error_log /var/log/nginx/tracker-error.log warn; | |
# 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; | |
} | |
} | |
## Restart Nginx Service | |
sudo service nginx restart | |
# Copy the current cron into a new file | |
crontab -l > mwcron | |
# Add the new entries into the file | |
echo "* * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php send-campaigns >/dev/null 2>&1" >> mwcron | |
echo "* * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php queue >/dev/null 2>&1" >> mwcron | |
echo "*/2 * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php send-transactional-emails >/dev/null 2>&1" >> mwcron | |
echo "*/10 * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php bounce-handler >/dev/null 2>&1" >> mwcron | |
echo "*/20 * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php feedback-loop-handler >/dev/null 2>&1" >> mwcron | |
echo "*/3 * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php process-delivery-and-bounce-log >/dev/null 2>&1" >> mwcron | |
echo "0 * * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php hourly >/dev/null 2>&1" >> mwcron | |
echo "0 0 * * * /usr/bin/php -q /var/www/subdomain.domain.tld/apps/console/console.php daily >/dev/null 2>&1" >> mwcron | |
# Install the new cron | |
crontab mwcron | |
# Remove the crontab file since it has been installed and we don't use it anymore. | |
rm mwcron | |
## Remove Installation Folder | |
rm -rf /var/www/subdomain.domain.tld/install |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment