Drupal: Install PECL UploadProgress
Tags: linux, webdev, drupal
Published: 2021-12-12 21:10:00

<!-- wp:paragraph -->
<p>Drupal often recommends that you install and enable PECL UploadProgress to show better feedback when uploading files, but it doesn't make it obvious how to do that. This quick post will run through what it took for me to get PECL UploadProgress on an Oracle Linux 8 server.</p>
<!-- /wp:paragraph -->

<!-- wp:more -->
<!--more-->
<!-- /wp:more -->

<!-- wp:heading -->
<h2>Add required packages</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>There are a few preliminary packages that you'll need: gcc, make, php-devel, and php-pear. You can install in Oracle Linux 8 using this command:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo yum -y install gcc make php-devel php-pear</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>You don't have to provide the -y. That will pre-approve any other prompts that come up, including if it requires installing other dependent packages. If you want to be more careful, don't use that, but it can come in handy in contexts like installing this through a script.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Install PECL</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Now that you've got the dependencies, you can install uploadprogress:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo pecl -y install uploadprogress</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Add to php.ini</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>The packages are now in place, but your PHP installation will not make use of it unless it is recognized as an extension in your php.ini file. In the default Oracle Linux 8 setup, this file is located at /etc/php.ini. You'll need to add this line to your file:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>extension=uploadprogress.so</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>You can edit that file directly using your preferred editor to add this line to the file, or if you are using this within a script, you can have the script write it to the end of the file like this:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo echo "extension=uploadprogress.so" &gt;&gt; /etc/php.ini</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p>If you first need to check whether that line is already in the file - so that you don't end up writing it multiple times in a context where a script might add another line every time - you can use this in a bash script:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>if &#91; ! -z $(grep "extension=uploadprogress.so" /etc/php.ini) ]; then
    sudo echo "extension=uploadprogress.so" &gt;&gt; /etc/php.ini
fi</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Restart</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Finally, you'll need to restart Apache and PHP for this to go into effect:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>sudo systemctl restart php-fpm
sudo systemctl restart httpd</code></pre>
<!-- /wp:code -->

<!-- wp:paragraph -->
<p><a href="https://github.com/ryan-l-robinson/Drupal-Oracle-Linux-scripts/tree/main" data-type="URL" data-id="https://github.com/ryan-l-robinson/Drupal-Oracle-Linux-scripts/tree/main">This script is available in my GitHub</a>.</p>
<!-- /wp:paragraph -->