<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Syn Ify</title>
    <description>The latest articles on DEV Community by Syn Ify (@syn_ify_8fe53c8833faf3e7f).</description>
    <link>https://dev.to/syn_ify_8fe53c8833faf3e7f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3660939%2F2598b313-1bda-4e00-8349-843eb7cb944d.jpg</url>
      <title>DEV Community: Syn Ify</title>
      <link>https://dev.to/syn_ify_8fe53c8833faf3e7f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/syn_ify_8fe53c8833faf3e7f"/>
    <language>en</language>
    <item>
      <title>How to Set Up PHP 8.3 with Apache on Ubuntu (Beginner-Friendly Guide)</title>
      <dc:creator>Syn Ify</dc:creator>
      <pubDate>Wed, 17 Dec 2025 08:11:36 +0000</pubDate>
      <link>https://dev.to/syn_ify_8fe53c8833faf3e7f/how-to-set-up-php-83-with-apache-on-ubuntu-beginner-friendly-guide-4da0</link>
      <guid>https://dev.to/syn_ify_8fe53c8833faf3e7f/how-to-set-up-php-83-with-apache-on-ubuntu-beginner-friendly-guide-4da0</guid>
      <description>&lt;h2&gt;
  
  
  Introduction
&lt;/h2&gt;

&lt;p&gt;PHP is one of the most popular programming languages for designing server-side web applications in the world today. It has extensive documentation, is highly stable, and is widely used in platforms such as WordPress and Wikipedia.&lt;/p&gt;

&lt;p&gt;At the time of writing, PHP 8.4 has been released. However, because it is still relatively new, ecosystem support may be incomplete in some environments. For this reason, this guide focuses on PHP 8.3, which is currently considered stable and well-supported across most Linux distributions.&lt;/p&gt;

&lt;p&gt;This guide is made for people who have no prior experience setting up a web server and for those who are just beginning to use a Linux operating system such as Ubuntu.&lt;/p&gt;

&lt;h2&gt;
  
  
  What You Will Learn
&lt;/h2&gt;

&lt;p&gt;By the end of this guide, you will:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Understand the difference between PHP-CLI, mod_php, and PHP-FPM&lt;/li&gt;
&lt;li&gt;Install PHP 8.3 with Apache on Ubuntu 22.04+&lt;/li&gt;
&lt;li&gt;Choose the appropriate PHP handler for your use case&lt;/li&gt;
&lt;li&gt;Verify and troubleshoot a working PHP installation&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;p&gt;For this guide to be most compatible with your setup, you should be using an Ubuntu operating system version 22.04 or newer, and it must be connected to the internet.&lt;/p&gt;

&lt;p&gt;No prior server administration experience is assumed beyond your ability to read and follow instructions, navigate your system, and type commands into a terminal. You must also have &lt;strong&gt;sudo&lt;/strong&gt; (administrator) privileges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Description
&lt;/h2&gt;

&lt;p&gt;It is important to note that PHP can be installed and used in different contexts depending on how it is executed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PHP-CLI (Command Line Interface)&lt;/strong&gt; runs in the terminal and is entirely text-based. Its primary use cases in production include running cron jobs, background workers, maintenance scripts, and other automation tasks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Web-based PHP&lt;/strong&gt;, on the other hand, runs through a web server such as Apache and allows interaction through a web browser with full graphical user interface (GUI) support.&lt;/p&gt;

&lt;p&gt;Web-based PHP under Apache can be implemented in two major ways, each with its own strengths and trade-offs:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;mod_php&lt;/strong&gt; is generally easy to install and manage, but it is less efficient because PHP runs inside the Apache process itself. It is commonly used for local development, testing environments, or low-traffic production websites.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PHP-FPM (FastCGI Process Manager)&lt;/strong&gt; is the industry standard for production environments. While it is slightly more complex to configure, it offers better performance, scalability, and process isolation. For publicly accessible or higher-traffic websites, PHP-FPM is typically the preferred option.&lt;/p&gt;

&lt;h2&gt;
  
  
  Warning
&lt;/h2&gt;

&lt;p&gt;While it is perfectly fine—and often encouraged—to install both &lt;strong&gt;PHP-CLI&lt;/strong&gt; and web-based PHP, it is &lt;strong&gt;not advisable&lt;/strong&gt; to install both &lt;strong&gt;mod_php&lt;/strong&gt; and &lt;strong&gt;PHP-FPM&lt;/strong&gt; at the same time. These two Apache PHP handlers conflict with each other.&lt;/p&gt;

&lt;p&gt;Choose one approach and stick to it. Advanced users may configure both manually, but this is not recommended for beginners.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation Steps
&lt;/h2&gt;

&lt;p&gt;Begin by launching the &lt;strong&gt;Terminal&lt;/strong&gt; application on Ubuntu. Once you have confirmed that your system is connected to the internet, you can proceed with the installation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: mod_php Installation
&lt;/h3&gt;

&lt;p&gt;Add the required repository, update your package list, and install Apache with PHP 8.3 using mod_php:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;add-apt-repository ppa:ondrej/php
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;apache2 php8.3 libapache2-mod-php8.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Follow the prompts and confirm any installation requests as needed.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 2: PHP-FPM Installation
&lt;/h3&gt;

