How to upgrade Ubuntu 16.04 to 18.04

It’s always best to stay up to date with technologies that you are using these days, due to lots of data getting hacked because they are not updated.  I had written a post earlier on how to upgrade Ubuntu 14.04 to 16.04, the process is the same. Make sure you have a good backup and your backup is tested to be sure data you are backup are good. If you have an option you can do an upgrade on a test server and work out any issues, that way when you do upgrade on the production system it goes smooth.

Check list before starting upgrade process

  • Data backed up and verified, which includes configs, PHP, Databases, etc…
  • Make sure your application supports newer packages versions
  • List of application/services so it can be tested after the upgrade
  • Direct access to the server, remote session will give you an error
  • Stopping application/services, not required but if dealing with a database it’s safer
  • Double-check storage space for an upgrade to download/install, you will need about 10GB

To get list of packages:

dpkg -l | grep php | tee packages.txt

Current supported Ubuntu version: https://wiki.ubuntu.com/Releases

Login to the server directly to do the upgrade, also before the upgrade make sure you are up to date and don’t have any issues with your server or resources.

You can run following commands to check for any updates:

sudo apt update
sudo apt upgrade
sudo apt dist-upgrade

To start the upgrade process

Run the following command it will go through a check of currently installed packages and give you the option to check and make sure you are ok to start to upgrade.  You should check and make sure your application support new version, so it does not break your application after the upgrade. You can press d to get detailed list, when done press q and it will bring you back to option to Continue or N to cancel. Press y and Enter when you ready

sudo do-release-upgrade

If you have apache installed you will get this prompt, which you can select option best fit your needs.

If you get option for sshd_config, select keep the local version currently installed

It will scan for any obsolete software and will give you option to remove it

Once that done, then it will ask to restart the server press y and Enter

Once the server comes back you should see Ubuntu 18.04.x

Total size was about 10.5 GB and it took about 2 hours, yours may be different based on server resources, an application installed, etc…

common issues and solutions:

Very common if you are using web server you might have issue with PHP:
To check PHP version: php -v

Re-enable PHP, if upgrade from older version:

sudo a2enmod php7.2
sudo service apache2 restart

To install full PHP packages you can run following command:

sudo apt install php php-cgi libapache2-mod-php php-common php-pear php-mbstring

If you run the upgrade via SSH session you will get this message, which is not recommended:

Find all PHP version installed on your system:

dpkg -l | grep ‘\(php\)’
or
php -i | grep ‘php.ini’
or
php -i | grep ‘Configuration File’

Find all mysql version installed:

dpkg -l | grep ‘(mysql)’

How to remove old PHP version:

Before running this command, make sure you have backup of your php.ini or any custom changes did. This command will wipe out everything
Sudo apt purge php5*



How to Uninstall Windows Defender from Windows Server 2016

Most servers have 3rd party Antivirus solution, so you don’t need or want Windows Defender on your server. Here is how to uninstall it, so you can free up the resources of your server. You can remove via server manager or using PowerShell.

You can run this command to check if Windows Defender is running:

sc query Windefend

SERVICE_NAME: Windefend
        TYPE : 10  WIN32_OWN_PROCESS
        STATE : 4  RUNNING
                                (STOPPABLE, NOT_PAUSABLE, ACCEPTS_SHUTDOWN)
        WIN32_EXIT_CODE    : 0  (0x0)
        SERVICE_EXIT_CODE  : 0  (0x0)
        CHECKPOINT         : 0x0
        WAIT_HINT          : 0x0

If you get this message, which means Windows Defender is not running your system:

[SC] EnumQueryServicesStatus:OpenService FAILED 1060:
The specified service does not exist as an installed service.

or check via GUI: from Windows server manager

Remove just Windows Defender GUI:

Run PowerShell in Administrator, which will remove GUI only:

Uninstall-WindowsFeature -Name Windows-Defender-GUI

To completely remove Windows Defender

Uninstall-WindowsFeature -Name Windows-Defender

Then, just restart your server to finish the process

You can check if your Windows Defender is really removed from your server by going back to server manager

You can also check it by going to Settings>Update & Security>Windows Defender

Just in case you need to re-install Windows Defender back:

To install Windows Defender back for whatever reason, just service:

Install-Windows-Feature -Name Windows-Defender

To install Windows Defender with GUI:

Install-WindowsFeature -Name Windows-Defender-GUI

That’s it, hope you find it useful



How to set Time Zone in osTicket

How to setup Time Zone in osTicket, which is very important to have your system work correctly.  If the time zone is incorrect tickets get mixed up marked wrong data/time, SLA, etc.. So here are few places you can check to confirm your system is correctly setup.  I am using an Ubuntu system other Linux system works similar path might be different.  If your time shows incorrect you should also check to make sure you have installed the PHP Extensions “Intel” which effects the time you can check it at /scp/system.php. There at least 4 places you can set the time zone, I am listing it here, your settings may vary.

Option 1: from osTicket admin panel System Settings and Preferences

/scp/settings.php

