Rectangle 27 731

Display errors could be turned off in the php.ini or your Apache config file.

You can turn it on in the script:

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

You should see the same messages in the PHP error log.

Do I need to restart apache after changing the php.ini file?

ini_set()
php.ini
Sets the value of the given configuration option. The configuration option will keep this new value
during the script's execution
, and
will be restored at the script's ending

I don't know how many times I came to same answer. You helped me a lot. Thank you! :)

E_ALL
E_NOTICE

php - Showing all errors and warnings - Stack Overflow

php debugging warnings
Rectangle 27 731

Display errors could be turned off in the php.ini or your Apache config file.

You can turn it on in the script:

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

You should see the same messages in the PHP error log.

Do I need to restart apache after changing the php.ini file?

ini_set()
php.ini
Sets the value of the given configuration option. The configuration option will keep this new value
during the script's execution
, and
will be restored at the script's ending

I don't know how many times I came to same answer. You helped me a lot. Thank you! :)

E_ALL
E_NOTICE

php - Showing all errors and warnings - Stack Overflow

php debugging warnings
Rectangle 27 690

Display errors could be turned off in the php.ini or your Apache config file.

You can turn it on in the script:

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

You should see the same messages in the PHP error log.

Do I need to restart apache after changing the php.ini file?

Yikes! Don't remove E_NOTICE from error_reporting during development. Every notice is a bug in your code.

ini_set()
php.ini
Sets the value of the given configuration option. The configuration option will keep this new value
during the script's execution
, and
will be restored at the script's ending

I don't know how many times I came to same answer. You helped me a lot. Thank you! :)

E_ALL
E_NOTICE

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - Showing all errors and warnings - Stack Overflow

php debugging warnings
Rectangle 27 11

I was just typing that. I was going to point at the sub-clause that a lot, if not most shared hosts don't give their customers access to anything outside of the document root.

Still you have the literal password stored somewhere in one file. That's still a higher risk than you need to take.

Peter O'Callaghan, I have dedicated server, and even I can't store outside of the document root

php - a better approach than storing mysql password in plain text in c...

php mysql security passwords
Rectangle 27 11

I was just typing that. I was going to point at the sub-clause that a lot, if not most shared hosts don't give their customers access to anything outside of the document root.

Still you have the literal password stored somewhere in one file. That's still a higher risk than you need to take.

Peter O'Callaghan, I have dedicated server, and even I can't store outside of the document root

php - a better approach than storing mysql password in plain text in c...

php mysql security passwords
Rectangle 27 2

