{"id":625,"date":"2025-11-22T13:03:22","date_gmt":"2025-11-22T10:03:22","guid":{"rendered":"https:\/\/admin.danychrys.ro:4433\/?p=625"},"modified":"2025-12-06T21:03:24","modified_gmt":"2025-12-06T18:03:24","slug":"how-to-install-php-and-php-fpm-on-ubuntu-24-04","status":"publish","type":"post","link":"https:\/\/danychrys.go.ro\/web\/how-to-install-php-and-php-fpm-on-ubuntu-24-04\/","title":{"rendered":"How to install php and php-fpm on Ubuntu 24.04"},"content":{"rendered":"<p style=\"text-align: justify;\">\u00a0 We are going to show you how to install PHP and PHP-FPM on Ubuntu 24.04. PHP, or Hypertext Preprocessor, is a popular open-source programming language used mostly for online development. The only PHP implementation of PHP FastCGI that is really helpful for websites with a lot of traffic is PHP. At the end of this guide, you should be ready to go with PHP running on your server.<\/p>\n<h3 style=\"text-align: justify;\">PREREQUISITES<\/h3>\n<ul class=\"cp_check red\">\n<li>Before we start, please confirm you have the following:<\/li>\n<li>Ubuntu 24.04 LTS installed on the server<\/li>\n<li>A user account with the sudo access<\/li>\n<li>An essential command-line operation understanding<\/li>\n<li>A reliable internet connection for downloading software packages<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">To ensure that your system is up to date, run the following commands:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt update\r\nsudo apt upgrade<\/pre>\n<h3>INSTALL APACHE<\/h3>\n<p>Launch the Apache web server using the following command:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt install apache2<\/pre>\n<h3>INSTALL PHP<\/h3>\n<p>Let&#8217;s begin with installing the PHP package in Ubuntu 24.04 server.<br \/>\nFirst, open a terminal on your Ubuntu system.<br \/>\nPHP and common modules are included in the installation action:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo add-apt-repository ppa:ondrej\/php<\/pre>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt install php8.4<\/pre>\n<p>That command installs the core PHP package, the command-line interface, and common libraries.<\/p>\n<p>Make sure the installation works:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">php -v<\/pre>\n<p>INSTALL PHP EXTENSIONS<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt install php8.4-curl php8.4-mbstring php8.4-xml php8.4-mysql php8.4-gd php8.4-zip<\/pre>\n<p>Short description:<\/p>\n<ul class=\"cp_check red\">\n<li>php-mysql &#8211; Allows MySQL database connection<\/li>\n<li>php-gd &#8211; Adds ability to manipulate images<\/li>\n<li>php-curl &#8211; Makes possible to communicate with servers<\/li>\n<li>php-mbstring &#8211; Provides multibyte string support<\/li>\n<li>php-xml &#8211; Enables XML support<\/li>\n<li>php-zip &#8211; Enables ZIP support<\/li>\n<\/ul>\n<p>Additional extensions can be installed as you see fit for your projects. You can search<br \/>\nthem using:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">apt-cache search php-<\/pre>\n<h3>INSTALL AND CONFIGURE PHP-FPM<\/h3>\n<p>PHP-FPM is essential when dealing with high-traffic websites. To install and configure it:<\/p>\n<p><strong>1.Install the package:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt install php8.4-fpm<\/pre>\n<p><strong>2.Launch PHP-FPM service. Depending on the installation, version number may differ.<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo systemctl start php8.4-fpm<\/pre>\n<p><strong>3.Tell PHP-FPM to go on boot:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo systemctl enable php8.4-fpm<\/pre>\n<p><strong>4.Verify PHP-FPM is working:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">systemctl status php8.4-fpm<\/pre>\n<p>This will output a response that says &#8222;Active (Running)&#8221; if everything is working as expected.<\/p>\n<h3>CONFIGURATON<\/h3>\n<p><strong>1.Set Up Apache for PHP-FPM. Ensure Apache is made compatible for PHP-FPM, by first finding Apache configuration file (usually \/etc\/apache2\/sites-available\/your_conf.conf) then inserting:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">&lt;FilesMatch \\.php$&gt;\r\nSetHandler &quot;proxy:unix:\/var\/run\/php\/php8.4-fpm.sock|fcgi:\/\/localhost&quot;\r\n&lt;\/FilesMatch&gt;<\/pre>\n<ul class=\"cp_check red\">\n<li>OPTIONAL: You can put this line on .htaccess file (this work only for directory where is the .htaccess file)<\/li>\n<\/ul>\n<p>Remember we must alter specific PHP version and socket path to suit individual settings of the server.<br \/>\n<strong>2.Activate PHP and PHP-FPM. Enable PHP and PHP-FPM following these instructions:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo apt install libapache2-mod-php8.4\r\nsudo a2enmod proxy_fcgi setenvif<\/pre>\n<p><strong>3.Reboot Apache. Apply changes by restarting Apache server:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">sudo systemctl restart apache2<\/pre>\n<p><strong>4.To ensure that PHP and PHP-FPM are both running with no problems, create a test file then serve it via the website&#8217;s server. Let&#8217;s say it uses Apache in this example:<\/strong><br \/>\nGenerate PHP Info File. To show PHP settings using the phpinfo() function, do the following:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">mkdir -p \/var\/www\/html\r\necho &quot;&lt;?php phpinfo(); ?&gt;&quot; | sudo tee \/var\/www\/html\/info.php<\/pre>\n<p><strong>5.Access PHP Info Page. First open your web browser and go to:<\/strong><\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">http:\/\/your_server_ip\/info.php<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 We are going to show you how to install PHP and PHP-FPM on Ubuntu 24.04. PHP, or Hypertext Preprocessor, is a popular open-source programming language used mostly for online development. The only PHP implementation of PHP FastCGI that is really helpful for websites with a lot of traffic is PHP. At the end of&hellip;<\/p>\n","protected":false},"author":1,"featured_media":624,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-625","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials","category-5","description-off"],"_links":{"self":[{"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/posts\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":9,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/posts\/625\/revisions"}],"predecessor-version":[{"id":894,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/posts\/625\/revisions\/894"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/media\/624"}],"wp:attachment":[{"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/media?parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/categories?post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danychrys.go.ro\/web\/wp-json\/wp\/v2\/tags?post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}