&lt;p&gt;If you choose PHP-FPM, first add the repository and install Apache, PHP 8.3, and PHP-FPM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;add-apt-repository ppa:ondrej/php
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;apache2 php8.3 php8.3-fpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, enable the Apache modules required for PHP-FPM integration. These modules allow Apache to communicate with PHP-FPM over FastCGI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;a2enmod proxy_fcgi setenvif
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Enable the PHP-FPM configuration for Apache:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;a2enconf php8.3-fpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To prevent conflicts, disable the standard PHP module used by mod_php:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;a2dismod php8.3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;PHP-FPM works best with Apache’s event-based multiprocessing model. Disable the prefork MPM and enable the event MPM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;a2dismod mpm_prefork
&lt;span class="nb"&gt;sudo &lt;/span&gt;a2enmod mpm_event
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, restart Apache to apply all changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Troubleshoot Installation
&lt;/h2&gt;

&lt;p&gt;In some cases, errors may arise during installation. While this section is not exhaustive, it covers some commonly encountered issues.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;add-apt-repository: command not found&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This typically occurs when the system is not a full Ubuntu installation (for example, certain minimal VPS images or containers).&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; A different setup guide may be required.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Could not get lock /var/lib/dpkg/lock-frontend&lt;/strong&gt; or &lt;strong&gt;resource temporarily unavailable&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This usually means another package management process is running.&lt;br&gt;&lt;br&gt;
&lt;strong&gt;Fix:&lt;/strong&gt; Wait several minutes for the process to complete. If it is clearly stuck, you may identify and terminate it carefully:&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;sudo &lt;/span&gt;fuser &lt;span class="nt"&gt;-v&lt;/span&gt; /var/lib/dpkg/lock-frontend
  &lt;span class="nb"&gt;sudo kill&lt;/span&gt; &lt;span class="nt"&gt;-9&lt;/span&gt; &amp;lt;PID&amp;gt;
  &lt;span class="nb"&gt;sudo &lt;/span&gt;dpkg &lt;span class="nt"&gt;--configure&lt;/span&gt; &lt;span class="nt"&gt;-a&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Unmet dependencies&lt;/strong&gt;
This can result from previous incomplete installations.
&lt;strong&gt;Fix:&lt;/strong&gt; Repair dependencies with:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nt"&gt;--fix-broken&lt;/span&gt; &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;apache2.service failed&lt;/strong&gt; or &lt;strong&gt;could not bind to address 0.0.0.0:80&lt;/strong&gt;
Port 80 may already be in use by another web server such as Nginx.
&lt;strong&gt;Fix:&lt;/strong&gt; Stop the conflicting service and restart Apache:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;  &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl stop nginx
  &lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl start apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Installation Test
&lt;/h2&gt;

&lt;p&gt;If the installation completes successfully, you can verify that PHP is working in both CLI and web server modes.&lt;/p&gt;

&lt;p&gt;To test PHP-CLI, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php &lt;span class="nt"&gt;-v&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the PHP version is displayed, PHP-CLI is functioning correctly.&lt;/p&gt;

&lt;p&gt;To test PHP through the web server, create the file &lt;code&gt;/var/www/html/info.php&lt;/code&gt; with the following contents:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="nb"&gt;phpinfo&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Open &lt;code&gt;http://localhost/info.php&lt;/code&gt; in your web browser. At the top of the page, you should see a large header displaying the PHP version currently in use (for example, PHP Version 8.3.x). Below this header is a series of tables showing detailed configuration information about your PHP installation.&lt;/p&gt;

&lt;p&gt;At this point, your system should meet the following criteria:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Apache is running and listening on port 80&lt;/li&gt;
&lt;li&gt;PHP 8.3 is available via the CLI&lt;/li&gt;
&lt;li&gt;Apache is correctly forwarding PHP requests&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If either PHP mode does not work as expected after carefully following this guide, further troubleshooting may be required depending on your system environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Configurations
&lt;/h2&gt;

&lt;p&gt;While PHP may now be functional, additional extensions are often required for real-world applications.&lt;/p&gt;

&lt;p&gt;Install commonly used extensions with:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install &lt;/span&gt;php8.3-mysql php8.3-curl php8.3-mbstring php8.3-xml php8.3-gd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Restart Apache to apply the changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart apache2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are using PHP-FPM, restart the FPM service as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;systemctl restart php8.3-fpm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After testing your setup, it is advised to remove the &lt;code&gt;/var/www/html/info.php&lt;/code&gt; file you created earlier, as exposing &lt;code&gt;phpinfo()&lt;/code&gt; publicly can leak sensitive configuration details.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;At the end of this guide, your Ubuntu system should now be running PHP 8.3 integrated with Apache. You should be able to handle PHP server requests both locally and over an internet connection.&lt;/p&gt;

&lt;p&gt;This guide demonstrates a basic setup and does not cover SSL, firewall rules, or advanced hardening required for internet-facing production servers.&lt;/p&gt;

&lt;h3&gt;
  
  
  Next Steps
&lt;/h3&gt;

&lt;p&gt;After completing this setup, you may want to explore the following:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Installing a database server such as MySQL or MariaDB&lt;/li&gt;
&lt;li&gt;Learning how to configure Apache Virtual Hosts&lt;/li&gt;
&lt;li&gt;Exploring PHP frameworks such as Laravel or Slim&lt;/li&gt;
&lt;li&gt;Hardening your server with basic security practices&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I wish you success in all the web applications you create henceforth.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>ubuntu</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
