How to confirm php enabled on ubuntu server

4

2

I am not much into Linux. I am trying to setup a server through ssh. I installed apache php and mysql through this command.

sudo aptitude install apache2 php5-mysql libapache2-mod-php5 mysql-server

but I think php is not enabled on the server.

When I run command I receive response as below

$ which apache2ctl
/usr/sbin/apache2ctl

But when I check $ which php I receive no response.

$ locate php5
/etc/apparmor.d/abstractions/php5
/usr/share/ubuntu-serverguide/html/C/php5.html

Shishant

Posted 2009-11-22T09:46:39.080

Reputation: 1 095

Answers

13

On Debian (and thus Ubuntu), the Apache configuration files are stored under /etc/apache2. In that directory, there are 2 sub-directories for configuring modules: mods-available and mods-enabled. When you install an Apache module (ie: foo), it will put foo.load (and possibly foo.conf) into the /etc/apache2/mods-available directory. When you enable an Apache module using a2enmod, it will create a symbolic link in /etc/apache2/mods-enabled for each of the matching files from /etc/apache2/mods-available.

Thus for an Ubuntu server with PHP5 enabled, you should see something like this:

$ cd /etc/apache2
$ ls -l mods-*/*php*
-rw-r--r-- 1 root root 133 2008-02-27 15:49 mods-available/php5.conf
-rw-r--r-- 1 root root  59 2008-02-27 15:49 mods-available/php5.load
lrwxrwxrwx 1 root root  27 2009-02-05 07:30 mods-enabled/php5.conf -> ../mods-available/php5.conf
lrwxrwxrwx 1 root root  27 2009-02-05 07:30 mods-enabled/php5.load -> ../mods-available/php5.load

If the php5 configuration files aren't shown in the mods-enabled directory, enable them as follows:

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

Once you've done that, in order to test that PHP5 is configured, create /var/www/test.php as follows:

$ echo "<?php phpinfo(); ?>" | sudo tee /var/www/test.php
$ sudo chown www-data:www-data /var/www/test.php
$ sudo chmod 755 /var/www/test.php

Once that's done, you should be able to browse to /test.php on that server and see the PHP configuration data.

Craig Trader

Posted 2009-11-22T09:46:39.080

Reputation: 351

I am getting permission denied for this line $ sudo echo "<?php phpinfo(); ?>" > /var/www/test.php. – 151291 – 2016-02-23T04:49:08.243

@151291, try echo "<?php phpinfo(); ?>" | sudo tee /var/www/test.php instead. – Craig Trader – 2016-02-24T12:55:13.523

3

Use the phpinfo() function. Create a .php file that Apache will serve up and include the following:

<?php

phpinfo();

?>

When you navigate to the .php file, and php is installed, it should give you a whole lot of information about the php version you have installed.

Richard Nienaber

Posted 2009-11-22T09:46:39.080

Reputation: 131

2

I believe the php binary is part of a separate package called php5-cli which you don't seem to have installed.

Aleksander Kmetec

Posted 2009-11-22T09:46:39.080

Reputation:

3This is correct, but just to clarify: php5-cli is the commandline version, which you don't need if you're using it with apache. – Brendan Long – 2009-11-22T10:19:47.327

1

In aptitude do /^php5$ and see if you have that package. If not, install it - that's the core package.

meder omuraliev

Posted 2009-11-22T09:46:39.080

Reputation: 1 609

any command line that covers all php5 with cgi and so.? – Shishant – 2009-11-22T09:56:45.117

Do you have the php5 package installed? – meder omuraliev – 2009-11-22T10:05:04.173

yes it has [i] in front of them – Shishant – 2009-11-22T10:08:23.967

1Did you restart apache? – meder omuraliev – 2009-11-22T10:10:07.393

What does which php5 return? Did you try making a .php page with phpinfo();? Did you enable your site with a2ensite? – meder omuraliev – 2009-11-22T10:11:07.650

which php5 returns no response, can you please help me over im? my yahoo id todi_shish. This is the first time I am setting up a server. – Shishant – 2009-11-22T10:18:09.833

I don't have Yahoo but AIM - did you sudo apache2ctl graceful or sudo apache2ctl restart yet? – meder omuraliev – 2009-11-22T10:34:21.577

my aim shishant18 i restarted the apache server. – Shishant – 2009-11-22T10:41:05.180

so you got it? what was it specifically? – meder omuraliev – 2009-11-22T13:22:47.843

1

a2dismod disable apache modules and when executed without arguments displays the list of enabled modules:

Your choices are: alias auth_basic authn_file authz_default authz_groupfile authz_host authz_user autoindex cgi deflate dir env mime mod-evasive mod-security negotiation php5 rewrite scgi setenvif ssl status unique_id

Which module(s) do you want to disable (wildcards ok)?

if php5 is in the list it's installed and enabled. (CTRL-C to discard the command)

user159717

Posted 2009-11-22T09:46:39.080

Reputation:

0

Request the following URI from your server:

/?=PHPE9568F34-D428-11d2-A769-00AA001ACF42

You should get the PHP logo. If you do, PHP is working

anonymous coward

Posted 2009-11-22T09:46:39.080

Reputation: 427

No i am not getting any response – Shishant – 2009-11-22T10:22:44.400

not working on my ubuntu with php enabled.. – None – 2009-11-22T10:23:06.387

That URI only works if the root page is interpreted by PHP; if the URI isn't processed by PHP, nothing will happen. – Craig Trader – 2009-11-22T11:22:18.867