Why is my PHP source code showing? - apache

So, I added the following to my http.conf file:
Listen443
NameVirtualHost *:443
<VirtualHost *:443>
DocumentRoot /PATH_TO/www
ServerName www.domain.com
SSLEngine on
SSLCertificateFile /PATH_TO/domain.crt
SSLCertificateKeyFile /PATH_TO/domain.key
SSLCertificateChainFile /PATH_TO/intermediate.crt
</VirtualHost>
https://www.domain.com works now, but it displays the PHP source code? What could be the reason for this?

"Server configuration error" is the reason ;-)
It is choosing to serve PHP files as "plain content" instead of handing them to a PHP engine for processing. This doesn't have anything to do with SSL (it will just as happily send the "plain content" over a secure connection).
From PHP: Installation:
AddModule mod_php.c
LoadModule php_module modules/mod_php.so
LoadModule php5_module modules/libphp5.so
AddType application/x-httpd-php .php
And from PHP pages won't load:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
See a pattern? :-) In any case, read the fine installation instructions for the particular platform/server.
Happy coding.

It could also be that your php.ini configuration is set to not parse code between short php tags.

In centos this can happen because of php-module missing, to fix that issue we have to install
sudo yum install php-mysql php-devel php-gd php-pecl-memcache
php-pspell php-snmp php-xmlrpc php-xml

Just type LOCALHOST in your browser. then it will open the http://localhost/htdocs/ location. then navigate to your php file. It will open accordingly.

Related

How to change server name in apache

i want to change server name in apache. i know its easy as we can make changes in apache.cnf and httpd.cnf file. But i am tired after make changes in all file. i have checked all files and configuration but its not work only repdirect to another ip worked. So how can i change servername ??
<VirtualHost *:443>
ServerName xyz.com
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/server.crt
SSLCertificateKeyFile /etc/apache2/ssl/server.key.nopass
</VirtualHost>
Thanks for any help.
This can be achieved by installing Apache mod_security module.
After installation , open the Apache configuration file.
$ sudo vi /etc/apache2/apache2.conf #Debian/Ubuntu
$ vi /etc/httpd/conf/httpd.conf #RHEL/CentOS/Fedora
Now change or add these lines below (make sure to change Tech_Web to any other thing you want to appear to clients).
ServerTokens Full
SecServerSignature “Tech_Web”
Finally restart the web server.

Deploying Mono MVC in shared hosting environment

I'm not posting on serverfault because the application is under development and I need to test it in Mono, but it could be suitable there too...
I would like not to ask if it's possible to deploy an ASP.NET MVC website on Apache2 VirtualHost, because it is, but rather if it's possible without interfering with PHP configuration.
The long question
Apache's default PHP configuration looks like this
<IfModule mod_php5.c>
AddHandler application/x-httpd-php .php4
AddHandler application/x-httpd-php .php5
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .php4s
AddHandler application/x-httpd-php-source .php5s
AddHandler application/x-httpd-php-source .phps
DirectoryIndex index.php4
DirectoryIndex index.php5
DirectoryIndex index.php
</IfModule>
And this tells Apache that .php files are PHP scripts.
OK...
Now if I enable mod_mono on server, it maps .aspx files to Mono. And that's OK.
But when I enable the test host VirtualHost with a barebone configuration that is perfect for PHP (it's based on mod_macro if you mind the dollars)
<VirtualHost *:80>
ServerName www.$name
ServerAlias $name
<IfModule mpm_itk_module>
AssignUserID $user $user
</IfModule>
ErrorLog /path/tp/$name/logs/error_log
CustomLog /path/to/$name/logs/access_log combined
DocumentRoot /path/to/$name/htdocs
ServerAdmin email#email
</VirtualHost>
Then I get a 404 error for the default controller.
I know I can, on my own test server, simply say SetHandler mono and voilà. But the question affects general-purpose hosting. Also, I could have the answer by myself: since there is no .aspx file in Razor-MVC (or better paths are mapped to controllers via routers) then I obviously get a 404 error for everything that Apache doesn't recognize as a file.
If I want to deploy this Mono application on a server run by a generalistic hosting provider that supports Mono, or vice versa if I would like to offer (on a production server) hosting for PHP and Mono too without having to change configuration according to customer's demands, could I use an Apache configuration that both satisfies Mono and runs PHP?
The shortened question
How can I configure Apache2 once in order to run both PHP and Mono MVC on the same VirtualHost without changing the configuration according to language the application is written in?
go to this configurator
http://go-mono.com/config-mod-mono/
it provide auto make config for Apache2, based on virtualHost.
Now i'm using mod_mono and mod_php5 jointly.

suPHP setting user/group to virtual host and using docroot

I am trying to get suPHP working, i followed tutorials and seem to have it installed correctly.
now my issue is this
1) i set docroot in the suphp.conf file, but its set to /var/www by default. The problem I have with this is that my domains are stored under another directory as well. So for instance i have my subdomains in one directory and my regular domains in another. So I get an error thrown to my browser telling me that a domain is resolving to a directory not in the configuration.
2) I would like to know how to use suPHP_UserGroup to set the user/group of a specific domain set under my VirtualHost configuration.
This is an example VirtualHost that I have to better show my issues.
<VirtualHost *:80>
ServerAdmin admin#domain.com
ServerAlias mail.domain.com
DocumentRoot /web/users/domain.com/subdomains/mail/webmail
<IfModule mod_suphp.c>
suPHP_UserGroup mail mail
</IfModule>
<Directory "/web/users/domain.com/subdomains/mail/webmail">
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
When I reload apache I get an error:
Invalid command 'suPHP_UserGroup', perhaps misspelled or defined by a module not included in the server configuration
I configured suPHP with this:
./configure --prefix=/usr --sysconfdir=/etc --with-apr=/usr/bin/apr-1-config --with-apxs=/usr/sbin/apxs --with-apache-user=apache --with-setid-mode=owner --with-php=/usr/bin/php-cgi --with-logfile=/var/log/httpd/suphp_log --enable-SUPHP_USE_USERGROUP=yes
http://www.suphp.org/DocumentationView.html?file=apache/CONFIG
suPHP_UserGroup (expects user- and groupname)
Only supported when compiled with setid-mode "force" or "paranoid" *
Specify the user- and groupname to run PHP-scripts with. This setting
can only be used within a or context.
Example: suPHP_UserGroup foouser bargroup
./configure --prefix=/usr --sysconfdir=/etc --with-apr=/usr/bin/apr-1-config --with-apxs=/usr/sbin/apxs --with-apache-user=apache --with-setid-mode=paranoid --with-php=/usr/bin/php-cgi --with-logfile=/var/log/httpd/suphp_log --enable-SUPHP_USE_USERGROUP=yes
I add the following four lines to my vhost definitions. Line two is relevant to your question.
suPHP_Engine on
suPHP_UserGroup vhost_owner vhost_group
suPHP_AddHandler x-httpd-php
AddHandler x-httpd-php .php .php3 .php4 .php5

get 404 with passenger and rails

I'm trying to run a rails app on a shared hoster.
I create the app in the directory /home/rails_projects/jens_blog and the document root is /home/www/jens_blog.
In the /home/www/jens_blog dir is a symlink public -> /home/rails_projects/jens_blog/public/
I created a scaffold posts. But when i run the mydomain/ or mydomain/posts in the browser I get always an 404 error.
File does not exist: /home/www/jens_blog/public/posts
<VirtualHost ip.port>
ServerName www.mydomain.de
ServerAdmin webmaster#www.mydomain.de
DocumentRoot /home/www/jens_blog/public
LoadModule passenger_module /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /usr/lib/ruby/gems/1.8/gems/passenger-3.0.7
PassengerRuby /usr/bin/ruby
PassengerDefaultUser myuser
PassengerAnalyticsLogUser myuser
CustomLog /home/log/access_log mesos2
<Directory "/home/www/jens_blog/public">
Allow from all
Options -MultiViews
Options FollowSymLinks
</Directory>
</VirtualHost>
if I put a index.php file into the /home/rails_projects/jens_blog/public/ dir the file content will be show.
Can anybody help me?? I am desperated.
I have only a shared web hosting.
Update: I added "PassengerResolveSymlinksInDocumentRoot on" to the apache config. But now I get Exception LoadError in PhusionPassenger::Rack::ApplicationSpawner (no such file to load -- bundler)
:-((
Cheers
Jens
My question was quite similar to yours Deployed rails site on ec2 using capistrano, but it doesn't show up on the browser, here is the site -> http://passionate4.net/
I would say place your site in this directory /var/www/myapp/public.
Use these settings.
ServerName www.passionate4.net
DocumentRoot /var/www/capi_app/current/public
RailsEnv production
Allow from all
Options -MultiViews
I have written couple of blogs on how to successfully deploy the site on Ubuntu. I believe you problem is quite similar to mine. http://recipe4developer.wordpress.com/

How do I conditionally add a line to Apache .htaccess based on the domain?

My local development PC is set up to use PHP5 by default, my client's host (1and1.co.uk) is set up to use PHP4 by default.
To enable PHP5 on a 1and1 account, you must add the following line to your .htaccess file:
AddType x-mapp-php5 .php
If I add this line to my local .htaccess file, it breaks my PHP.
How do I add this line conditionally based on the domain (or some other parameter?) so it is only executed by the live site and not my dev site?
I'd like to be able to just upload (FTP) my entire source tree without worrying about having to remember to edit the .htaccess on the server ever time.
e.g.
<IfDomain www.example.com>
AddType x-mapp-php5 .php
</IfDomain>
... rest of .htaccess
Is this possible?
I don't have access to the server config file, only .htaccess
Thanks in advance.
To others looking at this, and using a local server with virtualhost directives: took me a while, and none of the methods found online worked (probably because my MAMP apache version is not 2.4 yet or something), but this one did.
Forget about adding 'conditional' lines to your .htaccess file: you can define which .htaccess file to use in your virtualhost setting!
So just create a file .htaccess_dev, and add this line to your virtualhost definition on your local / dev machine:
AccessFileName .htaccess_dev
So it becomes something like this:
<virtualhost>
ServerName www.example.local
DirectoryRoot /var/www/www.example.local
AccessFileName .htaccess_dev
</virtualhost>
Try this. I have no idea whether it'll work. The terminology used in the documentation suggests that it should, but since no one ever does what you're trying to do, it's a little up in the air.
<Location http://www.example.com/>
AddType x-mapp-php5 .php
</Location>
I know that you can do server-specific commands in httpd.conf using the VirtualHost tag. (http://httpd.apache.org/docs/1.3/vhosts/ip-based.html)
While I'm not 100% sure that you can use this in a .htaccess file, I would suggest trying the following:
<VirtualHost www.example.com>
AddType x-mapp-php5 .php
</VirtualHost>
You can use the VirtualHost directive to accomplish this. I just did the same when I wanted django with mod_python to run only at a subdomain
<VirtualHost *:80>
DocumentRoot /www/docs/path
ServerName www.example.com
....
AddType x-mapp-php5 .php
</VirtualHost>