httpd.conf or your server config for php or other users (usually locat...

After So Much Search i landed on this solution and its work form me on local system and also on live web faction server this is my solution for Django users please go to your apache folder located in project then in bin you find

<IfModule mod_headers.c>
SetEnvIf Origin (.*) AccessControlAllowOrigin=$1
Header add Access-Control-Allow-Origin %{AccessControlAllowOrigin}e env=AccessControlAllowOrigin
Header set Access-Control-Allow-Credentials true
</IfModule>

then in angular js app you just needed to place

angular.module('app', ['ngCookies'])
    .config([
   '$httpProvider',
   '$interpolateProvider',
   function($httpProvider, $interpolateProvider, $scope, $http) {
       $httpProvider.defaults.withCredentials = true;
       $httpProvider.defaults.xsrfCookieName = 'csrftoken';
       $httpProvider.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded';
   }]).
   run([
   '$http',
   '$cookies',
   function($http, $cookies) {
       $http.defaults.headers.post['X-CSRFToken'] = $cookies.csrftoken;
   }]);

AngularJS + Django Rest Framework + CORS ( CSRF Cookie not showing up ...

django angularjs cors django-rest-framework django-cors-headers
Rectangle 27 18

PHP comes with two native functions to show which config file is loaded :

  • php_ini_scanned_files return a list of .ini files parsed from the additional ini dir

Depending on your setup, Apache and CLI might use different ini files. Here are the two solutions :

Just add the following in a php file and open it in your browser

print php_ini_loaded_file();
print_r(php_ini_scanned_files());

Copy-paste in your terminal :

php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'

Under-appreciated, thorough, and (almost) correct answer. I almost switched this to the correct answer but I am worried that php_ini_loaded_file may not always be available.

@zylstra what was your php version? the docs for php_ini_loaded_file say php version >= 5.2.4

@necromancer Not sure now. Forgot which system I was checking. :/

linux - Dude, where's my php.ini? - Stack Overflow

php linux php-ini
Rectangle 27 16

PHP comes with two native functions to show which config file is loaded :

  • php_ini_scanned_files return a list of .ini files parsed from the additional ini dir

Depending on your setup, Apache and CLI might use different ini files. Here are the two solutions :

Just add the following in a php file and open it in your browser

print php_ini_loaded_file();
print_r(php_ini_scanned_files());

Copy-paste in your terminal :

php -r 'print php_ini_loaded_file(); print_r(php_ini_scanned_files());'

Under-appreciated, thorough, and (almost) correct answer. I almost switched this to the correct answer but I am worried that php_ini_loaded_file may not always be available.

@zylstra what was your php version? the docs for php_ini_loaded_file say php version >= 5.2.4

@necromancer Not sure now. Forgot which system I was checking. :/

linux - Dude, where's my php.ini? - Stack Overflow

php linux php-ini
Rectangle 27 1

require_once 'Zend/Application.php'; ^ See this line? It requires the Zend Framework to be in your include path before even the config file is loaded.

I can't? so what's the usage of the includePaths.library line in config file? Btw in my index.php i have " require_once APPLICATION_PATH.'/library/Zend/Application.php';"

php - Zend setting includePaths from config file - Stack Overflow

php zend-framework config include-path
Rectangle 27 14

you should use a config file that will be included in each file first line, for example your app look like this

app-config.php
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

now, suppose you have to include a plugin file, so

my-plugin.php
require_once '../../app-config.php';

now everything below this line can use ABSPATH

example do you want to load an image

<img src='".ABSPATH."Public/images/demo.png' alt=''/>
plugin-widget-1.php

so that everything inside this file or any other file loaded by the my-plugin.php file can use the ABSPATH without include each time the app-config.php file.

with this in mind you can have all the short-hand you want into the app-config.php example

define('UPLOAD_PATH', ABSPATH. 'Public/uploads/');
define('IMAGES_PATH', ABSPATH. 'Public/images/');
define('HELPERS_PATH', ABSPATH. 'App/helpers/');
...

so, now that you have all defined, if you need to move a file, let's say one folder forward example:

require_once '../../../app-config.php';

obviously i suppose that you are not changing paths each time =) anyway if you need to do so is always more simple to change one file inclusion instead of hundreds.

I'm implementing this solution right now. Thanks.

Sign up for our newsletter and get our top new questions delivered to your inbox (see an example).

php - Absolute vs. relative paths - Stack Overflow

php relative-path absolute-path
Rectangle 27 14

you should use a config file that will be included in each file first line, for example your app look like this

app-config.php
if ( !defined('ABSPATH') )
    define('ABSPATH', dirname(__FILE__) . '/');

now, suppose you have to include a plugin file, so

my-plugin.php
require_once '../../app-config.php';

now everything below this line can use ABSPATH

example do you want to load an image

<img src='".ABSPATH."Public/images/demo.png' alt=''/>
plugin-widget-1.php

so that everything inside this file or any other file loaded by the my-plugin.php file can use the ABSPATH without include each time the app-config.php file.

with this in mind you can have all the short-hand you want into the app-config.php example

define('UPLOAD_PATH', ABSPATH. 'Public/uploads/');
define('IMAGES_PATH', ABSPATH. 'Public/images/');
define('HELPERS_PATH', ABSPATH. 'App/helpers/');
...

so, now that you have all defined, if you need to move a file, let's say one folder forward example:

require_once '../../../app-config.php';

obviously i suppose that you are not changing paths each time =) anyway if you need to do so is always more simple to change one file inclusion instead of hundreds.

I'm implementing this solution right now. Thanks.

php - Absolute vs. relative paths - Stack Overflow

php relative-path absolute-path
Rectangle 27 12

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

I was able to get this to work by putting all the settings into application/config/email.php.

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE@gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Then, in one of the controller methods I have something like:

