multi php.ini files in my system - user-agent

I have Linux Ubuntu 10.10 and when i run the below in a terminal:
php -i | grep php.ini
I got the loaded Configuration File => /etc/php5/cli/php.ini
While if I use phpinfo() in the browser it will be:
Loaded Configuration File /etc/php5/apache2/php.ini
Which means that there are different ini files according to php_sapi_name!!
now the question is how can i set the same php.ini for all user agents (browser, cli, etc) without copying the same file to different locations!?

I don't think setting all the different php contexts to use the same config is a good idea in the first place but if you really want to, you could just have one php.ini and all the others be symbolic links.
I don't think there is a way to change php's behavior as to which file it will include without at the very least recompiling it.

sometimes you can have more than one php.ini to manage different interfaces or websites
for example you can have different php.ini for each website you host on your server by setting PHPINIDir in your virtualhost as below
<VirtualHost 10.24.11.2:80>
ServerName foo.com
ServerAlias www.foo.com
PHPINIDir /var/www/html/foo
</VirtualHost>
however, if you like to make only one php.ini for all interfaces, the only way is to use symlinks as below:
ln -s /etc/php5/cli/php.ini /etc/php5/apache2/php.ini

You could use symlinks.
ln -s /etc/php5/cli/php.ini /etc/php5/apache2/php.ini

What about replacing one of them with a symlink?

You can use symlinks (Apache is using this technique for sites-available and sites-enabled).
So navigate to
cd /etc/php5/
and copy your desired php.ini file there, then navigate to cli/ and apache2/ - remove php.ini (mv or rm it) and then run
cd /etc/php5/apache2
mv php.ini php.ini.bkp
ln -s php.ini ../php.ini
This will create a symlink to php.ini in your /etc/php5/apache2/ and /etc/php5/cli/ folders.
Note: It is a good practice to have diff. php.ini files, for cli there are few extensions that are not loadable and much more. :)

Related

Apache Virtualhost One IP multiple laravel project [duplicate]

The problem is that I have only one domain name on which three different products need to be run (two of them PHP based and one python). So I need to treat the path in the URL as a different virtual host; i.e.:
www.domain.com/first_URL/
www.domain.com/second_URL/
www.domain.com/third_URL/
Where the first to third will act as separate virtual hosts.
How can I do this?
This can be achieved by using the Alias or AliasMatch directive:
Alias /first_url/ /var/www/first_url_resources
More details can be found in Apache Module mod_alias.
A "virtual host" in Apache works on domain names only, not on parts of the path. You cannot achieve what you want.
This example explains how to assign a different PHP version per directory. It can also be adapted to add Python support by running the Python interpreter as fast_cgi on a particular port.
For the purpose of the example, I assume there is a separate directory for each PHP version and they are named according to the PHP version that runs them, but this can be adjusted.
mkdir /home/user/www
mkdir /home/user/www/5.6.5
mkdir /home/user/www/7.0.2
mkdir /home/user/www/7.0.4
mkdir /home/user/www/7.0.6
Create symbolic links to directories that should be handled by different PHP versions:
sudo ln -s /home/user/www/7.0.2/ /var/www/html/7.0.2
sudo ln -s /home/user/www/7.0.4/ /var/www/html/7.0.4
sudo ln -s /home/user/www/7.0.6/ /var/www/html/7.0.6
Then add the following lines to /etc/apache2/sites-enabled/000-default.conf in default virtual host *:80
(For your needs, you can set up one more FastCGI handler here for the website that requires Python). I assume PHP 5.6.5 runs on port 9999, 7.0.2 runs on port 9998, etc.
DirectoryIndex index.html index.php
ProxyPassMatch ^/5.6.5/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9999/var/www/html/
ProxyPassMatch ^/7.0.2/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9998/var/www/html/
ProxyPassMatch ^/7.0.4/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9997/var/www/html/
ProxyPassMatch ^/7.0.6/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9996/var/www/html/
Assuming your server is pointed by example.com, you can test it on:
http://example.com/5.6.5/
http://example.com/7.0.2/
http://example.com/7.0.4/
http://example.com/7.0.6/
You probably want to do something with the apache-config directives, since you're asking for a virtualhost solution. Apache can only work with virtualHosts as actual domains, as cweiske explained.
The solution in this case would be to either use a .htaccess file in the sub-directories you're working in, or to set up a <Directory "/web/root/subdir">..</Directory> block within your current (virtual-)host configuration.
You could also choose to host them on different sub-domains if you per se want to run them as VirtualHosts ('app1.domain.org').

OXID starting on localhost/source, I want to start it at localhost

My OXID store starts on localhost with http://localhost/source, but I just want it to start with http://localhost.
You need to change the DocumentRoot setting in your httpd.conf file. You also have to change the corresponding Directory Setting in the same file. Both should point to the "source" directory. How do I change the root directory of an Apache server?
In your Oxid installation you then have to change the "sShopURL" setting in config.inc.php to http://localhost/, and additionally you have to change "RewriteBase /source" to "RewriteBase /" in your .htaccess file (both of these files are in the "source" directory of your shop).
Remember that you have to remove the write protection from the config.inc.php file in order to edit it. One more Tip: if you are using xampp you can edit the httpd.conf file and restart apache in the xampp control panel.

