Apache 2.4 SetEnv not working - php

I'm trying to set a local environment variable to test my PHP app on a windows machine. I added SetEnv API_HOST /foo/bin in the file C:\Apache24\conf\httpd.conf and restarted the server by executing httpd -k restart at the command line.
In my app I check the variable $_SERVER['API_HOST'] and I always get null and it isn't null in the development server since the environment variable is set there.
I also tried to create confs files, set the env variable and include the files in the httpd.conf, but also doesn't work.
I was expecting this to be straight forward, but it seems something is missing. Any idea why it isn't working?
Thanks.

Sorry, forgot to answer earlier. It started working with the following in the httpd.conf:
<VirtualHost *:80>
DocumentRoot "path/to/project-root"
ServerName localhost
SetEnv API_HOST /foo/bin
</VirtualHost>
And restart the apache server by going to the path C:\Apache24\bin on the cmd and execute httpd -k stop and httpd -k start. I tried httpd -k restart several times before and didn't work, don't know why.
Cheers

Related

Apache is using a different port and Document Root than is in the config file

I am trying to get apache running locally with php, but for some reason, my apache is running on port 8080 instead of port 80 and it is using a different document root than is defined in the httpd.conf
When I run /usr/sbin/httpd -V it tells me where my server config file is
-D SERVER_CONFIG_FILE="/private/etc/apache2/httpd.conf"
I went to that file and it has this for Listen:
<IfDefine SERVER_APP_HAS_DEFAULT_PORTS>
Listen 8080
</IfDefine>
<IfDefine !SERVER_APP_HAS_DEFAULT_PORTS>
Listen 80
</IfDefine>
And this for document root:
DocumentRoot "/Library/WebServer/Documents"
apachectl -S also says Main DocumentRoot: "/Library/WebServer/Documents"
Earlier today it was saying /usr/local/var/www but i fixed that, but apache is still using /usr/local/var/www as the document root. Any ideas on what's causing this? My apache server is also not running the php it is just showing as plain text, not sure if that is related or not
Finally figured it out, I ran /usr/local/opt/httpd/bin/httpd -V | grep SERVER_CONFIG_FILE and that gave me -D SERVER_CONFIG_FILE="/usr/local/etc/httpd/httpd.conf" which was the actual config file it was using, I fixed that one and now its working.

Could not reliably determine the server's fully qualified domain name for MacBook

First time got a new MBP 2016. Trying to setup PHP,MySQL & Apache. Started Apache by using command
sudo apachectl restart
Then installed PHP by
brew install php71 --with-httpd24
Also did following changes...
#
# DirectoryIndex: sets the file that Apache will serve if a directory
# is requested.
#
DirectoryIndex index.html index.php
SetHandler application/x-httpd-php
ServerName dev-server
Also, updated the same in host file /etc/hosts/
But, whenever I'm trying to Stop/Restart my apache by using command sudo apachectl restart or sudo apachectl stop I'm getting following errors.
AH00557: httpd: apr_sockaddr_info_get() failed for Sureshs-MacBook-Pro.local
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
httpd not running, trying to start
But, strangely when I'm executing any PHP file from my browser http://localhost/index.php it's working fine. As in my index.php file I'm using code <?php phpinfo(); ?> It's showing PHP version PHP Version 7.1.4 loaded.
Tried a lot but no clude what's going wrong at where.
---UPDATE---
After updating 127.0.0.1 Sureshs-MacBook-Pro.local in my /private/etc/hosts file, one error solved. Now I'm getting only one below error.
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using Sureshs-MacBook-Pro.local. Set the 'ServerName' directive globally to suppress this message
Finally, I solved this by updating ServerName localhost:8080 on file /usr/local/etc/apache2/2.4/httpd.conf. It was a differnt httpd.conf file which I didn't knew about it.
Also, for Apache start/restart/stop following command sudo /usr/sbin/apachectl start works for me.
As per message:
Set the 'ServerName' directive globally to suppress this message.
You need to identify httpd.conf Apache configuration file by:
apachectl -t -D DUMP_INCLUDES
then edit it and uncomment the line with ServerName (make sure it has the valid server name). E.g.
ServerName localhost
open file httpd.conf
vi /etc/httpd/conf/httpd.conf
add to first line
ServerName localhost
systemctl restart httpd
I resolved this issue changing the port address in the httpd.conf file in windows.
This problem arises due to the port already listening, which we use in the conf file.
To view the port listening, use the command "netview /a"
if the port used in the conf file already listening, change to different one(e.g, 8080)
set servername to "localhost" or 127.0.0.1
Now start the apache server "httpd.exe -k start"
it will work fine.
On macOS Catalina...
Edit the Apache config file
sudo vi /etc/apache2/httpd.conf
Find the ServerName entry by typing a / followed by ServerName and hit enter
Press n to go to the next occurrence until you are on #ServerName www.example.com:80 (keep pressing n if you go past it)
Add a newline by typing an o
Type the following: ServerName localhost
Save and exit by typing !wq then hit enter (or type ZZ which is capital Z twice)
Restart Apache
sudo apachectl restart

How to set an environmental variable in Apache (or OS) and get the value in PHP?

