LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 07-28-2010, 11:36 PM   #1
scotty2024
LQ Newbie
 
Registered: May 2010
Posts: 17

Rep: Reputation: 0
Question apache2 and php5


Hello, I am trying to get apache2 and php5 running. I have installed both apache2 and php5 (apt-get install apache2 and apt-get install php5) as well as libapache2-mod-php5 (apt-get install libapache2-mod-php5).

When I try to open a php page in my browser it prompts me to download the file. What am I missing?

Thanks.
 
Old 07-29-2010, 03:12 AM   #2
konzo
Member
 
Registered: Dec 2008
Location: Bulgaria
Distribution: Debian / Slackware / Ubuntu
Posts: 230

Rep: Reputation: 34
When you ran apt-get install all dependencies are installed too.
(you can also run apt-get install apache2 php5 ... as one command)

try this:
- give more information about the site you load. Try to open the default site of apache in /var/www/index.html It should give "It works!" msg
- review your config files(chech you set ip address, port, etc.)
- OR probably you have to edit headers with header function. See php manual for header(), Content-type

Last edited by konzo; 07-29-2010 at 05:49 AM.
 
Old 07-29-2010, 06:36 AM   #3
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Could be your browser is not reloading the site but displays the cached result?
Apache has to be restarted after the changes but debian based systems should do that automatically...
 
Old 07-29-2010, 09:18 AM   #4
scotty2024
LQ Newbie
 
Registered: May 2010
Posts: 17

Original Poster
Rep: Reputation: 0
Hi Thanks for the replies,

When I enter 127.0.0.1 I see the "It works!" message. I have read that there are some config files that may need to be set. I'm not sure which ones or what needs to be entered. Could you give me more information on that.

I am currently not at the computer that I am trying to install this on, so I will post back the additional details you have requested later.

At this point would it help to do apt-get install apache2 php5 or is it too late for that?

Thanks.
 
Old 07-29-2010, 09:53 AM   #5
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
you already installed it as you said, so running again wouldn't do much.

if you want to be on the 110% sure side, run
apt-get purge apache2 php5
followed by
apt-get install apache2 php5

even if you do it separately, as you did initially, once php5 is installed, the apache server gets restarted.

the config file you may need to adjust is
/etc/php5/apache/php.ini for the apache php config, and, if you want to run shell scripts with php
/etc/php5/cli/php.ini

what could cause the error is that the libapache2-mod-php5 hasn't been symlinked properly (or apache not restarted after installation)

make sure that in
/etc/apache2/mods-available there is the php5.conf and php5.load file. if they are, check if they're symlinked to
/etc/apache2/mods-enabled

symlink them if not, restart apache, insert a php file into the current apache2 docroot for testing purposes and post what happens
 
Old 07-29-2010, 01:24 PM   #6
scotty2024
LQ Newbie
 
Registered: May 2010
Posts: 17

Original Poster
Rep: Reputation: 0
/etc/php5/apache/php.ini exists but is a huge file. Is there anything specific that I would need to edit?

php5.conf and php5.load exist in /etc/apache2/mods-available and they're symlinked to /etc/apache2/mods-enabled.

I inserted a test.php (<?php echo 'Hello World!'; ?>) page into /var/www and hit it in my browser http://127.0.0.1/test.php. The page loaded fine and the echo 'Hello world' output. However, when I try to open the same php file from my desktop or other directory by dragging it into firefox, it prompts me to download the page. Do I have to move all my php files into /var/www?

Thanks
 
Old 07-29-2010, 03:05 PM   #7
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
Quote:
Originally Posted by scotty2024 View Post
/etc/php5/apache/php.ini exists but is a huge file. Is there anything specific that I would need to edit?
Well, if you want to work with PHP, having a look at the ini file is a good move.

If you want to have PHP files working in a browser on your local box, you need to set up a virtualhost for apache for each directory, e.g. your
/home/user/php
/var/development/php
etc.

you won't need to create virtualhosts for subdirectories in above directory examples.

running php scripts through the command line interface can be done anywhere w/o needing to configure any apache virtualhosts
 
Old 07-29-2010, 03:28 PM   #8
scotty2024
LQ Newbie
 
Registered: May 2010
Posts: 17

