info.php

My info.php

PHP:
<?php phpinfo(); ?
is not resolving.

Can anyone see what I could have missed by installing Apache with this code?
sh:
#!/bin/sh

# Ensure the script is run as root
if [ "$(id -u)" -ne 0 ]; then
  echo "This script must be run as root!"
  exit 1
fi

# Step 1: Update system and install required packages
echo "Updating the system and installing Apache, PHP-FPM, and required modules..."
pkg update && pkg upgrade -y
pkg install -y apache24 php84 php84-mysqli php84-mbstring php84-session php84-gd php84-curl php84-zip

# Step 2: Enable and start Apache and PHP-FPM services
echo "Enabling and starting Apache and PHP-FPM services..."
sysrc apache24_enable=yes
sysrc php_fpm_enable=yes
service apache24 start
service php-fpm start

# Step 3: Configure Apache to use PHP-FPM
echo "Configuring Apache to use PHP-FPM..."
echo "LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so" >> /usr/local/etc/apache24/httpd.conf
echo "AddHandler php-fcgi .php" >> /usr/local/etc/apache24/httpd.conf
echo "Action php-fcgi /php-fcgi" >> /usr/local/etc/apache24/httpd.conf
echo "Alias /php-fcgi /usr/local/www/php-fpm" >> /usr/local/etc/apache24/httpd.conf
echo "FastCgiExternalServer /usr/local/www/php-fpm -socket /var/run/php-fpm.sock -pass-header Authorization" >> /usr/local/etc/apache24/httpd.conf

# Step 4: Configure PHP-FPM to use Unix socket
echo "Configuring PHP-FPM pool to use Unix socket..."
echo "listen = /var/run/php-fpm.sock" >> /usr/local/etc/php-fpm.d/www.conf
echo "listen.owner = www" >> /usr/local/etc/php-fpm.d/www.conf
echo "listen.group = www" >> /usr/local/etc/php-fpm.d/www.conf
echo "listen.mode = 0660" >> /usr/local/etc/php-fpm.d/www.conf
echo "user = www" >> /usr/local/etc/php-fpm.d/www.conf
echo "group = www" >> /usr/local/etc/php-fpm.d/www.conf

# Step 5: Restart services to apply changes
echo "Restarting Apache and PHP-FPM services..."
service apache24 restart
service php-fpm restart

# Step 6: Create a PHP info page to test the installation
echo "Creating a PHP info page..."
echo "<?php phpinfo(); ?>" > /usr/local/www/apache24/data/info.php

# Step 7: Enable PF firewall and allow HTTP/HTTPS traffic (if PF is enabled)
echo "Configuring firewall to allow HTTP/HTTPS traffic..."
sysrc pf_enable=yes
echo "pass in on egress proto tcp to any port {80, 443}" >> /etc/pf.conf
service pf start

# Final message
echo "PHP-FPM and Apache setup complete!"
echo "You can test your setup by visiting http://your-server-ip/info.php"
echo "Remember to delete the info.php page after testing: rm /usr/local/www/apache24/data/info.php"
 
is not resolving.
What do you mean? It's not rendering the phpinfo page? Or are you seeing the actual php code as text in your browser?

Also, you seem to use CGI, which is an old, and entirely different, way of using a scripting engine (or plain executables).
 
Code:
<?php phpinfo(); ?>
This isn't CGI, it's PHP embedded in an HTML document.
Why do you think it's CGI ?

I'm just trying to show this.


1775039990315.png


I did it a few days ago but am having problems recreating it.
 
Why do you think it's CGI ?
It's not, that's the point. You configured Apache to use PHP as (Fast)CGI, not PHP-FPM:

Code:
echo "AddHandler php-fcgi .php" >> /usr/local/etc/apache24/httpd.conf
echo "Action php-fcgi /php-fcgi" >> /usr/local/etc/apache24/httpd.conf
 
Code:
% cat /usr/local/etc/apache24/modules.d/001_php-fpm.conf
LoadModule proxy_module libexec/apache24/mod_proxy.so
LoadModule proxy_fcgi_module libexec/apache24/mod_proxy_fcgi.so

<IfModule proxy_fcgi_module>
  <IfModule dir_module>
     DirectoryIndex index.php
  </IfModule>
  <FilesMatch "\.(php|phtml|inc)$">
     SetHandler "proxy:fcgi://127.0.0.1:9000"
  </FilesMatch>
</IfModule>

You're going to want to change that 'proxy' address to use the socket.
 
Code:
root@freya ~>  service apache24 start
Cannot 'start' apache24. Set apache24_enable to YES in /etc/rc.conf or use 'onestart' instead of 'start'.
root@freya ~>  service php_fpm start
Cannot 'start' php_fpm. Set php_fpm_enable to YES in /etc/rc.conf or use 'onestart' instead of 'start'.

service xyz start doesn't work in your scenario; It only works if you have stoped the service before.
 
It's not, that's the point. You configured Apache to use PHP as (Fast)CGI, not PHP-FPM:

Code:
echo "AddHandler php-fcgi .php" >> /usr/local/etc/apache24/httpd.conf
echo "Action php-fcgi /php-fcgi" >> /usr/local/etc/apache24/httpd.conf
Sorry, I was just copying code and running it without really knowing what I was doing.
 
Back
Top