![]() ![]() Access to anything that should be public has to be specifically allowed. In the nf file, there’s a section which denies access to any resource by default. Make sure to change this path, along with the other instance of it in the section, to the actual path of your website on your machine! The DocumentRoot directive specifies the location in the file system where the files to be served exist. Apache will find the virtual host with the corresponding hostname and serve that site. When we visit my-project.test in the browser, the change we made to /etc/hosts will make sure the request is sent to the local Apache server. ServerName sets the hostname for the virtual site. Then, let's configure an actual virtual host: Otherwise, Apache will emit some warnings on startup, as the document roots for these sites likely don't exist. Start by deleting or commenting out the existing dummy virtual hosts in the file. ![]() Earlier, we uncommented a line in order to include the /opt/homebrew/etc/httpd/extra/nf file. We still need to add configuration for each virtual host separately. We’ve now set up Apache to support PHP and virtual hosts. ![]() While most files are just served using a built-in handler, the PHP files have to be passed through the PHP interpreter before being served. A handler in Apache represents an action to take for a file. php, and set their handler to application/x-httpd-php - a handler provided by the PHP module. However, these files may get edited independently of each other, so let’s follow the convention of the other files in the extra directory and check that the modules we use are available. We start by checking if the PHP module is available, which might seem redundant as we just added it in the nf file. The rest of our PHP configuration goes in the file /opt/homebrew/etc/httpd/extra/nf: We need to include it explicitly from the main configuration file, so find the section with Include directives and add this after the last one: # PHP settings Let’s add further PHP configuration in a separate file in the extra directory, just like Apache does for the virtual hosts configuration by default. There is some additional configuration required. For this, we’ll add another LoadModule directive after the other ones, loading a module provided by PHP as installed through Homebrew earlier: LoadModule php_module /opt/homebrew/opt/php/lib/httpd/modules/libphp.so We want PHP to be available on our server. However, to silence the warning message, we’ll uncomment the default ServerName directive in nf (or just enter any hostname you want): ServerName 4. We’ll set the hostname on a per-virtual host basis later. This module will likely be useful, so let’s enable it by removing the # below: #LoadModule rewrite_module lib/httpd/modules/mod_rewrite.soĪpache comes with configuration for a default site, with a document root of /opt/homebrew/var/As it stands, everything would work, but Apache would emit a warning every time it started, stating that it can’t determine the hostname to use for this default site. For example, many web frameworks use it to enable “pretty URLs”, letting site visitors use URLs like /posts/2021/some-post-title/ while translating them into URLs like /index.php?p=697 for the back-end. This module is used to rewrite/incoming URLs. We’ll uncomment another line in order to load the mod_rewrite module. Virtual host support has to be enabled by removing the # in front of the line below, turning it from a comment into an Apache directive that loads the virtual hosts configuration from the file in question: #Include /opt/homebrew/etc/httpd/extra/nf To serve multiple sites from one Apache server, Apache can look at the hostname of the incoming request and pass the request to one of multiple virtual hosts. Requests to any of these hostnames will hit the same Apache server. However, as HTTP traffic goes to port 80 by default, we want to listen on that port instead: Listen 80Ĭhances are, you want to run multiple websites on your computer, with several hostnames in /etc/hosts. Accessing ports with numbers lower than 1024 require root privileges and so, listening on port 8080 lets users run Apache without being root. This line tells Apache to listen for traffic on the port 8080. In this file, there are a few changes to make: Listen 8080 In my case, the main Apache configuration file is located at /opt/homebrew/etc/httpd/nf (as mentioned, on an Intel-based Mac, this is likely to be /usr/local/etc/httpd/nf). Next, let’s get to work on the actual Apache configuration. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |