Trick PHP running behind mod_php and change host and protocol - php

I'm migrating legacy apps to docker and I need to "trick" php into thinking that it runs on the exact same environment as it used before.
Basically, the app used to run on an apache2 with mod_php and the PHP code does something somewhere that says "If you've been called with HTTP, set the link for the images to http."
My docker image is now accessible locally with http only. But I would like to still fake PHP into thinking that it has been accessed with HTTPS.
I suppose that Apache should rewrite the $_SERVER['HTTPS'] variable but I can't find in the documentation how I could do that.
Here is my current configuration for my app:
<VirtualHost *:8080>
DocumentRoot "/var/www/app"
<Directory /var/www/app>
Require all granted
Order allow,deny
Allow from all
Options Indexes FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>

Related

using PHP within WAMP- how can I create new directories on my local drives?

I am trying to use PHP within my WAMP environment to create new directories (checking if they exists first) on a local drive (U:) which is mapped to a media server (\tr-svrwc-fms)- with no success: I receive a 403 error.
I've tried creating directory Aliases:
Alias /vid "tr-svrwc-fms//"
<Directory "tr-svrwc-fms//">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>
and also:
Alias /vid "U:"
<Directory "U:">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order Allow, Deny
Allow from all
</Directory>
I've even tried modifying the root directory settings in httpd.conf to "Allow from all".
my WAMP server version is 2.2 with Apache version 2.2.21
thank you in advance for your help
It is recommended to only use only UNC paths for network resources in httpd.conf
The syntax should look something like this:
Alias /vid "//laptop1/vid"
<Directory "//laptop1/vid">
...
</Directory
Where laptop1 of course will be different in your case.
I've learned that with WAMP installed on my local hard drive, the Apache server (as configured) does not allow for communication outside of the WAMP root folder due to permissions.
This type of communication can however be accomplished via a PHP shell script on the Command Line which doesn't route through the Apache Server.

Django and Php Sites on single Apache Server

I have a Django site running on ec2 instance (ubuntu) on apache2 using mod_wsgi. I have placed it in /var/www/django_project. It is Up and running without any issues. Now i want to host another site (php, mysql) on this ec2 instance only. I tried to configure my httpd.conf and added php directory with proper permissions, but I believe due to Alias setting in mod_wsgi, any request above '/' is taken up by django.
I DO NOT have any domain name. I access my Django site with IP of machine (i.e w.x.y.z/django_app).
Correct me if I am wrong : Since i do not have server name, I cannot have both site running on port 80 using virtual Hosts.
And I do not mind running them on different ports either. Please suggest me a way to host php site on this server. which file to configure and how to configure it.
My httpd.conf file:
Alias /static /var/www/resumerepo/static
<Directory /var/www/resumerepo/static>
order deny,allow
Allow From All
</Directory>
WSGIScriptAlias / /var/www/resumerepo/resumerepo/wsgi.py
WSGIPythonPath /var/www/resumerepo
<Directory /var/www/resumerepo>
<Files wsgi.py>
Order deny,allow
Allow From All
</Files>
</Directory>
It works fine and my app is accessible. However if i put it in one virtual host and make another virtual host, apache restart throws an error saying PythonPath can not be in virtual host.
You can't do this easily if your django project is accessible via the root of your domain (or your IP), for example: http://1.2.3.4 -> leads to your django project`.
I think, one solution could be to move your django project to a subdirectory, like http://1.2.3.4/django, and make your php project also accessible in subdirectory, like http://1.2.3.4/php.
Or you can create a new virtual host, listening on port 8080, for example, for your php project. This way :
http://1.2.3.4 leads to your django project
http://1.2.3.4:8080 leads to your php project
The second option may be easier to set up, as you won't have to change config for your django project.
Your vhost file could look like :
<VirtualHost *:8080>
ServerAdmin contact#yourdomain
DocumentRoot /var/www/php
<Directory /var/www/php>
AllowOverride All
Order allow,deny
Allow From All
</Directory>
</VirtualHost>
Maybe this won't work : according to Apache documentation, you should not use virtual hosts without ServerName.

Running Rails applications with Passenger alongside PHP applications

