In my /etc/apache2/httpd.conf, I open it.
LoadModule php5_module libexec/apache2/libphp5.so
my vhost config
I want to ask how does apache work with the php code.
When I update the php code. I need not to send any commands to apache. I send a request to the apache, I get the right response as the updated php code making.
Does apache read the php code file when it handle every request.
Or does apache read the php code first time, then parse it, then save the parsed code into apache runtime memory? When the php file update, apache catches the system signal, reloads its runtime memory
Apache as a web server doesn't understand/know your file if it doesn't know its mime_type. So, first thing before parsing any file it checks its extension in mime.conf file and gets its mime_type based on that it parses the file. Now if your file is PHP it will start parsing it since apache is loaded with all the enabled modules one of them is libphp.so which contains the php parser and all the php methods definitions.
Related
I work on a shared server that has multiple php versions. I read on the internet that simply adding a .htaccess file with the following line in my folder dictates what version of php will be used when the scripts in that folder run: "AddHandler application/x-httpd-php52 .php"
After adding this line when i call myScript.php i get the actual content of the file
<?php
phpinfo();
?>
Accessing the script in the browser downloads a copy of the script
What am i doing wront ?
If your browser is downloading the script that means the php module or handler is not loaded.
check the php module in httpd.conf. do not forget to restart apache.
I'd like to put in place a php logging script inside an .exe file (which is a plain text file anyways, to log additional things not shown up in apache logs, whos accessing for example /joomla/ecard.exe and further processing of malicious access attempts) - and no i don't run a joomla there :) ). The logging/processing part is no problem, but Apache always treats the .exe as octet stream and thus firefox is downloading the .exe instead of executing the php code inside it.
I repeat: I don't want to execute an exe (what would require a windows host anyway and run through phps exec command) I'd like to have an exe treated as a php script.
I've already tried to modify the .htaccess file and change the Handler / Type of exes, but with no luck. Last test was like this:
cat .htaccess
AddHandler application/x-httpd-php .exe
AddType application/x-httpd-php .exe
Any ideas? It could have something to do with the file magic / MIME-TYPE?
I'm currently in the process of moving a Wordpress and Drupal website from a hostgator account to a VPS purchased by the client. The VPS has "WHM vps" installed.
I've had a whole lot of problems with this for such a simple task (such as the provider having deprecated configuration options in the my.cnf file causing MySQL to not startup correctly, and having to import a ridiculously large database from Drupal causing all sorts of problems).
But the most recent problem I've run into is the site simply not executing and just returning an Error 500. PHP is installed, but I can't find the PHP5_Module in the Apache Modules, instead there is "suphp_module" which is a shared module. PHP Error Reporting is switched on, as is error reporting in the .htdocs file.
If I add AddType application/x-httpd-php .php to the mime type it just causes the PHP files to download upon being loaded.
I'm honestly running out of ideas here, is it because php is not correctly installed, do I have to reinstall php5?
EDIT: Added the Apache Logs, not sure if the first line has anything to do with it however.
SoftException in Application.cpp:357: UID of script "/home/creative/public_html/index.php" is smaller than min_uid
Premature end of script headers: index.php
You have to assign the php to other owner and group as it is probably assigned to root:root that isn't secure, so the system prevent the execution
You can assign the webserver user and group that is likely to be apache if you're running httpd
I am trying to setup a basic apache 2 webserver just for testing purposes. I have apache 2 installed on Ubuntu 11.10. I can access the root directory on the webserver just fine by going to "localhost" in my browser. This is all located in the default directory: /var/www. However, the problem starts whenever I try to access the subdirectories of my webserver. So, for example if I goto "localhost/phpproject/", which has an index.php file listed in it (and I did test to make sure PHP was working correctly), all it seems to want to do in my browser is attempt to download a file when I type in the address instead of actually displaying anything.
I even tried to give full permissions on the subdirectory to make sure it wasn't just a permissions-related problem. Any ideas?
First of all, you shouldn't be keeping your development files in /var/www folder. Configure your apache to keep your web files within your home directory. In doing so, you don't have to have sudo privilege to edit files in /var/www. If you want to follow my setup, create a directory called www in your home folder /home/yourname/www. Look at my config of /etc/apache2/sites-enabled/000-default
http://pastebin.com/3gcE59Lh
It works good for me.
If you change your config like this, make sure to restart apache [sudo service apache2 restart]
Make sure that you installed PHP correctly and registered PHP in your Apache configuration.
This is the key here, it looks like it's sending you the index.php file, test a PHP file in the main folder behind this sub-directory and see if it tries to download it.
File Could just be:
<?php
phpinfo();
See if putting that in index.php in the parent folder gives you a phpinfo page or tries to download index.php.
If it tries to download it it's just that PHP is not configured in apache to handle files that end in .php
To configure it, add the following lines to your httpd.conf file
LoadModule php4_module modules/libphp4.so
#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288
</Files>
AddType application/x-httpd-php .php
Make sure that you installed PHP correctly and registered PHP in your apache configuration.
The manual should explain the required installation steps in detail.
in Ubuntu you should install the LAMP option using tasksel at the CL. That will give you Apache, MySQL and PHP all working together. It sounds like you may have installed them separatley and have not configured PHP correctly. mime types determine the servers handling of specific file types.
apesa#ubunt$ sudo tasksel
Follow the prompts
EDIT:
We used to make all the config changes in httpd.conf. If you used package manager, like you did then you will have a distributed configuration environment. You will need to go to etc/apache2/mods enabled and look in the php.conf file. There are directions inside. It sounds like you need to make sure the web server understands the directories and FS locations. Look at #Chrispy example. You won't be using the first line as the php module in your env are loaded via php.load and the config is done in php.conf. That AddType directive is important and tells the server to exec your file instead of serving it. have a look. BTW, the Apache Project supports one of the best listservers out there at URL:http://httpd.apache.org/userslist.html
I want to create a Chrome app, but I have the same problem as this guy. When I add the .php extension and I run the app, it downloads the file.Should I do something more? I have installed PHP (if that means to download and extract the file in the same folder with my app, I'd be wrong). I'm a beginner... :(
EDIT
Some of you told me to install Apache or IIS. I said earlier that I want to create a Chrome app.
Do I need to install Apache? Where would I run it (I don't have a local host, Chrome extensions and apps use the "chrome-extension://" prefix, which means it is hosted on the browser). What about more information (you've all been helpful by now)?
EDIT 2
It turns out that Google Chrome doesn't allow developers toto run PHP inside Chrome apps.
Thanks for your help!
This means the server is either missing the PHP plugin (either CGI or otherwise) or the the server doesn't recognize that it must pass a file with the extension in to PHP for pre-processing.
If you're on a host out of your control (e.g. using GoDaddy) then make sure they allow PHP (some of the free hosts won't have PHP as they deam it an unnecessary security risk). If it's your own server, make sure you installed PHP and it's enabled.
If it DOES has PHP installed, but you're not getting it to parse, you'll need to bind the .php extension to the PHP handler using either an .htaccess file or the config.
For apache, your http.conf needs the following (assuming you already have PHP plugin):
AddType application/x-httpd-php .php
Or for something more broad, place an .htaccess file with the above code in your hosted directory.
EDIT
You mentioned you installed PHP. I'm going to assume you're using Apache, as IIS now has a Web Extensions installer that would (typically) take care of the "hard part" for you. So, having said that, open your http.conf (Usually located in C:\Program Files\Apache Software Foundation\Apache2.2\conf\ [using 2.2 as a demo version]). Within that file, at the bottom, add the following [replacing files paths to those that correlate to your own install]:
LoadModule php5_module "C:/php/php5apache2_2.dll"
AddType application/x-httpd-php .php
PHPIniDir "C:/php"
A better reference can be found by googling "install PHP [version] on [webserver]". Here's just one of the results I was able to locate.
Do you have a server installed on your machine? PHP is a server-side script & unlike Javascript you cannot run it without a server.
PHP files are server side code only. So you need to install a local server like APACHE to get the PHP script to execute.
PHP must be run on a web server, not your desktop. Install PHP on your webserver, then open the PHP file from a web browser via: http://localhost/yourfile.php
You need an Apache server on your computer. download xampp: http://www.apachefriends.org/en/xampp.html and put your files in the htdocs folder.
EDIT:
This will explain how to install a PHP environment: http://www.tanguay.info/web2008/tutorial.php?idCode=phpDevelopmentQuick