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
Related
Good day friends,
I know that similar questions exist for deploying a Symfony 2.7 application on shared hosting with CPanel. But in my case I do not have access to SSH. Therefore installing via Composer is out of question.
To work around it I have copied the entire sources into a sub folder in "public_html" folder. When I try to configure Symfony using "web/config.php" it gives some pre-requisites issues. To resolve this I have copied custom "php.ini" in my sub folder and also added the ".htaccess" file to root of "home/user" with following content
SetEnv PHPRC /home/user/public_html/subfolder/php.ini
But still the setting is not taking affect. Do i need to ask the hosting provider to restart the web server ? this wont be easy since it is shared hosting.
Please suggest any alternative way
Your custom .htaccess is not used by the application.
Try to add the SetEnv in the public_html/web/.htaccess that is used to browse your application.
If this has no effect, a working way is to add the following in the VirtualHost of your application:
<VirtualHost *:80>
PHPINIDir /home/user/public_html/subfolder/php.ini
</VirtualHost>
But that involves to restart apache once.
EDIT
If PHP run as CGI:
Create a wrapper script called phpini.cgi to export the directory that contains the php.ini file as PHPRC.
#!/bin/sh
export PHPRC=/home/user/public_html/subfolder
exec /path/to/cgi-bin/php5.cgi
In your /home/user/public_html/web/.htaccess add the following lines:
AddHandler php-cgi .php
Action php-cgi /cgi-bin/phpini.cgi
If php run as CGI with wrapper (for FASTCGI):
You should already have the following wrapper script:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php5.cgi
Change it to:
#!/bin/sh
export PHP_FCGI_CHILDREN=3
exec /path/to/cgi-bin/php.cgi -c /home/user/public_html/subfolder/php.ini
More informations and alternatives in the source.
I hope this solves your problem, it should if you are sure you are php run as cgi/fast-cgi.
How can I see a webpage with extension php without uploading it to the server?
I want to be able to see php files offline in order to preview a page before uploading it to the server.
My searches revealed that I need to have php installed. My OS is Ubuntu, and I did install php5 and apache2, but I can't figure out how to setup the server in order to see my files which are in /home/user/WWW
Is it possible to have a clear explanation how to setup a server properly and how to make it "see" my webpages? I'm not very advanced in web designing. I just want to design a simple webpage displaying my research. I found that writing in php makes things like header, footer easier to include in every page. On the other side, I really want to preview the files before uploading them...
Change the directory DocumentRoot in httpd.conf and restart your Apache server
#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/home/user/WWW"
If you just want to test your PHP without serving a Web page you can run php at a shell prompt with
$ php myScript.php
(see also How can I run a php without a web server?)
As suggested by Ologho Cyril Paul in its comment, XAMPP does the trick. It is easy to install, and its visual launcher has a config button which lets you change the DocumentRoot to your preferred folder. Once the server is active, typing localhost/your_site in your browser leads you to the webpages.
After changing all .html files into .php I found out that it is possible to make php code work in html. Too bad everyone says "it is not possible"... Just make a file called .htaccess in the folder containing your html files and add to it the following line:
AddHandler application/x-httpd-php .html
Now you can write .php code in html. (this was taken from other questions like this)
With the Apache and php pre-installed on OS X Mountain Lion, here are the steps I thought sufficient to run a server locally—without installing MAMP (which would install duplicates):
Uncomment the line LoadModule php5_module libexec/apache2/libphp5.so in /etc/apache2/httpd.conf.
Add the appropriate /etc/apache2/users/calaf.conf.
Save the php example above in ~/Sites/introductory-example.html (correction)
Restart Apache by running sudo apachectl start (or sudo apachectl restart).
Save a file containing <html><head><title>Example</title></head><body><php? echo "Hi"; ?></body></html> (or rather, be precise, this one) twice—first in /Library/WebServer/Documents/introductory-example.html and a duplicate in ~(whoami)/Sites/introductory-example.html).
I now expect that pointing to either http://localhost/introductory-example.html or to http://localhost/~calaf/introductory-example.html will give me a page with two features:
The title of the page is "Example".
The body of the page is "Hi."
Whether I am looking at the introductory-example.html in /Library/WebServer/Documents or in ~/Sites/ I get the first (the title is correct) but not the second (the body is empty)—why?
I ways symlink /Library/WebServer/Documents into my home folder, and change apache to run as my user instead of the default user. Also you need to enable htaccess for most PHP code (set AllowOverride to "All" I think) and probably install MySQL (the official pkg installation will work out of the box with apple's pre installed PHP).
If you aren't comfortable configuring apache, then MAMP is a good idea.
To my knowledge PHP is not activated system wide. It isn't in any system and/or combination I ever tried anyways. Apache is running PHP for files in a particular folder only (and its sub-folders). The standard apache folder should be in:
/Library/WebServer/Documents/
This guide should get you up and running although I haven't tried it myself.
EDIT:
You need to save a file which contain PHP code in .php, not .html. Rename or re-save the file to introductory-example.php
The following URL do not work since the path does not exist.
http://localhost/Users/calaf/Sites/introductory-example.html
Use the following URL (you maybe need to remove the tilde ~)
http://localhost/~calaf/introductory-example.php
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
I'm starting to unravel the mysteries of PHP and I configured the pre-installed Snow Leopard PHP and activated the Apache server in the system preferences. So far so good: it works if you put a PHP file in your ~/Sites directory.
Since I've my projects in a code/projects directory I created a symbolic link from the ~/Sites dir to the code/projects/one-project/php-dir and bang!, a 403 error: access forbidden.
I've been changing the permissions of the dirs to 777, but no luck.
Is anyone using the default Snow Leoapard configuration for PHP development and if so, how do you link to your codebase?
Thanks in advance,
Juan
Off the top of my head: it might be the FollowSymLink option in the Options directive of Apache (http://httpd.apache.org/docs/2.0/mod/core.html#options).
That might work if you set FollowSymLinks in your Apache config, but I suggest putting the PHP files under the web root directly.
One good method is to put the presentation files under the web root, and include/require any libraries directly from where they are in the code/projects directory (assuming that dir is readable by the web server user). The include dir shouldn't be writable by the web server, for security. Keep it owned by your user account, and set the permissions to 744.
I presume you have ~/code/projects/projectA/php-dir and ~/sites/php-dir
You need to make sure that the directory above the directory you're sym-linking is readable by the webserver. In this case you need to set the permissions on the folder to 755. Or at least that solved things for me.
you'll most likely need to add a Directory directive to your httpd.conf file as well...
<Directory code/projects/one-project/php-dir>
order allow,deny
allow from all
</Directory>
Above configuration allows access from all IP's, all hosts.
I myself use macports, I find it better since it isolates everything in the /opt directory. But it's a bit of work to get it running...