Activating PHP on a Fresh Virtualmin Install’s Default Website

by | Feb 12, 2024 | Technical Help, Web Hosting

Introduction

Virtualmin logoSetting up PHP on a freshly installed Virtualmin default website involves several steps. This guide will walk you through the process from start to finish, ensuring your default website can efficiently run PHP scripts using PHP-FPM.

Prerequisites

  1. A fresh Virtualmin installation.
  2. Root access to your server.

Getting the Default Domain Ready

The next steps involve getting the default domain ready. Virtualmin creates a numbered file for each domain that is handled on the server. You need to know which “number” corresponds to your domain name on the server. Here is a way to figure that out:

Do a directory listing of the domains directory:

ls /etc/webmin/virtual-server/domains

This will show you a list. If this is a fresh Virtualmin installation, there will only be one number in here. If you already have more than one listing in here, you will have to use nano and view the files to see which belongs to your domain. In the alternative, you can view the Apache virtual host configuration file to determine which number belongs to your domain as it is listed within that file as well.

Now do:

nano /etc/webmin/virtual-server/domains/[the number here]

This will display a very long configuration file. In mine, I changed three entries:

php_mode=fpm (this one was originally "none")
emailto=support@charlesworks.com (this was originally a server name that no email existed for)
emailto_addr=support@charlesworks.com (this was also originally a server name that no email existed for)

Now CTRL O to save and CTRL X to exit.

Enable the site:

a2ensite [site name].conf

Steps to Activate PHP

1. Verify PHP-FPM Installation

First, check if PHP-FPM is installed. Use the following command:

dpkg -l | grep php8.2-fpm

If PHP-FPM is not installed, install it:

apt-get install php8.2-fpm

2. Ensure PHP-FPM Service is Running

Check the status of the PHP-FPM service:

systemctl status php8.2-fpm

If it’s not running, start it:

systemctl start php8.2-fpm

Enable PHP-FPM to start on boot:

systemctl php8.2-fpm

3. Check the PHP-FPM Socket

Verify the PHP-FPM socket path in the configuration file:

cat /etc/php/8.2/fpm/pool.d/www.conf | grep listen

You should see something like this:

listen = /run/php/php8.2-fpm.sock

4. Edit Apache Virtual Host Configuration

Navigate to the Apache sites-available directory and open your site’s configuration file:

cd /etc/apache2/sites-available
nano [site domain].conf

Update the configuration to include the necessary settings for PHP-FPM:

<VirtualHost [ip address]:80>
ServerName [server name]
DocumentRoot /home/._default_hostname/public_html
ErrorLog /var/log/virtualmin/[server name]_error_log
CustomLog /var/log/virtualmin/[server name]_access_log combined
DirectoryIndex index.php index.htm index.html<Directory /home/._default_hostname/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
Require all granted
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

<Directory /home/._default_hostname/cgi-bin>
Require all granted
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"
</FilesMatch>
</VirtualHost>

<VirtualHost [ip address]:443>
ServerName [server name]
DocumentRoot /home/._default_hostname/public_html
ErrorLog /var/log/virtualmin/[server name]_error_log
CustomLog /var/log/virtualmin/[server name]_access_log combined
DirectoryIndex index.php index.htm index.html

<Directory /home/._default_hostname/public_html>
Options -Indexes +IncludesNOEXEC +SymLinksIfOwnerMatch
Require all granted
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

<Directory /home/._default_hostname/cgi-bin>
Require all granted
AllowOverride All Options=ExecCGI,Includes,IncludesNOEXEC,Indexes,MultiViews,SymLinksIfOwnerMatch
</Directory>

<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.2-fpm.sock|fcgi://localhost/"
</FilesMatch>

SSLEngine on
SSLCertificateFile /etc/ssl/virtualmin/[site number]/ssl.cert
SSLCertificateKeyFile /etc/ssl/virtualmin/[site number]/ssl.key
SSLProtocol all -SSLv2 -SSLv3 -TLSv1 -TLSv1.1
SSLCACertificateFile /etc/ssl/virtualmin/[site number]/ssl.ca
</VirtualHost>

5. Enable Necessary Apache Modules

Ensure the required Apache modules are enabled:

a2enmod proxy_fcgi setenvif
a2enconf php8.2-fpm

6. Restart Apache

After making these changes, restart Apache to apply the configuration:

systemctl restart apache2

To activate the new configuration, you need to run:

systemctl reload apache2

7. Verify the PHP Configuration

Create a PHP info file to verify PHP is working:

echo "<?php phpinfo(); ?>" > /home/._default_hostname/public_html/info.php

Troubleshooting

  • Apache Error Logs: Check the Apache error logs for any configuration issues:
    tail -f /var/log/apache2/error.log
  • PHP-FPM Logs: Check the PHP-FPM logs for any errors or issues:
    tail -f /var/log/php8.2-fpm.log

Conclusion

By following these steps, you can configure PHP-FPM on a fresh Virtualmin installation’s default website, ensuring efficient PHP script execution.

For more info on Virtualmin, please visit:
https://virtualmin.com

CLICK HERE to find your domain name!   CLICK HERE to transfer your domain name!

Archives

Tags