I made sure the env module was installed:
a2enmod
Your choices are: access_compat
...
Which module(s) do you want to enable (wildcards ok)?
env
Module env already enabled
I tried setting an environmental variable in "/etc/apache2/apache2.conf" for localhost by adding the following section:
<VirtualHost *:80>
ServerName localhost
ServerAdmin me#somewhere.com
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SetEnv devmode 1
</VirtualHost>
...restarted Apache using:
sudo /etc/init.d/apache2 restart
...and then getting the value in PHP using:
getenv("devmode")
or:
apache_getenv("devmode")
...but nothing shows up with these functions when accessing the script via a browser on localhost, the values are empty in PHP. I tried placing the command on it's own, without the VirtualHost section:
SetEnv devmode 1
I tried adding the following line to envvars:
export devmode=1
Update
I also tried putting the VirtualHost section in a dedicated file in /etc/apache2/sites-available, and adding the file with a2ensite.
I am using Linux Mint version 17.3. What am I doing wrong?
Have you tried apache_getenv ?
After putting the VirtualHost section into a dedicated file, as I described in the original question, I found that the solution was to run the Apache restart command again:
sudo /etc/init.d/apache2 restart
Then the devmode variable showed up in PHP.

wamp apache 2.4.9 not started after adding virtual host in httpd.conf

I am using wamp (php v 5.5.12, apache v 2.4.9). When I start the apache server the icon becomes green as if everything is fine. I can access to all services with no problem. When I try to add a virtual host to configure in httpd.conf for my symfony project apache will not restart.
<VirtualHost *:80>
   DocumentRoot C:\wamp\www\tuto\Symfony\web
    <Directory "C:\wamp\www\tuto\Symfony\web">
        DirectoryIndex app_dev.php
        Options -Indexes FollowSymLinks SymLinksifOwnerMatch
        AllowOverride All
        Allow from All
    </Directory>
</VirtualHost>`
The server icon then stays in yellow instead of green and I can't access to localhost url. When I remove my config, everything becomes normal again. Please help me to understand how I can resolve this.
You have a single-quote at the end of:
</VirtualHost>`
Remove it.
You can use the symfony 2 built in server . first undo any changes on your httpd.conf
open your cmd and do this:
cd C:\wamp\www\tuto\Symfony\web
next
php app/console server:run
now try this on your browser: http://127.0.0.1:8000
this is equal to : http://localhost/tuto/Symfony/web/app_dev.php
if you want to start web server on your local ip use this
php app/console server:run yourIP:port
It's solved, thank you guys !
What I did :
1-Adding my conf in httpd-vhost.conf with ServerName parameter
ServerName www.project.com inside section as #skrilled said.
2-In the httpd.conf, Uncomment this line : Include conf/extra/httpd-vhosts.conf
3-In the system file "hosts", I added this line : 127.0.0.1 www.project.com

Configuring HHVM 3.7 with Apache 2.4 gives me a 404?

I can't seem to configure HHVM and Apache, it keeps giving me a 404 file not found error. My configuration file for the website is saved as www.example.com.conf, it contains:
<VirtualHost *:80>
ServerName website.com
ServerAdmin mail#website.com
DocumentRoot /var/www/website.com/public_html/
ProxyPassMatch ^/(.*\.php(/.*)?)$ fcgi://127.0.0.1:9000/var/www/website.com.com/public_html/$1
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Note that I've removed my actual website name, but it's for a subdomain so it's this: subdomain.xyz.com. I've tried looking up how to fix this, but whatever I've tried doesn't seem to work; even the GitHub issues people have posted on the official repository don't seem to work. I also haven't changed the default apache configuration, the only thing I have changed is the root directory of my website which does much up to the directory in the configuration file above.
Any ideas? Thanks.
I know it's been two months already, but maybe it helps someone else (I had a similar issue occur many times when configuring HHVM + Apache2).
Try to enable the vhost if you haven't yet done so. Issue sudo a2ensite www.example.com and reload apache afterwards with sudo service apache2 reload.
If the vhost is ok and you have your browser requests visible in the vhost access log, then it means that it's not Apache2 that's the culprit there.
So if you're still with me and the first two steps didn't help, try the following, although in HHVM 3.7 it shoulnd't be the case anymore (but it might, I just follow the try-and-check method when it comes to configuring HHVM, and it usually works). Open /etc/hhvm/server.ini and append the following line to that file:
hhvm.server.fix_path_info = true
After changing the HHVM's configuration, issue sudo service hhvm restart. Then try to refresh your website. It should be all good.
I had similar issues and back then it was the most common fix on all webservers I configured to work with HHVM. But, after the latest updates, I had to comment that line out of my hhvm server.ini in order for my code to work - I read that they have somehow changed the parameters of the server and this parameter does no good anymore, AFAIK.
I have also tried to put that line in /etc/hhvm/php.ini but as far as I remember, it should go to server.ini because it's a server parameter.
So. Try it and let me know if that helped. If not then please issue the following commands on your webserver and paste the output here, so I can see if you have the necessary modules installed
ls /etc/apache2/mods-available | grep -E 'proxy|alias|fcgi|hhvm'
ls /etc/apache2/mods-enabled | grep -E 'proxy|alias|fcgi|hhvm'
Oh, and please include your full HHVM and Apache2 version output:
hhvm --version
apache2 -v

Categories