Original Poster
Rep: Reputation: 0
I want to work with php file on my local machine. If I put the files into /var/www/ they seem to work but don't work in other locations. Does this mean it is working correctly?

How do I run a php file from command line?

I am willing to edit the php.ini config file but I am not sure what to edit. Can you help me with anything specific I should edit within that file?

Thanks.
 
Old 07-30-2010, 04:22 AM   #9
konzo
Member
 
Registered: Dec 2008
Location: Bulgaria
Distribution: Debian / Slackware / Ubuntu
Posts: 230

Rep: Reputation: 34
Quote:
Originally Posted by scotty2024 View Post
However, when I try to open the same php file from my desktop or other directory by dragging it into firefox, it prompts me to download the page.
Well, you should not expect to open php file in browser, because it is server side. This mean that the server should parse and execute it and give the output contents to the browser. The browser didn't recognize or parse php tags and functions. They are executed only in the server.

Edit: here is some info about server side programming
http://en.wikipedia.org/wiki/Server-side_scripting

You can find more on internet.

Last edited by konzo; 07-30-2010 at 04:24 AM.
 
Old 07-30-2010, 04:23 AM   #10
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
if they work in /var/www, then your php installation works.

running a php file from command line is done easily through

Code:
~%> php myscript.php
that of course won't show you html stuff. it's quite useful as a scripting tool however for many tasks.

read through the comments in php.ini. Granted, the php.ini since 5.3. has gotten bigger, but mostly because they added some more comments. Keep in mind, you do not edit this file for the locations where PHP will work by accessing the files through your apache server.

You need to set up apache config files for that.

Have a look at
/etc/apache2/sites-available

In it should be at least one file, named
default

which contains a Virtualhost.

In short:
copy the file, adjust the "DocumentRoot" in it, symlink the file to /etc/apache2/sites-enabled, restart/reload apache2

In long:
copy the file, check if you need the Directory settings in it, remove all unnecessary stuff (e.g. the cgi-bin, /usr/share/doc), set up the Log files (mostly just rename it from access.log and error.log to something else,specific for this virtualhost, to keep it separate from the other log entries of other virtualhosts)

Adjust the DocumentRoot to the path where you want to have php working through apache2.

Put some thought into this, set up a structure where you want all your web sites to be. Usually
/var/www is good enough, but of course you can also set up
/var/development, or /home/myuser/myphpstuff/

Further, you can also include php files in your scripts which aren't in the document root, e.g. following:

your docroot is /home/myuser/myphpstuff
your site is running via /home/myuser/myphpstuff/website2
using php's include/require functions, you can include files from, say,
/home/myuser/someotherscripts/script1/lib/
 
Old 07-31-2010, 04:14 PM   #11
scotty2024
LQ Newbie
 
Registered: May 2010
Posts: 17

Original Poster
Rep: Reputation: 0
I am unable to connect to my mysql db. I get the error "Fatal error: Call to undefined function mysql_connect()".

I checked phpinfo() and there is no reference to MySQL. I believe this means that my install of PHP doesn't support MySQL. Do I need to uninstall and reinstall with a version of PHP with MySQL support?
 
Old 08-01-2010, 03:57 AM   #12
konzo
Member
 
Registered: Dec 2008
Location: Bulgaria
Distribution: Debian / Slackware / Ubuntu
Posts: 230

Rep: Reputation: 34
Here is possible solution of your problem:

http://www.somacon.com/p109.php

Good luck!
 
Old 08-01-2010, 10:52 AM   #13
rsciw
Member
 
Registered: Jan 2009
Location: Essex (UK)
Distribution: Home: Debian/Ubuntu, Work: Ubuntu
Posts: 206

Rep: Reputation: 44
Probably all you need is to run
sudo apt-get install php5-mysql
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache2+php5 sunescan Linux - Software 2 12-18-2008 04:54 AM
Apache2 and php5 barrythai Mandriva 2 05-08-2007 08:09 AM
Apache2 and PHP5 SpiderIRE Linux - Software 3 09-30-2005 03:25 PM
Apache2 and PHP5 rul3r Slackware 7 09-11-2005 05:21 PM
Apache2 + PHP5.0.3 24jedi *BSD 1 07-21-2005 03:07 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration