/    Sign up×
Community /Pin to ProfileBookmark

php not working on ubuntu

I’ve installed php5 on ubuntu with apache5 and tried to code a $_POST script. After finding out that Echo wasn’t even working, which leads me to think my php5 isn’t installed correctly.

I typed in php -v in my terminal and it came out with

PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May 2 2011 23:18:30)
Copyright (x) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Techonologies

I’ve installed php5 by using Synaptic Package Manager.

Any suggestions? I’m not sure what the next steps are.

my post script is on the top of the script:
<?php
echo “hi”;
if(isset($_POST[‘name’])){
echo ‘hi’ . $_
POST[‘name’];
}

so
when i put form action = “<?=$_SERVER[PHP_SELF’]?>”

the URL is linked to a “Not Found” error page.

Please help!
Thanks in advance.

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@aj_nscAug 17.2011 — If php isn't being parsed, then when you view your php page in the browser (by typing in something like http://localhost/mypage.php - not by opening up mypage.php WITHOUT using localhost, or equivalent) your PHP code would be visible.

So when you type http://localhost/mypage.php in your browser, do you see your PHP code, or do you see it's output?

If you see it's output, then you're fine and it's possible that short tags have been turned off on your install. Generally, it's a good idea to always use full tags <?php echo $_SERVER['PHP_SELF']; ?> instead of <?=$_SERVER['PHP_SELF']; ?>
Copy linkTweet thisAlerts:
@travelprojauthorAug 18.2011 — thanks so much. i was using the file name index.html instead of index.php
Copy linkTweet thisAlerts:
@eval_BadCode_Aug 20.2011 — That's OK. you can keep them .html, just add this to your .htaccess or virtual host file:


[CODE]

<FilesMatch ".html$">
AddHandler x-httpd-php5.3 .html
</FilesMatch>

[/CODE]
Copy linkTweet thisAlerts:
@travelprojauthorAug 20.2011 — thanks for the tip!
Copy linkTweet thisAlerts:
@criterion9Aug 21.2011 — It should be noted that having the php engine parse html files can cause undue strain on the server (especially if you have a ton of html files that do not contain PHP). Additionally, if you are purchasing low-cost hosting you may or may not have the option to alter what type of files the PHP engine parses and you'd then have to refactor all your code to change the extension back.
Copy linkTweet thisAlerts:
@travelprojauthorAug 21.2011 — hnm. thats interesting to know, though I've switched from using php as my backend language to python. using .psp. Though also having complications with not being able to use languages such as javascript, but just trying to handle html + mod_python
Copy linkTweet thisAlerts:
@eval_BadCode_Aug 24.2011 — Ubuntu is incredibly resilient when it comes to adding/removing/purging libraries... somehow it doesn't break like *some* of the other distros.

I included some python here for you. It was meant to work with apache. Pay attention to the # at top, the sys.stderr=stdout, and the printing of headers.

[CODE]
#!/l/python3.1.3/bin/python
import urllib.request
import urllib.parse
import xml.etree.ElementTree as ET
import cgi
import sys

sys.stderr = sys.stdout

class YQLWeather():
_YQL_URI = 'http://query.yahooapis.com/v1/public/yql?'
_YQL_WEATHER_URI= 'http://weather.yahooapis.com/forecastrss?w='
_NOAA_ALERT_URI = 'http://alerts.weather.gov/cap/&#37;s.php?x=1'
woeid = ""
stateCode = ""

def __init__(self, location):
#sprint on argv[1] to form URL
params = urllib.parse.urlencode(dict(q='select * from geo.places where text="%s"' % location, format='xml'))
#fetch URI into xml
root = ET.fromstring(urllib.request.urlopen(self._YQL_URI, params).read())

#iterate and find the woeid and state code
elements = root.getiterator()
for elem in elements:
if elem.tag == "{http://where.yahooapis.com/v1/schema.rng}woeid":
self.woeid = elem.text
if elem.tag == "{http://where.yahooapis.com/v1/schema.rng}admin1":
self.stateCode = elem.attrib['code'][3:]

#use the woeid to get weather XML
self.weatherXML = urllib.request.urlopen(self._YQL_WEATHER_URI + self.woeid).read()
root = ET.fromstring(self.weatherXML)

#grab the YQL weather description
elements = root.getiterator()
for elem in elements:
if elem.tag == 'description':
self.condition = elem.text

## get weather alerts
root = ET.fromstring(urllib.request.urlopen( self._NOAA_ALERT_URI % self.stateCode ).read())

#grab the NOAA alert summary
elements = root.getiterator()
for elem in elements:
if elem.tag == "{http://www.w3.org/2005/Atom}summary":
self.weatherAlert = elem.text
break

def getWOEID(self):
return self.woeid

def getCondition(self):
return self.condition

def getWeatherXML(self):
return self.weatherXML

def getAlerts(self):
return self.weatherAlert

########## MAIN #############

print('Content-type: text/htmln')
form = cgi.FieldStorage()
location = form.getfirst("location", None)
print("<html><head><title>Example Script for WebDev</title></head><body><pre>")

if location != None:
weather = YQLWeather(location)
print(weather.getCondition().replace("http://l.yimg.com/a/i/us/we/52/", "***ignore this line***"))
print(weather.getAlerts())

print('<form method="get" target="_self"><br />Enter your city, state:<br /><input type="text" name="location"><button type="submit">Find the weather</button></form>')

print("</pre></body></html>")

[/CODE]



You can always try asking in the perl/python forum if you have more questions.
×

Success!

Help @travelproj spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...