I'm setting a server where I will need to run Ruby On Rails 3 applications along with some PHP websites.
The server is a CentOS 5.8 machine running Apache 2.4.3.
The server is for testing and PRE-production, so performance is not an issue.
I'm using Phusion Passenger for the Rails apps, and I've created a bunch of virtual-hosts (with associated folders and DB accounts).
Then, I'm planning to use other v-hosts for PHP.
Is it possible? How should I proceed?
Thank you very much
details:
httpd.conf:
LoadModule passenger_module /app/auser/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17/ext/apache2/mod_passenger.so
PassengerRoot /app/auser/.rvm/gems/ruby-1.9.3-p286/gems/passenger-3.0.17
PassengerRuby /app/auser/.rvm/wrappers/ruby-1.9.3-p286/ruby
(...)
##
## Virtual hosts
Include conf/extra/httpd-vhosts-phpmyadmin.conf
Include conf/extra/httpd-vhosts-rails01.conf
Include conf/extra/httpd-vhosts-rails02.conf
Include conf/extra/httpd-vhosts-php01.conf
Include conf/extra/httpd-vhosts-php02.conf
....
Passenger-managed v-hosts will be like:
Include conf/extra/httpd-vhosts-rails01.conf
<VirtualHost *:80>
ServerName rails01.lcl
DocumentRoot "/app/auser/apps/rails01/public"
<Directory "/app/auser/apps/rails01/public">
AllowOverride all
Options -MultiViews
</Directory>
</VirtualHost>
PHP-based v-hosts will be like:
Include conf/extra/httpd-vhosts-php01.conf
<VirtualHost *:80>
ServerName php01.lcl
DocumentRoot "/app/auser/apps/php01/public"
<Directory "/app/auser/apps/php01/public">
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Yes, Running Rack/Rails alongside PHP definitely works.
There is a really cool gem called rack-legacy which might be what you are are looking for. It allows you to execute PHP code hosted on your Rails application server through php-cgi.
Rack Legacy tries to provide interaction with legacy environments like PHP and CGI while still getting the Rack portability so you don't need a full Apache/lighttpd stack.
I have used for some experiments, and it seems is possible to have a wordpress running and served with the Rails app server without having to mess up with apache/ngix files.

In which directory i should keep my workspace or project

I have installed XAMPP in my machine(Windows XP OS). And I have Eclipse as IDE.
Now my question is, In which directory i should keep my workspace (or project).
Whether I should keep under the path "C:\xampp\php\www" OR under "C:\xampp\htdocs".
You need to change the DocumentRoot value in c:\xampp\apache\conf\httpd.conf from
DocumentRoot "C:\xampp\htdocs"
to
DocumentRoot "E:/MyProject/Source/Admin"
and configure permissions also.
<Directory "E:/MyProject/Source/Admin">
Options +Indexes FollowSymLinks +ExecCGI
AllowOverride AuthConfig FileInfo
Order allow,deny
Allow from all
</Directory>
and then restart the apache server(in xampp control panel). so from there onwards whenever you access http://localhost/ it will execute the files under E:/MyProject/Source/Admin
see for more info.
http://httpd.apache.org/docs/2.0/mod/core.html#documentroot
http://www.apachefriends.org/en/xampp-windows.html#529
Looking at the Where I change the start page? section of XAMP's FAQ (quoting) :
The DocumentRoot folder is
"\xampp\htdocs". There is the
index site (index.php) the real
start page which is loaded after
executing of "http://localhost/".
So, I'd say, in your case, you'll have to work in C:\xampp\htdocs.
Still, of course, you can change that by modifying Apache's configuration and/or creating new VirtualHosts.

Acessing other webapps while one is in document root

I have a Zend Framework project on a local machine, and as recommended its /public subfolder is made a DocumentRoot in httpd.conf. So I access this app simply with http://localhost.
This new requirement makes me unable to access other
web apps in a former webserver root (which contains a few regular php apps and a couple of zend framework apps).
What configuration should I choose to be able to simultaneously access both ZF root-based apps and other apps like PHPMYADMIN?
You'll probably need to use some kind of VirtualHost
You have at least two solutions :
VirtualHosts based on diferent port numbers
For instance, you'd have one site on http://localhost/ (ie, default port = 80)
And another one on http://localhost:8001/
And another one on http://localhost:8802/
And so on
VirtualHosts based on different domain-names
For instance, you'd have on site on http://localhost/
And another one on http://mytestwebsite/
In the second case (the solution I always use), you will have to edit your "hosts" file, so "mytestwebsite" is an alias to your local machine -- which IP address is 127.0.0.1
Under windows, this file is located in C:\WINDOWS\system32\drivers\etc
On Linux, it's in /etc/
You'd have to add a line like these ones :
127.0.0.1 localhost
127.0.0.1 mytestwebsite
Then, in the Apache configuration, you need to create one VirtualHost per site. Something like this, I suppose :
<VirtualHost *>
ServerName mytestwebsite
DocumentRoot /home/squale/developpement/tests
<Directory /home/squale/developpement/tests>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost *>
ServerName myothertestwebsite
DocumentRoot /.../myothertestwebsite
<Directory /.../myothertestwebsite>
Options Indexes FollowSymLinks MultiViews +SymLinksIfOwnerMatch
AllowOverride All
</Directory>
</VirtualHost>
(Needs tunning / configuration, of course)
And you'll also probably need some directive like this one :
NameVirtualHost *
Well, this might not be the entire solution (that one depends on your server / applications) ; but I hope these few pointers will help you get to it !
If you need more help, the keyword is "VirtualHost" ;-)
Have fun !
Zend Framework probably uses a .htaccess file. If so, you might use that to add rules to leave the other apps alone. Another option is to use subdomain (eg phpmyadmin.localhost)

Categories