Where is php in ubuntu?

I have installed Apache and PHP. I know PHP works as I have tested a simple PHP file on an Apache server.

I'm writing a simple webserver which should be able to process PHP files. So once I get a request for a PHP file, I want to do something like 'exec php test.php' and get the output and pass it to the client.

As I'm not much into Ubuntu, I don't know where the PHP executable is (should be in \bin right?) to do it. But there is no PHP file inside \bin or \usr\bin.

When I run 'which php' it shows nothing. How do I do this?

PHP - Scripting Language

PHP is a general-purpose scripting language suited for Web development. PHP scripts can be embedded into HTML. This section explains how to install and configure PHP in an Ubuntu System with Apache2 and MySQL.

This section assumes you have installed and configured Apache2 Web Server and MySQL Database Server. You can refer to the Apache2 and MySQL sections in this document to install and configure Apache2 and MySQL respectively.

Installation

PHP is available in Ubuntu Linux. Unlike Python, which is installed in the base system, PHP must be added.

To install PHP and the Apache PHP module you can enter the following command at a terminal prompt:

sudo apt install php libapache2-mod-php

You can run PHP scripts at a terminal prompt. To run PHP scripts at a terminal prompt you should install the php-cli package. To install php-cli you can enter the following command:

sudo apt install php-cli

You can also execute PHP scripts without installing the Apache PHP module. To accomplish this, you should install the php-cgi package via this command:

sudo apt install php-cgi

To use MySQL with PHP you should install the php-mysql package, like so:

sudo apt install php-mysql

Similarly, to use PostgreSQL with PHP you should install the php-pgsql package:

sudo apt install php-pgsql

Configuration

If you have installed the libapache2-mod-php or php-cgi packages, you can run PHP scripts from your web browser. If you have installed the php-cli package, you can run PHP scripts at a terminal prompt.

By default, when libapache2-mod-php is installed, the Apache 2 Web server is configured to run PHP scripts using this module. Please verify if the files /etc/apache2/mods-enabled/php8.*.conf and /etc/apache2/mods-enabled/php8.*.load exist. If they do not exist, you can enable the module using the a2enmod command.

Once you have installed the PHP related packages and enabled the Apache PHP module, you should restart the Apache2 Web server to run PHP scripts, by running the following command:

sudo systemctl restart apache2.service 

Testing

To verify your installation, you can run the following PHP phpinfo script:

<?php
  phpinfo();
?>

You can save the content in a file phpinfo.php and place it under the DocumentRoot directory of the Apache2 Web server. Pointing your browser to http://hostname/phpinfo.php will display the values of various PHP configuration parameters.

References

  • For more in depth information see the php.net documentation.

  • There are a plethora of books on PHP 7 and 8. A good book from O’Reilly is Learning PHP, which includes an exploration of PHP 7’s enhancements to the language.

  • Also, see the Apache MySQL PHP Ubuntu Wiki page for more information.

Where is php in ubuntu?

Last updated on June 7th, 2022 | 2 replies

As there are multiple versions of PHP with different sever configurations, php.ini could be located in several different folders.

Method 1

One way to find out exactly which php.ini file your web sever is using is by creating a new PHP file in document root called info.php.

info.php

<?php
phpinfo();
?>

Load this file in your browser, press CTRL + F (or Command + F on Mac) and search for “Loaded Configuration File”. You should see something like

/etc/php/8.1/apache2/php.ini

This will tell you the exact location of the php.ini file you want to edit.

Method 2

In Linux, run this command to locate the PHP.ini configuration file.

php -i | grep "Loaded Configuration File"

Or in Windows Command Line:

php -i | findstr /c:"Loaded Configuration File"

The result should be something like this:

Loaded Configuration File => /etc/php/8.1/cli/php.ini

In the above example, we can see that the PHP install is located in /etc/php/8.1. Note that there are three different configuration files you should we aware of:

CLI

/etc/php/8.1/cli/php.ini is for the CLI PHP program. Changes to this config file will only affect PHP as it runs in the terminal – it will NOT affect the web server.

Apache

/etc/php/8.1/apache2/php.ini is for the PHP plugin used by Apache. This is the one you need to edit if you are using the Apache web server.

