Configure VPS with details & LAMP

  • Essentials:
    Initial setup of Ubuntu 22.04
  • Fail2ban:
    sudo apt-get install fail2ban
  • Disable journal logs:
    Sometimes, if your VPS has problems, journal logs could occupy whole disk space (95%+).
    se.com/how-to-clear-journalctl
    journalctl --vacuum-size=100M
    nano /etc/systemd/journald.conf –> SystemMaxUse=100M
    – To clear existing cache: (sudo find /var/log/journal -name "*.journal" | xargs sudo rm) && (sudo systemctl restart systemd-journald)
  • Change default SSH port:
    It’s not requirement, but good thing to change from default 22 to your desired, i.e. 12345:
    sudo ufw allow 12345/tcp
    nano /etc/ssh/sshd_config and change Port=22 to12345.
    service ssh restart (or service sshd restart
    – in rare cases, you might also need to amend: /etc/apache/sites-enabled && /etc/apache2/ports.conf
  • Docker:
    install docker (only if you know docker and want to use it)
  • LAMP (APACHE & MYSQL & PHP):
    Now, instead of the combined articles (i.e. install-lamp-1 or install-lamp-2 ) I advise more specific oriented articles:
    – install apache
    install mysql
    – install php: 1) Install phpbrew  2) try  blog/docker-php-8-zts-apache-swoole-parallel & gmp install 3) might need to add AddType application/x-httpd-php .php in /etc/apache2/mods-available/php.load
  • LetsEncrypt free SSL:
    for apache
    for-nginx 
    – (if different ports needed: here or here)
  • Firewall:
    firewall-on-ubuntu
    configure-firewall-and-change-ssh-port.md
  • WordPress (with mysql):
    ubuntu tutorial
    do.com/wordpress-on-ubuntu
  • Simple Disk usage:
    sudo apt install ncdu and anytime just run ncdu
  • Set correct permissions for multiple users
    – to rewrite privileges after uploading files automatically: 
    */10 * * * * sudo chown -R www-data:www-data /var/www
  • Increate timeout for SSH client (instead of default 10):
    nano /etc/ssh/sshd_config –>set  ClientAliveInterval 60   and ClientAliveCountMax 5 

== others ==

  • [PHP]:
    – Install Redis Cache
    – Install MBstring : sudo apt-get install php-mbstring php8.1-mbstring php-gettext libapache2-mod-php8.1
  • Add user through SSh
  • Download & unpack file: 
    wget --no-check-certificate --content-disposition https://codeload.github.com/USER/REPONAME/zip/refs/heads/master -O temp.zip && unzip -o temp.zip -d /var/www/path/folder
  • Find file:
    find . -type f -name "*John*"
  • Install & Configure mail: article1 | article2
  • Auto- Restart stopped-service : Github repo 
  •  
  • Restrict port to specific IP:
    sudo iptables -A INPUT -p tcp -s YOURRRRRRR_IPPPPPPPPPPP -j ACCEPT
    sudo ufw allow from 123.123.123.123 to any port 22 proto tcp
  • Monitor files/folders changes : 
    inotify-hookable -w path_to_plugin -c "COMMAND_TO_EXECUTE" (i.e. "docker container restart CONTAINER_NAME") 

### MYSQL ###

  • Add/Create user:
    CREATE USER 'myuser1'@'192.168.1.123' IDENTIFIED BY 'password123';
    GRANT ALL PRIVILEGES ON dbnamee.* TO 'myuser1'@'192.168.1.123';
    FLUSH Privileges;
  • reset root pass;
  • user password change : 
    ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxxxxx';
  • disable mysql-logs : se.com/delete-mysql-bin-files & se.com/disable-mysql-logging
    /etc/mysql/my.cnf - >
    [mysqld]
    max_allowed_packet = 512M
    skip-log-bin
    binlog_expire_logs_seconds=1600
    In mysql: 
    SHOW VARIABLES LIKE 'max_allowed_packet';
    SET @@global.max_allowed_packet = 16777215;
    SHOW VARIABLES LIKE 'max_allowed_packet';

Leave a Comment

Your email address will not be published. Required fields are marked *

WordPress › Error

There has been a critical error on this website.

Learn more about troubleshooting WordPress.