-5

I'm having:

  • Ubuntu Linux 12.04 LTS
  • Apache Web Server(Apache httpd 2.4.16)
  • PHP 5.5.29

Now, whenever something goes wrong in code I always see a white screen in my browser window with no output at all. So, I googled for the solution and come to know that I have to turn the error reporting on in order to get the detailed errors/exceptions/warnings/etc.

And for this I come to know that I need to change php.ini file which Apache web server is making use of.

I opened up the file '/etc/php5/apache2/php.ini' by selecting it with my mouse, right click on the file '/etc/php5/apache2/php.ini', selected the option 'Open With Sublime Text2' and open up the file in Sublime Text Editor.

I did one small change on line no.466 of '/etc/php5/apache2/php.ini' file as follows :

display_errors = Off //Old code present on line no.466 of php.ini
display_errors = On  //New code changed by me on line no.466 of php.ini

I am not sure is this the only change I need to make to '/etc/php5/apache2/php.ini' file to get errors/warnings/exceptions/etc. Please guide me in detail regarding the changes I need to make to the file '/etc/php5/apache2/php.ini' to get all the possible errors/warnings/exceptions/etc.

Now when I tried to save this file I got a pop-up saying 'Unable to save /etc/php5/apache2/php.ini'.

I'm the owner of my laptop, the system is mine, I am the administrator of my system and still I can't make any change to the file. This is really an un-understandable, useless and strange stuff for me. Previously when I was using PHP on my windows machine such weird things and headache never happened.

Please someone take me out of this bloody mess by giving descriptive and step by step answer.

Few people are saying I have to open up the terminal and type commands there. But I'm not getting What is terminal? Where it is? How to open it? What is root user and what is sudo user? What does each of the users do? What's the difference in between them? The purpose of graphical text editor is to manipulate files and this Ubuntu is preventing me from doing it.

Everything is strange here with Ubuntu Linux. What's the use of it? etc.

Madara's Ghost
  • 172,118
  • 50
  • 264
  • 308
PHPLover
  • 1
  • 51
  • 158
  • 311
  • 2
    edit the file as root by launching your editor with `sudo` – Joe Nov 27 '15 at 15:04
  • @Joe : I simply right clicked the file with my mouse and selected the option 'Open With Sublime Text 2' just I do on Windows. Now I'm not getting you what are you saying by means of 'edit the file as root by launching the editor with sudo'. How should I launch the Sublime editor with sudo while I right click to open up the file? Tell me clearly. – PHPLover Nov 27 '15 at 15:07
  • @Joe: I never faced such kind of time consuming and useless issues on Windows OS. – PHPLover Nov 27 '15 at 15:08
  • 1
    Windows has a similar feature called User Account Control – Andrea Nov 27 '15 at 15:39
  • Did you ever read the error log of your apache web server? – Ken Cheung Nov 30 '15 at 09:31
  • @user2839497: Did you checked my solution? – Somnath Muluk Dec 01 '15 at 13:30

5 Answers5

4

What is terminal?

Terminal is an interface where you execute your commands. More details here. Its like cmd in windows.

Where it is? How to open it?

Open the Dash (Dash is similar to the Start button in windows) enter image description here and type terminal. enter image description here

The black board like icon with >_ is your terminal, click on it. enter image description here

This is what a terminal looks like.

What is root user and what is sudo user? What does each of the users do? What's the difference in between them?

Quoted from Ubuntu docs

In Linux (and Unix in general), there is a SuperUser named root. The Windows equivalent of root is the Administrators group. The SuperUser can do anything and everything, and thus doing daily work as the SuperUser can be dangerous. You could type a command incorrectly and destroy the system. Ideally, you run as a user that has only the privileges needed for the task at hand. In some cases, this is necessarily root, but most of the time it is a regular user.

By default, the root account password is locked in Ubuntu. This means that you cannot login as root directly or use the su command to become the root user. However, since the root account physically exists it is still possible to run programs with root-level privileges. This is where sudo comes in - it allows authorized users to run certain programs as root without having to know the root password.

Editing the php.ini file:

Now that you know what terminal is, open the terminal and type:

sudo vi /etc/php5/apache2/php.ini

Note: There are various other editors, like nano, gedit etc.

You'll be prompted to enter the password:

[sudo] password for user:

Just type in the password and hit enter. You'll see the contents of php.ini in the terminal. Now, scroll and search for the line Display_errors =off. You will have to change this to Display_errors =on, to do this change press i, make your changes, press esc, press shift+q type wq! and hit enter. Now, you will have to restart apache to have the changes take effect. So, type:

sudo service apache2 restart

and hit enter. Thats it. Hope that gives you an idea :)

Community
  • 1
  • 1
Criesto
  • 1,985
  • 4
  • 32
  • 41
1

Regarding php.ini

You can do runtime change in all settings of your php.ini or by editing php.ini.

You should keep error_reporting false by default. And in development you can make reporting on runtime.

