After strugling and googleing for a long time, scratching my hair to make this issue resolved, it took lots of my time to come into a conclusion and resolve the issue.

First of all on the directory where the site is hosted, there should be a .htaccess file and you can see it by changing your working directory to your web directory and type the below command to see it

ls -la

this command will list all the files in that directory using the l which is list and a which will show hidden files.

if you dont have the file, please create it using the blow command and add the content below

sudo touch .htaccess
sudo vim .htaccess

and add the below content

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

After saving the file and exit.

Change its permision to 660

chmod 660 .htaccess

and change the owner of the file to be www-data

chowner www-data:www-data .htaccess

 

At this point the marathon is not over, we need to edit the directory access on apache to allow .htaccess overide some configurations on the apache web server, Edit the below file and add some configurations

/etc/apache2/sites-available/000-default.conf

Add the below

ServerAdmin webmaster@domain.com
        DocumentRoot /var/www/html

After changes it should look like this

ServerAdmin webmaster@domain.com
        DocumentRoot /var/www/html
        <Directory /var/www/html>
                Options +FollowSymLinks
                AllowOverride All
        </Directory>

Also edit the file /etc/apache2/apache2.conf

and change as below

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride ALL
        Require all granted
</Directory>

 

then you have one command to fire up things, run the below command

sudo a2enmod rewrite

and restart apache

/etc/init.d/apache2/restart

Here your ready to test the permalinkg after you change and update.

Things will come as expected from here.

Try it and see it for yourself, drop us a comment if this helps you

Thanks and mostly welcome