I am working on MacOS, following operation solved my problem:
I copied from : https://akrabat.com/setting-up-php-mysql-on-os-x-10-7-lion/
cd /etc/apache2
Give write permission the config file to root: sudo chmod u+w httpd.conf sudo vim httpd.conf
Find #LoadModule php5_module libexec/apache2/libphp5.so
and remove the leading #
Find #LoadModule rewrite_module libexec/apache2/mod_rewrite.so
and remove the leading #
Find AllowOverride None within the section and change to AllowOverride All so that .htaccess files will work.
Change permissions back: sudo chmod u-w httpd.conf
Restart Apache by running following in terminal:
sudo apachectl restart