error_reporting(E_ALL);
ini_set("display_errors", 1);

Do this only if you are in development mode to see all fatal/parse errors or set error_log to your desired file to log errors instead of display_errors in production (this requires log_errors to be turned on).

Regarding file changes

php.ini needs to be edited by root user.

So you can edit by terminal:

  1. Open terminal
  2. Switch user as root
  3. Edit php.ini by vi editor and do changes.
  4. Restart apache server

Or If you still want to edit by sublime

  1. Open php.ini by sublime with root access
  2. You need do required changes in php.ini
  3. Restart apache server
Community
  • 1
  • 1
Somnath Muluk
  • 55,015
  • 38
  • 216
  • 226
1

Terminal

The terminal is an interface in which you can type and execute text based commands.
Think of it like cmd in windows.

How to run it:
Open the Dash (Super/window Key) or Applications and type terminal, or use the keyboard shortcut by pressing Ctrl+Alt+T.

As this is to broad, and you actualy don't need terminal for your problem; for a great explanation of terminal please see: What is a terminal and how do I open and use it?.

Display error settings in php.ini

There are 2 settings you must edit:

  • error_reporting = E_ALL
    Make sure it only have the value E_ALL.
    E_ALL = Show all errors, warnings and notices including coding standards.
    E_NOTICE = Show notices
    E_STRICT = Show coding standard warnings
    if you put ~ in-front it, it means Except.
  • display_errors = On

Unix-like OS file permissions

In unix-like OSes, files and directories are owned by a user and distinct permissions (read, write, run) apply to the owner.

These are very simplified explanation:
The '/etc/php5/apache2/php.ini' file is owned by root and with write permission only for root, so you can't edit it unless you are the user root itself.

But there is a way for you to edit files owned by another user, and that is with a command: sudo (superuser do ...), or gksu/gksudo for graphical interfaces software.

You may think that your username is another administrator/SuperUser, so why can't you just edit and save the file? Well, in actual you are not. Your user is just a regular user, but with permission to do SuperUser task. In other word you are just a sudo user (sudoers).


So the only way for you to save the changes you made, is to run Sublime Text using root privilege.

This can be achieved from the terminal by executing it via command: sudo sublime or gksu sublime.

Or without terminal:
via Dash (press super/window key), just type gksu sublime and press enter (you will be asked for your password).

This makes you run sublime text editor as root user, so now you can open the '/etc/php5/apache2/php.ini' file and edit it and save it.

(If you don't have gksu, install it via Ubuntu Software Installer.)

Community
  • 1
  • 1
cwps
  • 367
  • 1
  • 6
0

I use gksudo and gedit to do the job. gksudo makes it possible to open a graphical interface. Gedit is the default text editor for GNOME. If you have KDE, then will you use kedit.

First I find the correct location of the used configuration file. You can find it easily making a php file calling the function php_info. The content of the php file is a call to one function:

  phpinfo();

That is it. I always have a file info.php in the documentroot of apache (in Ubuntu /var/www. Then I make a call to that file with:

http://localhost/info.php

and a document containing a lot of information will be returned. In it, you have a configuration value: Loaded Configuration File

The value on that line is the php file that is used by the apache server. You should edit that file in order to see errors displayed. Lets call that value %phpini-file%.

Next I open a terminal (see https://help.ubuntu.com/community/UsingTheTerminal) and type

gksudo gedit %phpini-file%

and I do traverse the file until I see error handling and logging. After that you will find the variables that you would like to be changed. On a development machine I set the variable error_reporting to:

error_reporting = E_ALL

The documentation in the file gives you good suggestions.

Underneath that variable you have the variables display_errors, display_startup_errors and log_errors. I always give those variables the values On on my development machine.

Some lines below that you have the variable track_errors. I put it to On.

After making those changes will you have to restart apache. The way I do it is:

sudo /etc/init.d/apache2 restart

It is equivalent to

sudo service apache2 restart

but it is how I have remembered it.

Instead of a terminal you can type ALT + F2 and you will see a command line appear in the midst of your screen. Next you type your command and the action will be performed.

Root is the user that has all privileges on an unix based system. Sudo is an abbreviation of super user do and makes it possible to execute commands as if someone is root. The whole root concept makes it safe that not any user can do anything on the system. You must be root or otherwise get sudo privileges in order to make changes on the system.

Loek Bergman
  • 2,192
  • 20
  • 18
0

You just need to press

Ctrl + Alt + T

and you'll see a window appearing, which is nothing but the Terminal.

There you just need to type :

sudo gedit /etc/php5/apache2/php.ini

[Gedit is nothing but the default linuk editor] After that you'll be asked to enter the password, where you need to enter your system's password.

The file will open in the editor, just find Display_Errors in that page and replace off with on, so it will be :

Display_Errors=on

After the changes save and close that file.

And just restart your apache by typing this command on the TERMINAL again :

sudo /etc/init.d/apache2 restart
Nehal
  • 1,542
  • 4
  • 17
  • 30