I am running PHP 7.4 from command line on Ubuntu 20.04 LTS. It appears to use some config values from the "cli/php.ini" file as well as some values from "apache2/php.ini" file. see expose_php and memory_limit values shown by "php -i" below: Show
How comes? asked Aug 18, 2020 at 9:04
2 Thanks to Mark for teaching me that .ini files in conf.d directory will overwrite the value set in php.ini. answered Aug 18, 2020 at 14:18
1 How to install PHP-FPM with Apache on Ubuntu 22.04. There are two distinct options to run PHP using the web server. One is using the PHP’s CGI and the other one is FPM. FPM is a process manager to manage the FastCGI in PHP. Apache ships with In this guide you are learn how to setup PHP 8.1-FPM and configure it with Apache and also configure PHP variables. This setup can also be done on other VPS or dedicated or cloud VM’s. This setup is tested on Google Compute Engine but it works on any Ubuntu or Debian Linux distributions. Getting StartedMake sure your Ubuntu server is having the latest packages by running the following command. sudo apt update This will update the package index and update the installed packages to the latest version. Step 1: Install PHP 8.1 FPMBy default Ubuntu 22.04 has the latest PHP 8.1 repository added. So you can install PHP using the following command. sudo apt install php8.1-fpm php8.1 libapache2-mod-php8.1 php8.1-common php8.1-mysql php8.1-xml php8.1-xmlrpc php8.1-curl php8.1-gd php8.1-imagick php8.1-cli php8.1-imap php8.1-mbstring php8.1-opcache php8.1-soap php8.1-zip php8.1-intl php8.1-bcmath unzip -y Wait for the installation to complete. Once the installation is complete verify the installation using the following command. sudo service php8.1-fpm status You will receive an output similar to the one below. Output
● php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-05-08 05:42:31 UTC; 2min ago
Docs: man:php-fpm8.1(8)
Process: 564 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /run/php/php-fpm.s>
... Step 2: Install ApacheOnce you have your PHP-FPM up and running you can install Apache web server. sudo apt install apache2 Check Apache version using the below command sudo apachectl -v Output Server version: Apache/2.4.52 (Ubuntu) Server built: 2022-03-25T00:35:40 Every process in Apache is managed with the sudo systemctl status apache2 Output ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2022-05-08 05:45:29 UTC; 1min 47s ago Docs: https://httpd.apache.org/docs/2.4/ Main PID: 12782 (apache2) Tasks: 55 (limit: 1151) Memory: 5.1M CPU: 52ms CGroup: /system.slice/apache2.service ├─12782 /usr/sbin/apache2 -k start ├─12784 /usr/sbin/apache2 -k start └─12785 /usr/sbin/apache2 -k start Step 3: Configure Apache with PHP-FPMBy default Apache will use Disable the default Apache vhost configuration. sudo a2dissite 000-default Enable Apache Event ModuleDisable any default preform modules for any existing PHP versions. sudo a2dismod php7.4 Disable Apache Prefork module. sudo a2dismod mpm_prefork Enable Apache Event module. sudo a2enmod mpm_event proxy_fcgi setenvif Enable PHP FPM ConfigurationNow you can enable PHP-FPM configuration. sudo a2enconf php8.1-fpm Enable HTTP2If you need HTTP 2 support you can enable it also. sudo a2enmod http2 Now Apache is configured with PHP FPM. Step 4: Configure PHP-FPMNow we configure PHP for Web Applications by changing some values in For PHP 8.1 with Nginx the sudo nano /etc/php/8.1/fpm/php.ini Hit upload_max_filesize = 32M Once you have modified your PHP settings you need to restart your PHP-FPM for the changes to take effect. sudo service php8.1-fpm restart Step 5: Configure Apache Virtual HostsCreate a new Apache vhost configuration. sudo nano /etc/apache2/sites-available/domain.conf Paste the below configuration in the file. <VirtualHost *:80>
ServerName domain.com
ServerAlias www.domain.com
Protocols h2 http/1.1
DocumentRoot /var/www/html/domain/public
<Directory /var/www/html/domain/public>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost> Hit Now you can enable the new Apache configuration. sudo a2ensite domain.conf Restart Apache. sudo service apache2 restart Step 6: Verify PHP-FPM with ApacheHere we have configured cd /var/www/html/domain/public sudo nano info.php Paste the following. <?php phpinfo(); Hit Now go your browser and point it to your server IP address or domain name followed by the You will see the PHP info page and confirm PHP-FPM is used with Apache. Prepare yourself for a role working as an Information Technology Professional with Linux operating system ConclusionNow you have learned how to install PHP 8.1-FPM with Apache and configure PHP in Ubuntu 22.04. You have also learned to setup PHP-FPM pools for multiple users. |