0

I just installed my first LAMP and NetBean in Ubuntu. I imported a small website and tried to run it both locally and remotely, but the pages that use json_decode (and other functions) don't work on the local server.

For example this page:

<?php
echo "X ";
var_dump(json_decode("{}"));
echo " Y";
?>

On the managed server shows X object(stdClass)#1 (0) { } Y, but on the local server shows X only.

I ctrl+clicked on the json_decode function name, and the file json.php opened with a json_decode function with the empty body. I don't understand if that's just the definition of an interface or the real function (I'm learning PHP), but the fact that the rendering stops there, without error messages, sounds weird.

UPDATE:

I uninstalled all the packages listed at the "Starting over" section in this page, and re-installed with sudo tasksel install lamp-server.

The next day there was a massive automatic update. I don't know if there is a relation between the installation and the update, or if the update would have come anyway.

Right now I'm still at the same position: some pages are rendered correctly locally, but my website uses json on almost every page, so I can't use the local server. (I was hoping to be able to use it in the next days, when I will be visiting the in-laws, where Internet is still an unknown concept.)

UPDATE 2:

The fact mentioned earlier that json_decode() has an empty body is not a problem. I just right clicked on session_start();, and the file session.php opened with the function defined as function session_start () {}. I don't understand why the library functions contain empty bodies, but session_start() works, so json_decode() should as well.

stenci
  • 8,290
  • 14
  • 64
  • 104
  • http://pecl.php.net/package/json – user602525 Dec 16 '13 at 04:18
  • @user602525: `php_info()` says `PHP Version 5.5.3-1ubuntu2`. I looked at the json page, but I don't know what to do with it. – stenci Dec 16 '13 at 04:28
  • How did you install PHP, did you just use apt-get install php5? – user602525 Dec 16 '13 at 04:29
  • I followed the instructions in https://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html `apt-get --purge remove php5-common` and `apt-get install php5 phpmyadmin` (after installing LAMP as suggested above in the same page) – stenci Dec 16 '13 at 04:33
  • Weird. Maybe try installing pear sudo apt-get install php-pear and sudo apt-get install php5-dev – user602525 Dec 16 '13 at 04:37
  • Although the docs say json is bundled with php5 now... – user602525 Dec 16 '13 at 04:38
  • I do have json.php. I did the two installations that you suggested, but nothing changed. If you think it would help I could try to restart from scratch. Is there a document that shows how to clean up and re-install (other than the page I mentioned earlier)? – stenci Dec 16 '13 at 04:47
  • https://help.ubuntu.com/community/ApacheMySQLPHP – user602525 Dec 16 '13 at 04:49
  • Do you suggest I should uninstall something NetBean, Apache or anything else first? – stenci Dec 16 '13 at 05:09
  • Yea probably. Do the starting over part on that link. – user602525 Dec 16 '13 at 05:10
  • Well... it says `remove the following packages`, but it doesn't say how. How do I remove a package? And how do I check if it's still there? I have Ubuntu, not Ubuntu server, does that make any difference? – stenci Dec 16 '13 at 05:13
  • #apt-get remove --purge #apt-get clean – user602525 Dec 16 '13 at 05:16
  • I did remove and reinstall, but nothing changed. localhost works, but restarting apache2 gives the error message mentioned under Checking Apache 2 installation, and the folder /etc/apache2/conf.d mentioned on that page does not exist. Php json functions don't work, the configuration directories are missing... what's going on? – stenci Dec 16 '13 at 05:41
  • I noticed that ctrl+clicking on other functions like `filter_input` opens a source file with the function definition without the body. – stenci Dec 16 '13 at 06:43
  • @stenci: the PHP core and extension functions are implemented in C/C++ (?), it is normal that you only see the function header as an interface definition. Regarding your problem: enable error_reporting, check your logs if anything unusual happened. One other thing: ubuntu has a rather strange handling of user rights - did you do the apt-get operations with sudo / as root? – cypherabe Dec 19 '13 at 14:28
  • also, you can use the phpinfo() function to get a lot of info about your installation, among them: config file path, status of extensions like json.. ;) – cypherabe Dec 19 '13 at 14:40

3 Answers3

0

Try installing the json extension separately. I think it's called php-services-json on Ubuntu, so run apt-get install php-services-json

bluesmoon
  • 3,918
  • 3
  • 25
  • 30
0

The fact that you are not seeing the "Y" would probably indicate a fatal error occuring during your json_decode (you could use ini_set("display_errors",1); at the top of your script to be sure)

The fatal would probably be something like:

PHP Fatal error: Call to undefined function json_decode()

Do some googling on that error. This post may help, if I am right about the fatal error:

PHP Fatal error: Call to undefined function json_decode()

Community
  • 1
  • 1
Jason Fingar
  • 3,358
  • 1
  • 21
  • 27
  • Good catch, that was the error message I would get using `ini_set("display_errors",1);` (which I didn't know). Installing the missing json with `sudo apt-get install php5-json` and restarting the server with `sudo service apache2 restart` did the job. Thanks! – stenci Dec 20 '13 at 07:13
0

Try not to use LAMP and install apache2 manually try if that works, maybe the LAMP package is causing you trouble. That is if you're not afraid of some extra work.

You could also check your configs if they forbid anything.

deW1
  • 5,562
  • 10
  • 38
  • 54