Default settings: Locale Defaults

If you need to customize:

Option 2: via php.ini file

Search or in your file under Date and just uncomment date.timezone =
Put your time zone name after = America/New_York (This would be mine)

Timezone name list: https://www.php.net/manual/en/timezones.php

Sample php.ini file looks like
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =

Option 3: via MySQL directly on the database

To see what’s currently is:

mysql -u YourDataBaseUserName -p -e “SELECT NOW();”

To see your current timezone within mysql: use the following command:

mysql> select now();

or
SHOW VARIABLES LIKE ‘%time_zone%’;

or
SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;

To set a time zone or a value: make sure to choose your own time zone:

SET time_zone = America/New_York;

or
SET GLOBAL time_zone = ‘+8:00’;

or
SET GLOBAL time_zone = ‘ America/New_York ‘;

or
SET @@global.time_zone = ‘+00:00’;

To configure the time zone in Ubuntu system:

 sudo dpkg-reconfigure tzdata

Restart the server or you can restart Apache 2 and MySQL:
/etc/init.d/mysql restart

Option 4: Agent profile, which does not affect system-wide

osTicket Agent profile: Agent panel -> Profile -> Preferences -> Localization

That’s it, check the logs of PHP, web server and osTicket if you having any issues, that will give you some more clue.

Issues you might have:

Time issues: if Intel PHP Extension is not installed:

Once you installed Intel PHP extension then, restart your apache (your webserver) service, if everything goes well it should be fine:



How to clean up old DHCP server’s entry in a domain via PowerShell and netsh command

It’s very easy to forget old server entries and it may cause an issue in your network.  Sometimes system/network admin wait for approval process or schedule to clean up or just simply don’t know how to.  Whatever your reason is, this should be done to keep your network healthy from any unknown issues.  Here are some ways to clean up, I have listed PowerShell, Netsh and via GUI.

Via PowerShell:

To see list of all DHCP server run PowerShell command:

PS C:\>Get-DhcpServerInDC

To remove it:

You have to be domain or enterprise admin to remove it otherwise, you will get error

PS C:\>Remove-DhcpServerInDC –DnsName YourDHCPserver –IPAddress

This is without error: if you have run as admin

To add it:

You have to be domain or enterprise admin to remove it otherwise, you will get error

PS C:\> Add-DhcpServerInDC –DnsName YourDHCPserver –IPAddress

Using netsh commands

To the list of commands: netsh dhcp list

To add:

Netsh dhcp add server NameOfYourDHCPServer IP address

To delete:

Dhcp delete server NameOfYourServer IP address

Via GUI:

To add:
open your DHCP server, right-click, and select add

To Remove:
open your DHCP server, right-click and select Manage authorized servers …
Then just remove HDCP server that’s no longer in use

That’s it



How to redirect HTTP to HTTPS in IIS

Redirect are very common for web servers for most if not all websites these days.  This post I am using the URL Rewrite, if your server does not have already you need to download URL Rewrite extension which works With IIS 7, IIS 7.5, IIS 8, IIS 8.5, IIS 10.  Note.  If you already have the URL Rewrite you can skip to the section Adding Redirect Rule

Installation of URL Rewrite:

You can download directly from this link: https://www.iis.net/downloads/microsoft/url-rewrite

If you already have the Web Platform Installer, you can double click and find it there, under your web server>Sites>Select site>on the right-side panel you will see Management section

To start the installation double click on the URL Rewrite and click Install

Read the terms then click on I Accept

If everything goes well you should see, successfully installed, click Finish
you should see the URL Rewrite, if you don’t close the IIS Manager and re-open it.

Adding Redirect Rule:

Double click on the URL Rewrite for the site you want to redirect

Add your rules here, which fits your needs you may need more than one rules

I am going to create a rule to redirect HTTP to HTTPS:

Click Add Rules(s)
Then click on Blank rule (for Inbound rules)

Fill in the Name and other options shown in the screenshot, then expand the Conditions and click Add

This condition will check if user type’s https, then this rule will be ignored, so it avoids the loop

Nothing set on the server variables, unless you needed in some special case, you can add it, Next, we want to set up the redirect
https://{HTTP_HOST}/{R:1}

https://docs.microsoft.com/en-us/iis/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

Your Rule should look something like this if you open your web.config file:
        <rewrite>
            <rules>
                <rule name=”http to https redirect” stopProcessing=”true”>
                    <match url=”(.*)” />
                    <conditions logicalGrouping=”MatchAny”>
                        <add input=”{HTTPS}” pattern=”^OFF$” />
                    </conditions>
                    <action type=”Redirect” url=”https://{HTTP_HOST}/{R:1}” />
                </rule>
            </rules>
        </rewrite>

If you have issues make sure to check following:

  • Make sure your webserver firewall ports 80 and 443 are opened
  • You may need to restart the IIS service for rule to take effect, also make your local cache is cleared for your browser.
  • Double-check the pattern of your rule make sure it’s correctly typed, not a typo

That’s it