Nginx or Apache with PHP-FPM

/etc/php/8.1/fpm/php.ini is a fastcgi-compatible ‘wrapper’ for PHP processing. This is the one you need to edit if you’re using the Nginx web server or Apache with PHP-FPM.

Method 3

Using the locate command in Linux,. If it’s not already installed, run  sudo apt update && sudo apt install mlocate.

You should see a list of php.ini files here. Try editing one of them and restarting you web server to see if makes the required changes.

Editing php.ini in Linux

Apache

On Apache, php.ini is usually located in /etc/php/8.1/apache2/php.ini. Replace 8.1 with your own version, e.g, php5.6php7.4, etc.

To edit:

sudo nano /etc/php/8.1/apache2/php.ini

However, if you are using PHP FPM, it may be located in /etc/php/8.1/fpm/php.ini. Replace 8.1 with your own version, e.g, php5.6php7.4, etc.

To edit:

sudo nano /etc/php/8.1/fpm/php.ini

To save file and exit, press CTRL + X, press Y and then press ENTER

You must restart Apache after altering php.ini.

sudo systemctl restart apache2

If you are using PHP-FPM, you must restart that service. Replace php8.1 with your own version, e.g, php5.6php7.4, etc.

sudo service php8.1-fpm restart

Nginx or Apache with PHP-FPM

