Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have a fresh installation of Ubuntu 10.10 and I'd like to get PHP to work. I've tried

sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo /etc/init.d/apache2 restart

but when I navigate to http://localhost/ all I see is the the Firefox error page stating "Unable to connect".

Moreover, when I try http://localhost/test.php , instead of the php file being executed, the browser asks if I'd like to download the file.

Here is the error.log file contents:

[Thu May 19 12:04:49 2011] [notice] Apache/2.2.16 (Ubuntu) configured -- resuming normal operations
[Thu May 19 12:05:01 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Thu May 19 12:05:04 2011] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
[Thu May 19 12:12:42 2011] [error] [client 127.0.0.1] File does not exist: /var/www/asd
[Thu May 19 12:13:32 2011] [notice] Graceful restart requested, doing restart
[Thu May 19 12:13:32 2011] [notice] Apache/2.2.16 (Ubuntu) configured -- resuming normal operations
[Thu May 19 12:14:11 2011] [notice] SIGHUP received.  Attempting to restart
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/interbase.ini on line 1 in Unknown on line 0
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/lasso.ini on line 1 in Unknown on line 0
PHP Deprecated:  Comments starting with '#' are deprecated in /etc/php5/apache2/conf.d/ming.ini on line 1 in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - idn_to_ascii in Unknown on line 0
PHP Warning:  Function registration failed - duplicate name - idn_to_utf8 in Unknown on line 0
PHP Warning:  intl: Unable to register functions, unable to load in Unknown on line 0
[Thu May 19 12:14:11 2011] [notice] seg fault or similar nasty error detected in the parent process

share|improve this question
    
Can you post any error messages? Please include your sfotware sources too, you can use the command from How do I find all of my software sources?. –  Lekensteyn Mar 23 '11 at 13:18
    
@Lekensteyn please refer to my comment to @Achu below –  Gaurav Sharma Mar 23 '11 at 13:38
    
BTW I am quite sure that the provided logs are not from the fresh installation and you have installed more than just apache2 and mod_php, namely php5-interbasse, php5-lasso and php5-ming. It's hard to provide correct answer when your question is about something different than your real problem. –  oerdnj Apr 5 '13 at 6:37

5 Answers 5

You can install LAMP running one command

Install tasksel Install tasksel

Select LAMP Server,
enter image description here

Follow the installation process.

After the installation completed you can test your localhost the way you did.

To Check php is working

sudo gedit /var/www/info.php

and past this php info code

<?php
phpinfo();
?>

Save it and exit

restart apache2

sudo /etc/init.d/apache2 restart

you can test php runing info.php file

http://localhost/info.php

share|improve this answer
    
Nothing happens when I run sudo tasksel, check LAMP Server and then click OK. I come back to the terminal. I don't get asked for a mysql root password. –  Gaurav Sharma Mar 23 '11 at 12:04
    
@gaurav if tasksel doesn't work for you, you can install running sudo apt-get install lamp-server^ –  Achu Mar 23 '11 at 12:08
    
@Achu.. nope... that doesn't work either..same problem –  Gaurav Sharma Mar 23 '11 at 12:42
    
@Gaurav You mean you can't install anything? so how can you install the packages you describe on your main question? if got error message when you run the installations, please include the output with you question. thanks –  Achu Mar 23 '11 at 13:04
    
@Achu I can install everything. The problem is that installing LAMP server does not help. In fact, when I remove everything i.e. apache2, libapache2-mod-php5 and php5 using purge, and then install only apache2, localhost comes up with the default "It works" page. It's when I add the PHP packages that the problem of "Cannot connect" comes up. –  Gaurav Sharma Mar 23 '11 at 13:37
up vote 5 down vote accepted

The steps listed at http://netbeans.org/kb/docs/php/configure-php-environment-ubuntu.html are exactly what I needed. I did a fresh installation of Ubuntu, ran

sudo tasksel install lamp-server

and then followed the steps in the Troubleshooting section i.e.

apt-get --purge remove php5-common

apt-get install php5 phpmyadmin
share|improve this answer
sudo apt-get install apache2
sudo apt-get install php5
sudo apt-get install libapache2-mod-php5
sudo apt-get install sendmail
sudo /etc/init.d/apache2 restart
share|improve this answer
    
sendmail is a little old fashioned as MTAs go... postfix is probably a better choice IMO. –  Oli Nov 7 '11 at 23:04

The real problem behind this is not the installation of PHP5, which went just fine, but the fact, there's an IDN extension installed either manually or from some ancient package, most probably php5-intl.

The purging of php5-common has uninstalled all of the installed extensions, so it has fixed this error, but the solution was very 'Computer Science' like: "Have you tried to shut it off and on again?", while you could have just issued dpkg --purge php5-intl to achieve the same result.

share|improve this answer

Check if your PHP 5 mod is enabled in Apache 2 (/etc/apache2/mods-enabled). If you can't find @php5* symlinks there, you can try:

sudo a2enmod php5
sudo /etc/init.d/apache2 restart

And be sure Apache 2 listens on the port 80.

share|improve this answer
    
how do check that Apache2 listens on port 80? I tried the commands and "Module php5 already enabled" is what I get. –  Gaurav Sharma Mar 23 '11 at 11:56
    
With the command 'sudo nmap localhost'. By default you don't have the 'nmap' installed. –  Iradrian Mar 23 '11 at 12:04
1  
Instead of using netmap to check port 80 from the client perspective, you can use netstat which is installed by default (from the net-tools package) to get a list of all listening services (over TCP): netstat -tln –  Lekensteyn Mar 23 '11 at 13:22
    
Or even netstat -aunt | grep :80 -- checking that the entry is under the Local Address column. –  belacqua Mar 28 '11 at 16:39
    
The logs provided in the question quickly clearly indicate that the PHP was in fact enabled in the Apache. –  oerdnj Apr 5 '13 at 6:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.