Asked  7 Months ago    Answers:  5   Viewed   30 times

Everything was going great until I added AddHandler application/x-httpd-php5s .php to the .htaccess file in my local server's document root (which I change frequently depending on the site I'm working with). Since I did that when I visit http://localhost:8888 my browser just downloads the index.php and it's not processed at all, just the raw code. Now I removed that line from the .htaccess file but I'm still having this problem.

I've found that if I add an alternative entry to my hosts file for 127.0.0.1 the new entry behaves like 'localhost' used to. But if I add the line above to my .htaccess it knocks out that new host as well. I've tried reinstalling MAMP and clearing its caches and all the temporary files I could find. I surfed through Apache's httpd.conf file all to no avail.

So, to be clear: http://localhost:8888 is experiencing the above problem. If I add a new entry to my hosts file for 127.0.0.1, say 'goomba' and the above line is not in the root .htaccess (and has never been for that host/alias/whatever) then I can access http://goomba:8888 just fine. But if I do add that line to the .htaccess then I have to add yet another entry to my hosts file to get around it even if I remove that line from the the .htaccess file.

I'm fine with using a different 127.0.0.1 alias (host? what is that called?) but it's bugging me that this is still broken.

Just to be clear, I'm on Mac OS Leopard (but I'm not using the built in Apache setup, but MAMP).

 Answers

70

You are applying a mimetype where a handler should be (see documentation on handlers)

Try this instead:

AddType application/x-httpd-php5 .php

EDIT: As you have indicated caching modules are loaded, you could read up on caching and htcacheclean (to clear the disk cache). You can also temporarily use the CacheDisable directive. One other thing that you could also try is to rename the file that you have requested (e.g. index.php -> index.bak), request the file again in the browser (should now 404), then revert and try again.

Wednesday, March 31, 2021
 
CAMason
answered 7 Months ago
36

Make sure libgd is installed!

http://libgd.github.io/

http://php.net/manual/en/book.image.php

CentOS users

  1. yum install gd gd-devel php-gd
  2. Restart http server (in my case apache).
Saturday, May 29, 2021
 
o_flyer
answered 5 Months ago
18

MAMP Folks just posted the workaround

Workaround for the 10.10 Preview 5 bug: Rename the file “envvars” located in /Applications/MAMP/Library/bin into “_envvars”

Test Update: It works!

Works for Yosemite release too!

Wednesday, June 9, 2021
 
saad
answered 5 Months ago
71

I did a bit of digging and this seems to resolve the php version issue:

sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set php_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set doc_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/doc/
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set data_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/data/
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set test_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/test/
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set www_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/www
sudo mkdir /Applications/MAMP/bin/php/php5.3.6/lib/php/www
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-show
sudo /Applications/MAMP/bin/php/php5.3.6/bin/pear config-set cfg_dir /Applications/MAMP/bin/php/php5.3.6/lib/php/cfg
sudo mkdir /Applications/MAMP/bin/php/php5.3.6/lib/php/cfg

Then just cd to /Applications/MAMP/bin/php/php5.3.6/bin and run ./pear upgrade --force

This will set all the config files in the .pearrc of your home directory, haven't looked into integrating them into the pear.conf in MAMP..

> cd /Applications/MAMP/bin/php/php5.3.6/bin
> ./pear version
PEAR Version: 1.9.4
PHP Version: 5.3.6
Zend Engine Version: 2.3.0
Running on: Darwin willem.local 11.2.0 Darwin Kernel Version 11.2.0: Tue Aug  9 20:54:00 PDT 2011; root:xnu-1699.24.8~1/RELEASE_X86_64 x86_64
Saturday, August 14, 2021
 
kneeki
answered 2 Months ago
52

you cannot pass by reference in C but can use pointers as an alternative

Yup, thats correct.


To elaborate a little more. Whatever you pass as an argument to c functions, it is passed by values only. Whether it be a variable's value or the variable address.

What makes the difference is what you are sending.

When we pass-by-value we are passing the value of the variable to a function. When we pass-by-reference we are passing an alias of the variable to a function. C can pass a pointer into a function but that is still pass-by-value. It is copying the value of the pointer, the address, into the function.


  • If you are sending the value of a variable, then only the value will be received by the function, and changing that won't effect the original value.

  • If you are sending the address of a variable, then also only the value(the address in this case) is sent, but since you have the address of a variable it can be used to change the original value.


As an example, we can see some C++ code to understand the real difference between call-by-value and call-by-reference. Taken from this website.

// Program to sort two numbers using call by reference. 
// Smallest number is output first.

#include <iostream>
using namespace std;

// Function prototype for call by reference
void swap(float &x, float &y);

int main()
{
   float a, b;

   cout << "Enter 2 numbers: " << endl;
   cin >> a >> b;
   if(a>b) 
     swap(a,b); // This looks just like a call-by-value, but in fact
                // it's a call by reference (because of the "&" in the
                // function prototype

   // Variable a contains value of smallest number
   cout << "Sorted numbers: ";
   cout << a << " " << b << endl;
   return 0;
}

// A function definition for call by reference
// The variables x and y will have their values changed.

void swap(float &x, float &y)
// Swaps x and y data of calling function
{
   float temp;

   temp = x;
   x = y;
   y = temp;
}

In this C++ example, reference variable(which is not present in C) is being used. To quote this website,

"A reference is an alias, or an alternate name to an existing variable...",

and

"The main use of references is acting as function formal parameters to support pass-by-reference..."

This is different then the use of pointers as function parameters because,

"A pointer variable (or pointer in short) is basically the same as the other variables, which can store a piece of data. Unlike normal variable which stores a value (such as an int, a double, a char), a pointer stores a memory address."

So, essentially when one is sending address and receiving through pointers, one is sending the value only, but when one is sending/receiving a reference variable, one is sending an alias, or a reference.


**UPDATE : 11 November, 2015**

There has been a long debate in the C Chatroom, and after reading comments and answers to this question, i have realized that there can be another way to look at this question, another perspective that is.

Lets look at some simple C code

int i;
int *p = &i;
*p = 123;

In this scenario, one can use the terminology that, p's value is a reference to i. So, if that is the case, then if we send the same pointer (int* p) to a function, one can argue that, since i's reference is sent to the function, and thus this can be called pass-by-reference.

So, its a matter of terminology and way of looking at the scenario.

I would not completely disagree with that argument. But for a person who completely follows the book and rules, this would be wrong.


NOTE: Update inspired by this chat.

Saturday, September 4, 2021
 
footy
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :