Apache 2.2 & PHP 5 (troubleshooting tip to fix force-download php script from localhost server)
1) Make sure the 'libphp5.so' file exists in '/usr/lib/apache2/modules' and file 'libapache2-mod-php5' is installed, use 'sudo apt-get install libapache2-mod-php5' to install.
2) Create a 'php5.conf' in '/etc/apache2/mods-enabled' then insert the code below:
NOTE: Apache2 will load all the *.conf/*.load files automatically when it starts/restarts.
3) Make sure to edit the file 'default' in '/etc/apache2/sites-available' folder to the code below.
These settings are for VirtualHost's/DocumentRoot and more:
NOTE: The 'default' file overrides 'httpd.conf' settings because it's configurations loaded after the 'httpd.conf' loads.
4) Make sure the file '/etc/hosts' has the following DNS settings for localhost server:
6) While in browser, if you site directory continues to force-download the php script then clear browser cache and refresh.
BONUES TIP: to enable mod_rewrite for htaccess in server, make sure the module 'rewrite' (mod_rewrite) is installed, then use command 'sudo a2enmod rewrite' to enable it in apache2.
2) Create a 'php5.conf' in '/etc/apache2/mods-enabled' then insert the code below:
LoadModule php5_module /usr/lib/apache2/modules/libphp5.so
AddType application/x-httpd-php3 .php3
AddType application/x-httpd-php3-source .php3s
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
NOTE: Apache2 will load all the *.conf/*.load files automatically when it starts/restarts.
3) Make sure to edit the file 'default' in '/etc/apache2/sites-available' folder to the code below.
These settings are for VirtualHost's/DocumentRoot and more:
# Enable named virtual hosts
NameVirtualHost *
# Override the default httpd.conf directives. Make sure to
# use 'Allow from all' to prevent 403 Forbidden message.
Options Indexes ExecCGI FollowSymLinks MultiViews
AllowOverride All
Allow from all
# A basic virtual host config
DocumentRoot /var/www/websites/
ServerName dev.mysite.com
ServerAlias mysite
DocumentRoot /var/www/websites/mysite/
NOTE: The 'default' file overrides 'httpd.conf' settings because it's configurations loaded after the 'httpd.conf' loads.
4) Make sure the file '/etc/hosts' has the following DNS settings for localhost server:
127.0.0.1 localhost5) Last step, load the server via browser 'http://localhost/'. This will give you a directory listing or point to index.php/index.html file.
127.0.0.1 dev.mysite.com
127.0.0.1 mysite
6) While in browser, if you site directory continues to force-download the php script then clear browser cache and refresh.
BONUES TIP: to enable mod_rewrite for htaccess in server, make sure the module 'rewrite' (mod_rewrite) is installed, then use command 'sudo a2enmod rewrite' to enable it in apache2.
Labels: apache 2, lamp, linux, localhost, mod_rewrite, php 5, server