Nginx uses PHP FPM and &lt;code&gt;php.ini&lt;/code&gt;&amp;nbsp;is usually located in&amp;nbsp;&lt;code&gt;/etc/php/8.1/fpm/php.ini&lt;/code&gt;.&amp;nbsp;Replace&amp;nbsp;&lt;code&gt;8.1&lt;/code&gt;&amp;nbsp;with your own version, e.g,&amp;nbsp;&lt;code&gt;php5.6&lt;/code&gt;,&amp;nbsp;&lt;code&gt;php7.4&lt;/code&gt;, etc.&lt;/p&gt;&lt;div class="code-wrap"&gt;&lt;pre id="supercoder-block_629f3eb9c73bc" class="code language-bash"&gt;&lt;code class="language-bash"&gt;sudo nano /etc/php/8.1/fpm/php.ini&lt;/code&gt;&lt;/pre&gt;&lt;div class="btn-copy-wrapper"&gt;&lt;button class="btn-copy" title="Copy"&gt;&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;&lt;p&gt;Save and exit (press &lt;code&gt;CTRL&lt;/code&gt; + &lt;code&gt;X&lt;/code&gt;, press &lt;code&gt;Y&lt;/code&gt; and then press &lt;code&gt;ENTER&lt;/code&gt;)&lt;/p&gt;&lt;p&gt;You must restart Nginx after altering&amp;nbsp;&lt;code&gt;php.ini&lt;/code&gt;.&lt;/p&gt;&lt;div class="code-wrap"&gt;&lt;pre id="supercoder-block_629f3ed8c73bd" class="code language-bash"&gt;&lt;code class="language-bash"&gt;sudo systemctl reload nginx&lt;/code&gt;&lt;/pre&gt;&lt;div class="btn-copy-wrapper"&gt;&lt;button class="btn-copy" title="Copy"&gt;&lt;/button&gt;&lt;/div&gt;&lt;/div&gt;&lt;a class="anchor" id="id-older-versions"&gt;&lt;/a&gt;&lt;h2&gt;Older Versions&lt;/h2&gt;&lt;p&gt;For versions of Ubuntu &lt;em&gt;lower&lt;/em&gt; than 16.04, &lt;code&gt;/etc/php/5.6/&lt;/code&gt;,&lt;code&gt;/etc/php/7.0/&lt;/code&gt;,&lt;code&gt;/etc/php/7.1/&lt;/code&gt;, and so on, are replaced by &lt;code&gt;/etc/php5/&lt;/code&gt; and so on. Otherwise, these paths remain accurate.&lt;span id="ezoic-pub-ad-placeholder-130" class="ezoic-adpicker-ad"&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;Let me know if this helped. Follow me on &lt;a href="https://twitter.com/DevAnswers" target="_blank" rel="noreferrer"&gt;Twitter&lt;/a&gt;, &lt;a href="https://www.facebook.com/DevAnswers-326312698016716/" target="_blank" rel="noreferrer"&gt;Facebook&lt;/a&gt; and &lt;a href="https://www.youtube.com/channel/UCXvcK0LxaefzAgkUJWqd0FA" target="_blank" rel="noreferrer"&gt;YouTube&lt;/a&gt;, or 🍊 &lt;a href="https://www.buymeacoffee.com/DevAnswers" target="_blank" rel="noreferrer"&gt;buy me a smoothie&lt;/a&gt;.&lt;/p&gt;&lt;p&gt;p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my &lt;a target="_blank" href="https://devanswers.co/ezoic-review-increase-adsense-ad-revenue/"&gt;Ezoic review&lt;/a&gt; to find out how.&lt;/p&gt;&lt;/div&gt;&lt;/article&gt;&lt;div id="comments" class="comments-area"&gt;&lt;a class="anchor" id="comments-anchor"&gt;&lt;/a&gt;&lt;h2 class="comments-title"&gt;2 replies&lt;/h2&gt;&lt;div id="respond" class="comment-respond"&gt;&lt;h3 id="reply-title" class="comment-reply-title"&gt;Leave a reply &lt;small&gt;&lt;/small&gt;&lt;/h3&gt;&lt;form action="https://devanswers.co/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate&gt;&lt;p class="comment-notes"&gt;&lt;span id="email-notes"&gt;Your email address will not be published.&lt;/span&gt; &lt;span class="required-field-message" aria-hidden="true"&gt;Required fields are marked &lt;span class="required" aria-hidden="true"&gt;*&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;p class="comment-form-comment"&gt;&lt;label for="comment"&gt;Comment &lt;span class="required" aria-hidden="true"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required&gt;&lt;/textarea&gt;&lt;/p&gt;&lt;p class="comment-form-author"&gt;&lt;label for="author"&gt;Name &lt;span class="required" aria-hidden="true"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;input id="author" name="author" size="30" maxlength="245" required&gt;&lt;/p&gt;&lt;p class="comment-form-email"&gt;&lt;label for="email"&gt;Email &lt;span class="required" aria-hidden="true"&gt;*&lt;/span&gt;&lt;/label&gt; &lt;input id="email" name="email" type="email" size="30" maxlength="100" aria-describedby="email-notes" required&gt;&lt;/p&gt;&lt;p class="comment-form-cookies-consent"&gt;&lt;input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"&gt; &lt;label for="wp-comment-cookies-consent"&gt;Save my name, email, and website in this browser for the next time I comment.&lt;/label&gt;&lt;/p&gt;&lt;p class="form-submit"&gt;&lt;input name="submit" type="submit" id="submit" class="submit" value="Post Comment"&gt; &lt;input type="hidden" name="comment_post_ID" value="464" id="comment_post_ID"&gt; &lt;input type="hidden" name="comment_parent" id="comment_parent" value="0"&gt;&lt;/p&gt;&lt;p style="display:none"&gt;&lt;input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="15809d2923"&gt;&lt;/p&gt;&lt;p style="display:none!important"&gt;&lt;label&gt;Δ&lt;textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"&gt;&lt;/textarea&gt;&lt;/label&gt;&lt;input type="hidden" id="ak_js_1" name="ak_js" value="120"&gt;&lt;script&gt;document.getElementById("ak_js_1").setAttribute("value",(new Date()).getTime());</p><a target="_blank" rel="nofollow" id="cancel-comment-reply-link" href="https://devanswers.co/ubuntu-php-php-ini-configuration-file/#respond" style="display:none">Cancel reply</a></div><ol class="comment-list"><li id="comment-29626" class="comment even thread-even depth-1"><article id="div-comment-29626" class="comment-body"><footer class="comment-meta"><div class="comment-author vcard"><img alt="" src="https://secure.gravatar.com/avatar/2c463d63c6611bc3b5e194d7c53ff6d3?s=32&d=identicon&r=g" srcset="https://secure.gravatar.com/avatar/2c463d63c6611bc3b5e194d7c53ff6d3?s=64&d=identicon&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" loading="lazy"> <b class="fn">Bruno Garcia</b> <span class="says">says:</span></div><div class="comment-metadata"><a target="_blank" href="https://devanswers.co/ubuntu-php-php-ini-configuration-file/#comment-29626"><time datetime="2021-09-10T12:13:20+00:00">September 10, 2021 at 12:13 pm</time></a></div></footer><div class="comment-content"><p>Very good… this information saved me!</p></div><div class="reply"><a target="_blank" rel="nofollow" class="comment-reply-link" href="https://devanswers.co/ubuntu-php-php-ini-configuration-file/#comment-29626" data-commentid="29626" data-postid="464" data-belowelement="div-comment-29626" data-respondelement="respond" data-replyto="Reply to Bruno Garcia" aria-label="Reply to Bruno Garcia">Reply</a></div></article></li><li id="comment-19862" class="comment odd alt thread-odd thread-alt depth-1"><article id="div-comment-19862" class="comment-body"><footer class="comment-meta"><div class="comment-author vcard"><img alt="" src="https://secure.gravatar.com/avatar/250bb06a78dde41fe62abac219c46cca?s=32&d=identicon&r=g" srcset="https://secure.gravatar.com/avatar/250bb06a78dde41fe62abac219c46cca?s=64&d=identicon&r=g 2x" class="avatar avatar-32 photo" height="32" width="32" loading="lazy"> <b class="fn">Soufian</b> <span class="says">says:</span></div><div class="comment-metadata"><a target="_blank" href="https://devanswers.co/ubuntu-php-php-ini-configuration-file/#comment-19862"><time datetime="2021-02-17T08:22:43+00:00">February 17, 2021 at 8:22 am</time></a></div></footer><div class="comment-content"><p>Thanks</p></div><div class="reply"><a target="_blank" rel="nofollow" class="comment-reply-link" href="https://devanswers.co/ubuntu-php-php-ini-configuration-file/#comment-19862" data-commentid="19862" data-postid="464" data-belowelement="div-comment-19862" data-respondelement="respond" data-replyto="Reply to Soufian" aria-label="Reply to Soufian">Reply</a></div></article></li></ol></article></section></div></div><div id="article-sidebar"><div class="ad-wrapper"><span id="ezoic-pub-ad-placeholder-102"></span></div><div class="ad-wrapper"><span id="ezoic-pub-ad-placeholder-121"></span><span class="ezoic-ad ezoic-at-0 large-leaderboard-1 large-leaderboard-1121 adtester-container adtester-container-121 ezoic-ad-adaptive" data-ez-name="devanswers_co-large-leaderboard-1"><span class="ezoic-ad large-leaderboard-1 large-leaderboard-1-multi-121 adtester-container adtester-container-121" data-ez-name="devanswers_co-large-leaderboard-1"><span id="div-gpt-ad-devanswers_co-large-leaderboard-1-0" ezaw="300" ezah="262" style="position:relative;z-index:0;display:inline-block;padding:0;min-height:262px;min-width:300px" class="ezoic-ad"><script data-ezscrex="false" data-cfasync="false" style="display:none">if(typeof ez_ad_units!='undefined'){ez_ad_units.push([[300,250],'devanswers_co-large-leaderboard-1','ezslot_6',121,'0','0'])};__ez_fad_position('div-gpt-ad-devanswers_co-large-leaderboard-1-0');

Where is PHP in in Ubuntu?

The default location for the php. ini file is: Ubuntu 16.04: /etc/php/7.0/apache2.

Where is PHP directory in Linux?

Usually, PHP resides in /usr/bin or /usr/local/bin .

How do I start PHP in Ubuntu?

I followed these steps and it worked for me..
Execute sudo su on the terminal..
Enter your password..
Execute sudo subl /etc/apache2/sites-available/000-default. ... .
Change DocumentRoot /var/www/html to /home/user/yoursubdir..
Save the file and close it..
Execute sudo subl /etc/apache2/apache2..

Does Ubuntu include PHP?

Note: Ubuntu 20.04 ships with PHP 7.4 in its upstream repositories. This means that if you attempt to install PHP without a specified version, it will use 7.4. You will want to avoid relying on the default version of PHP because that default version could change depending on where you are running your code.