Since your Apache configuration file is located at /opt/homebrew/etc/httpd/httpd.conf, follow these steps to enable PHP 7.4:
Step 1: Edit the Apache Configuration File
1. Open the configuration file:
sudo nano /opt/homebrew/etc/httpd/httpd.conf
2. Load the PHP 7.4 Module:
In the httpd.conf file, search for any existing LoadModule php lines (press Ctrl + W in nano to search) and either comment them out or replace them with the following line to load the PHP 7.4 module from Homebrew:
LoadModule php7_module /opt/homebrew/opt/php@7.4/lib/httpd/modules/libphp7.so
3. Add PHP Handling for .php Files:
Ensure that Apache handles .php files correctly by adding or ensuring the following line is present:
AddType application/x-httpd-php .php
4. Update Directory Index:
Make sure Apache serves PHP files as the default when accessing a directory. Find the line that starts with DirectoryIndex and ensure it includes index.php:
DirectoryIndex index.php index.html
Step 2: Restart Apache
After making the changes, restart Apache to apply the new settings:
sudo apachectl restart
Step 3: Test PHP 7.4
To verify that PHP 7.4 is running:
1. Navigate to your web root directory (this is usually /opt/homebrew/var/www/):
cd /opt/homebrew/var/www/
2. Create a test PHP file:
sudo nano info.php
3. Add the following PHP code:
<?php phpinfo(); ?>
4. Visit http://localhost/info.php in your browser. You should see the PHP information page, confirming that PHP 7.4 is correctly set up.
==========================================================================
sudo apachectl restart
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using Mds-MacBook-Pro-2.local. Set the ‘ServerName’ directive globally to suppress this message
The message you are seeing is a common Apache warning and doesn’t usually affect the functionality of the server. However, you can suppress it by setting the ServerName directive in your Apache configuration file. Here’s how you can fix this:
Step 1: Edit the Apache Configuration File
1. Open the Apache configuration file for editing:
sudo nano /opt/homebrew/etc/httpd/httpd.conf
2. Set the ServerName Directive:
Look for a place near the top of the configuration file, or search for an existing ServerName directive. If you don’t find one, add the following line to set the ServerName to localhost:
ServerName localhost
Step 2: Restart Apache
sudo apachectl restart
Step 1: Set Up the Virtual Host
To set up virtual hosts on macOS with Apache, follow these steps:
Step 1: Edit the Apache Configuration File
1. Open the Apache configuration file (httpd.conf):
sudo nano /opt/homebrew/etc/httpd/httpd.conf
It should now look like this:
Include /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
sudo nano /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
<VirtualHost *:8080>
ServerAdmin webmaster@mysite.test
DocumentRoot “/Users/mdanwarhossain/Sites/mysite”
ServerName mysite.test
ErrorLog “/private/var/log/apache2/mysite-error_log”
CustomLog “/private/var/log/apache2/mysite-access_log” common
<Directory “/Users/mdanwarhossain/Sites/mysite”>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
======================
1. Open the /etc/hosts file to map your local domain to localhost:
sudo nano /etc/hosts
127.0.0.1 mywebsite.test
127.0.0.1 anotherwebsite.test
127.0.0.1 mysite.test
sudo chmod -R 755 ~/Sites/
sudo apachectl restart
Forbidden
You don’t have permission to access this resource.
sudo chmod -R 755 /Users/yourusername/Sites/mysite
tail -f /private/var/log/apache2/mysite-error_log
AH00035: access to / denied (filesystem path ‘/Users/mdanwarhossain/Sites’) because search permissions are missing on a component of the path
sudo chmod +x /Users/mdanwarhossain
sudo chmod -R 755 /Users/mdanwarhossain/Sites
sudo apachectl restart
Link navigation showing not found
sudo nano /opt/homebrew/etc/httpd/httpd.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [L]
sudo nano /opt/homebrew/etc/httpd/extra/httpd-vhosts.conf
ServerAdmin webmaster@mysite.test
DocumentRoot “/Users/mdanwarhossain/Sites/mysite”
ServerName mysite.test
ErrorLog “/private/var/log/apache2/mysite-error_log”
CustomLog “/private/var/log/apache2/mysite-access_log” common
<Directory "/Users/mdanwarhossain/Sites/mysite">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
sudo apachectl restart
Leave a Reply