$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE@gmail.com', 'YOUREMAILHERE@gmail.com');
$this->email->to('SOMEEMAILHERE@gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();

Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:

extension=php_openssl.dll

php - Sending email with gmail smtp with codeigniter email library - S...

php codeigniter email smtp
Rectangle 27 12

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

I was able to get this to work by putting all the settings into application/config/email.php.

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE@gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Then, in one of the controller methods I have something like:

$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE@gmail.com', 'YOUREMAILHERE@gmail.com');
$this->email->to('SOMEEMAILHERE@gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();

Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:

extension=php_openssl.dll

php - Sending email with gmail smtp with codeigniter email library - S...

php codeigniter email smtp
Rectangle 27 12

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

I was able to get this to work by putting all the settings into application/config/email.php.

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE@gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Then, in one of the controller methods I have something like:

$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE@gmail.com', 'YOUREMAILHERE@gmail.com');
$this->email->to('SOMEEMAILHERE@gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();

Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:

extension=php_openssl.dll

php - Sending email with gmail smtp with codeigniter email library - S...

php codeigniter email smtp
Rectangle 27 12

If you prefer not to set preferences using the above method, you can instead put them into a config file. Simply create a new file called the email.php, add the $config array in that file. Then save the file at config/email.php and it will be used automatically. You will NOT need to use the $this->email->initialize() function if you save your preferences in a config file.

I was able to get this to work by putting all the settings into application/config/email.php.

$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
//$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'YOUREMAILHERE@gmail.com';
$config['smtp_pass'] = 'YOURPASSWORDHERE';
$config['smtp_port'] = 465; 
$config['smtp_timeout'] = 5;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;

Then, in one of the controller methods I have something like:

$this->load->library('email'); // Note: no $config param needed
$this->email->from('YOUREMAILHERE@gmail.com', 'YOUREMAILHERE@gmail.com');
$this->email->to('SOMEEMAILHERE@gmail.com');
$this->email->subject('Test email from CI and Gmail');
$this->email->message('This is a test.');
$this->email->send();

Also, as Cerebro wrote, I had to uncomment out this line in my php.ini file and restart PHP:

extension=php_openssl.dll

php - Sending email with gmail smtp with codeigniter email library - S...

php codeigniter email smtp
Rectangle 27 4

You need to add the following line into your Apache config file:

AddType application/x-httpd-php .htm .html
your_site.conf
/etc/apache2/mods-available
<Directory "<path_to_your_html_dir(in my case: /var/www/html)>">
    AllowOverride All
</Directory>
sudo a2enmod rewrite

After any of those steps, you should restart apache:

sudo service apache2 restart

Using .htaccess to make all .html pages to run as .php files? - Stack ...

php html apache .htaccess
Rectangle 27 1

To find out what user your script is running as (which in the general case is not necessarily the same as the owner of the file) you can check the output of:

$user_info = posix_getpwuid(posix_geteuid());
echo $user_info['name'];

If this user is root run fast and far from your current host.

If the returned user is the same as the file owner (the one you're logging in as over ssh, etc.), chmod the config file to 400 - there's no need for it to be world-readable. If it's a different user chmod 444.

chmod u+w your.file
chmod u-w your.file
chmod u+w
chmod 600
chmod 644
u-w

+1, also you must use Octal mode (ie, 0444) if doing this via PHP's chmod function.

How to prevent PHP from writing to a config file with permissions 644?...

php file-permissions
Rectangle 27 8

@Javacadabra, extensions like php_openssl.dll will be under php/ext/ directory, you could fix this path in the config file or you could copy that specific file from php/ext directory to php directory.

in your case it will be c:\php\ext

I will accept this answer, composer installed but for some reason it's commands are not being recognized on the command line, im guessing this is also a path issue.

php - Installing Composer OpenSSL Issue - Stack Overflow

php laravel openssl composer-php
Rectangle 27 8

@Javacadabra, extensions like php_openssl.dll will be under php/ext/ directory, you could fix this path in the config file or you could copy that specific file from php/ext directory to php directory.

in your case it will be c:\php\ext

I will accept this answer, composer installed but for some reason it's commands are not being recognized on the command line, im guessing this is also a path issue.

php - Installing Composer OpenSSL Issue - Stack Overflow

php laravel openssl composer-php
Rectangle 27 12

Dunno if it will help, but here is a piece of my standard config file for php projects. I tend not to depend too much on the apache configs even on my own server.

I never have the disappearing error problem, so perhaps something here will give you an idea.

/*
APPLICATION_LIVE will be used in process to tell if we are in a development or production environment.  It's generally set as early as possible (often the first code to run), before any config, url routing, etc.
*/

if ( preg_match( "%^(www.)?livedomain.com$%", $_SERVER["HTTP_HOST"]) ) {
    define('APPLICATION_LIVE', true);
} elseif ( preg_match( "%^(www.)?devdomain.net$%", $_SERVER["HTTP_HOST"]) ) {
    define('APPLICATION_LIVE', false);
} else {
    die("INVALID HOST REQUEST (".$_SERVER["HTTP_HOST"].")");
    // Log or take other appropriate action.
}


/*
--------------------------------------------------------------------
DEFAULT ERROR HANDLING
--------------------------------------------------------------------
Default error logging.  Some of these may be changed later based on APPLICATION_LIVE.
*/
error_reporting(E_ALL & ~E_STRICT);
ini_set ( "display_errors", "0");
ini_set ( "display_startup_errors", "0");
ini_set ( "log_errors", 1);
ini_set ( "log_errors_max_len", 0);
ini_set ( "error_log", APPLICATION_ROOT."logs/php_error_log.txt");
ini_set ( "display_errors", "0");
ini_set ( "display_startup_errors", "0");

if ( ! APPLICATION_LIVE ) {
    // A few changes to error handling for development.
    // We will want errors to be visible during development.
    ini_set ( "display_errors", "1");
    ini_set ( "display_startup_errors", "1");
    ini_set ( "html_errors", "1");
    ini_set ( "docref_root", "http://www.php.net/");
    ini_set ( "error_prepend_string", "<div style='color:red; font-family:verdana; border:1px solid red; padding:5px;'>");
    ini_set ( "error_append_string", "</div>");
}

Out of curiousity, where is APPLICATION_LIVE usually defined?

up 1 for the concept that overlook debug settings however server is configured, good while you are deploying or maintaining (under development)

error handling - PHP's white screen of death - Stack Overflow

php error-handling error-reporting wsod