24 hour (1) Accessibility (2) Accounting (1) Advertising (16) AdWare (1) Alex Johnson (2) Alignment (1) Android (2) Anti-Virus (1) Antivirus (1) Antrim Computer Repair and Service (3) APC Back-UPS (1) Appearance (2) Apple Mail (4) Apple Mobile Mail (2) Attachments (1) Audit (1) Authorized (1) Autoresponder (5) Availability (1) Backups (1) Badges (3) Bank Account (1) Bank Statement (1) Battery Backup (2) Better Business Bureau (3) Bob Hill (1) Bookkeeper (1) Branding (8) Budget (2) Business (29) Business Management (1) Catalog (1) Categories (1) Charles Oropallo (1) CharlesWorks (42) Cherryl Jensen (1) Chrome (1) CleanTalk (1) Cloud (1) Code (2) Communicating (1) Competition (1) Computer (2) Computer Cache (1) Computer Hardware (1) Computer Security (2) Constant Contact (1) Consultation (1) Contact Information (2) Content (1) Content Management (39) Content Management System (1) Copiers (1) Copy Machine (1) Coronavirus (2) Courteous (1) COVID-19 (3) Credibility (9) Credit Card (1) Credit Card Processing (1) CSS (9) Customer Service (2) Database (1) Debian (1) Design (49) Design Expertise (1) Desktop (1) Dialup (1) DirectAdmin (4) Directions (1) DIVI (7) DNS (2) Do-it-Yourself (1) Documentation (1) Domains (18) Domain Transfers (5) E-Commerce (1) ecommerce (1) Elementor (1) Email (65) Email Lists (4) Email Management (4) Email marketing (4) Etiquette (3) Eudora 6 (1) Exchange (1) Expanding (1) Facebook (2) Financial (1) Finish (1) Firefox (1) Fonts (1) Forms (2) Forms Protection (1) Fraud (2) Galaxy S4 (1) General Info (1) Gmail (1) GoDaddy (1) Google (1) Google Adwords Certified Partner (1) Google Chrome (2) Groups (1) Happy Holidays (1) Hardware Help (1) Hill Specialty Networks (1) Hosting (1) Images (1) IMAP (1) include (1) Infected (1) Information (36) insert pages (1) Internet Browsing Errors (1) Internet Consultant (1) Internet Explorer (1) Joomla! (1) Keywords (2) Laptop (1) Legibility (1) Linux (12) Logging on (1) Macintosh (1) Mail 6.0 (1) Mail 2011 (2) Make-Over (1) Malicious (1) Malware (1) Marketing (8) Matt Burke (3) MDaemon (3) MelbourneIT (2) menu (1) Merchant (1) meta (1) Microsoft (1) Microsoft Edge (1) Microsoft Hosted Exchange (5) Microsoft Live (2) Mobile Email Setup (1) Monadnock Region (1) Mozilla Firefox (2) MySQL (1) Nathan Wesley (1) Netscape (1) Netscape Messenger (1) Office Copiers (1) OfficeLive (1) Online (1) Outlook (9) Outlook 2010 (2) Outlook Express (1) PayPal (1) Pay Per Click (2) PC (1) Personal (1) Peter Harris (1) Peter Harris Creative (1) Phishing (2) PHP (3) pixel (1) plugins (1) Pop Email (1) Popularity (1) Portfolio (1) Power Grid Failure (1) PPC (1) Prevent Fraud (1) Privacy (1) Private (1) Product (6) products (1) Professional (6) Projects (2) Protect (1) Protection (1) QR codes (1) Quality (2) QuickBooks (1) Reconciliation (1) Reduce Risk (1) Register (1) Reliability (2) Renew (1) Reseller (2) Resolution (1) Restrict User Access (1) Results (1) Review (2) Risk (1) Robin Snow (1) Roundcube (1) Safe (1) Samsung (2) Scam (18) Scammer (18) Search (1) Search and Replace (1) Search Engine Optimization (SEO) (21) Security (28) Security Risk (1) Selling (1) Servers (2) Service (11) Shopping Cart (1) Site (1) SmarterMail (9) Social Engineering (1) Social Networking (1) Software (1) solar flares (1) Solutions for Today (1) Spam (1) Spam Filtering (16) Spammer (1) Spyware (2) SquirrelMail (1) SSL (8) Statistics (2) Stats (2) Stone Pond Technology (1) Storage (1) Support (1) Tablet (1) Target Market (1) Technical Help (1) Testimonials (9) The CW Corner (1) Thom Little (1) Thom Little Associates (1) Thunderbird (3) Thunderbird 10 (2) TLD (1) Topic (1) Top Level Domains (3) Transaction (2) Transfer Data (1) Transfer Funds (1) Typography (1) Update (2) Uploading (1) UPS System (2) Up to Date (1) Virtualmin (1) Virus (2) Viruses (1) Vista (1) Web (1) Web-Over (1) Web Development (102) Web Hoster (1) Web Hosting (2) Web Hosting Company (1) Webmail (8) Web Mail (1) Webmaster (10) Webmin (1) Web Presence (28) Website (114) Website Development (1) websites (2) Web Stats (1) Web terms (1) Web Writing (1) Windows 7 (2) Windows Mail (6) Windows XP (1) WooCommerce (6) WordPress (90) WordPress Updates (1) Working Remote (2) Writing (1) YouTube (1)
Protected by CleanTalk Anti-Spam