Change php.ini location

Is it possible to change the location of php.ini to be used by Apache? When I did php -i | grep 'Configuration File', the result is:
Path => /usr/local/etc
Loaded Configuration File => /usr/local/etc/php.ini
But the result of phpinfo() is
Configuration File (php.ini) Path : /etc
I can copy over php.ini from /usr/local/etc/ to /etc/, but is it possible to change the php.ini folder?
I installed PHP using homebrew and I am using OS X Snow Leopard.
PHP uses different .ini files when running via command line vs running as a web server module. When you grep the results of php -i your getting the command line ini. It's good practice to have separate ini's for the two environments.
If you must change the directory PHP looks for the php.ini file, you can use the PHPIniDir in your web server conf file.
If you wish to just add additional directories to be scanned, you can set the PHP_INI_SCAN_DIR environment variable.
To Change php.ini file path we have to declare PHPINIDir in the apache configuration file 'httpd.conf' syntax for that is :
PHPINIDir "path_to_ini_file";

include_path is not updated as specified in php.ini

I set up include_path in php.ini.
Then I call phpinfo()
And include_path differs from that I specified in php.ini.
What can cause this?
I modified the same php.ini as specified in "Loaded Configuration File" in phpinfo() call.
php is called via apache module, I restarted apache - this also does not help.
I use Windows Vista, Apache/2.2.14 (Win32) PHP/5.3.1
I calls set_include_path("...") in the beginning of my php file, but this is good for temporary workaround only.
One possibility is that there's a .htaccess file somewhere that is getting in your way. You can override php.ini settings in .htaccess files. E.g, in your .htaccess:
php_value include_path <path>
Paste your include_path= entry from your php.ini. I know php.ini entries have to be on one line and you need to have your directories separated by colons, but otherwise theres no trick to it.
you need to make sure that your include_path starts with ".:" .

Creating a symbolic link in Sites directory

I have a file in my ~/Sites directory that works fine when I browse to it through coderama.local/~coderama/index2.php
Now I want to get tricky and move my index2.php file to somewhere else on my system, so I do this by creating a symbolic link. However, when I try to access coderama.local/~coderama/index2.php I now get the following error.
Any ideas anyone?
Thanks!
Forbidden
You don't have permission to access /~coderama/index2.php on this server.
That's a configurable Apache option. It appears that by default on Macs (and probably most installations) Apache is configured to not follow symbolic links. I'm guessing (as others mention above) that it's for security purposes.
But it can be really convenient at times to enable following of symbolic links, particularly during development of certain kinds of apps. What you need to do is 1) change the Apache configuration to allow the following of symbolic links, and then 2) restart Apache.
The configuration step is performed as follows:
a) cd /etc/apache2 (this is where Apache's configuration files are by default on a Mac)
b) you'll see a couple of directories here. One is called users
c) cd users
d) ls should reveal a .conf file with your login name (login.conf) I'm "marvo" so mine is named "marvo.conf"
e) Edit this file (I use vi) -- but you have to do it using sudo:
sudo vi marvo.conf
f) You'll see something like
<Directory "/Users/marvo/Sites/">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
g) Add the "FollowSymLinks" option so that the second line of that .conf file looks like:
Options Indexes MultiViews FollowSymLinks
(You can find other configuration options out there on the 'net. I found this page: http://httpd.apache.org/docs/2.0/mod/core.html#directory )
h) Save the file.
Now you have to restart Apache so that it picks up the configuration change. Googling around a bit, I found that this is most easily done from the command line with the following command:
sudo /usr/sbin/apachectl restart
(Found that at http://mcapewell.wordpress.com/2006/09/22/restart-apache-in-mac-os-x/ )
Now that symbolic link should work just fine on your Sites pages.
Had the same issue. Unfortunately, Marvo's answer wasn't enough.
The problem lies with the permissions set on every folder in the path, starting from ~/. The directories needs the execute flag set to be able to recurse the directory tree. So, in my case, I symlinked a theme folder from ~/Dropbox/projects/theme to a wordpress install on ~/Site/wordpress.
The answer was:
chmod a+x ~/Dropbox/
chmod a+rx ~/Dropbox/projects
This is an old issue, but if anyone reaches this page, it might be useful. :)
Seems like a security issue (also suggested by Matt)
http://discussions.apple.com/thread.jspa?threadID=1771399
I don't remember the specific reason why, but it doesn't work. It's a security issue. You can use XAMPP http://www.apachefriends.org/en/xampp-macosx.html or MAMP http://www.mamp.info/en/index.html to get around this.
In addition to Marvo's answer. What helped me was to Change the permission on Documents folder:
cd ~
chmod a+rx Documents/
Also make sure you have a directive in your httpd-vhosts.conf
Otherwise you get the same '403 forbidden in the browser', with 'the client denied by server configuration in the error log.

Resources