Apache references wrong httpd.conf after Mac OS X Sierra upgrade - macos

I've recently upgraded to Mac OS X Sierra and it has totally shafted my apache/PHP setup. Having wasted most of the morning, I've finally found the actual httpd.conf file that is being referenced at /usr/local/etc/apache2/2.2/httpd.conf, whereas the file I need to be using is at /etc/apache2/httpd.conf.
How can I tell Apache to use the version I was successfully using before the update?

Not sure about MacOS version, but with any binary of httpd you use the parameter -f, as in:
httpd -k start -f /path/to/conf
In most cases you need to load envvars file in your environment, this file is in bin directory in an official install of httpd and generally adds HTTPD lib directory to LD_LIBRARY_PATH.
So briefly
. /path/to/httpd/bin/envvars
httpd -k start -f /path/to/conf
Or apachectl which is an official script which refers to both to make your life easier.

Related

Changing default Apache version on Mac OS

A security sweep of my network (using Nessus) revealed that my mac is running a version of Apache (2.4.46) with a few critical vulnerabilities. I've been told I need to upgrade to at least 2.4.47. I'm having issues getting MacOS to use the upgraded version over the default one:
The default httpd is located at /usr/sbin/, which is read only even as root. As far as I'm aware upgrading the default Mac OS version is not a possibility.
Installed a newer version of Apache (v2.4.48) using Homebrew. The homebrew version is located in /usr/local/bin/httpd and as long as /usr/local/bin is before /usr/sbin in the env path it should be the preferred version.
Running httpd -v in the terminal returns v2.4.48, but the vulnerability scan is still picking up the old version of Apache
What am I missing? Why is the OS picking up the old version? Do I simply have to wait for Apple to patch it? Is it even possible to upgrade /usr/sbin/httpd?
Two things here, how to set the default apache version, and whether your machine is vulnerable.
firstly, you can have multiple versions of apache installed, and even running simultaneously (listening on different ports). Installing homebrew apache, doesn't necessarily start the server automatically, or deactivate the default (apple) apache install.
You can see which versions of apache are running on your system by using the ps command, for example on my machine:
$ ps auxw | grep httpd
_www 782 0.0 0.0 34153280 1476 ?? S 26May22 0:00.83 /usr/sbin/httpd -D FOREGROUND
and check the version:
$ /usr/sbin/httpd -v
Server version: Apache/2.4.53 (Unix)
The apple httpd service is started by launchctl, and you can stop the apple httpd service from automatically starting up as follows:
$ sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist
To automatically start homebrew apache on system startup (assuming you have already installed it - brew install httpd), run brew services start httpd
Remember that the apache configuration files will be in a different location - apple conf file is /etc/apache2/httpd.conf, whereas homebrew's is in /usr/local/etc/httpd/httpd.conf. Also the default port may well be different - apple defaults to port 80 whereas homebrew httpd listens on port 8080 by default.
Secondly, does this security issue actually matter? By default apache listens on all network interface, but unless you need to access the web server from another machine, it is safer to configure it to only listen on localhost. You can do this in the httpd.conf file, as follows:
Listen 127.0.0.1:80
This page has a good walkthrough of the various steps: https://wpbeaches.com/installing-configuring-apache-on-macos-using-homebrew/

Which folder to keep projects for Homebrew nginx port 8080

I am using macbook and installed nginx using Homebrew from the terminal. I think i installed 2-3 versions of nginx in different locations. Now I can see my http://localhost:8080/ is working as it displays nginx home page in browser but how can I place my projects inside nginx? I tried to put those in one of the nginx directory but it does not work if if I try to go to project through browser.
Is there anything from where I can find the exact directory of this running version of nginx?
Use the brew list command:
$ brew list nginx
/usr/local/Cellar/nginx/1.10.1/bin/nginx
/usr/local/Cellar/nginx/1.10.1/homebrew.mxcl.nginx.plist
/usr/local/Cellar/nginx/1.10.1/html -> ../../../var/www
/usr/local/Cellar/nginx/1.10.1/share/man/man8/nginx.8
$ greadlink -f /usr/local/Cellar/nginx/1.10.1/html
/usr/local/var/www
Thus, the symlink links to /usr/local/var/www, and default configuration is likely to do likewise.

I have 2 versions of Apache running on my system

There is another version of apache running on my system.
When in run sudo apachectl stop I still get the "It Works" page
So I found the location of the other version that is still running and it looks to be an older version which probably came pre-installed and is located in /opt/local/apache2/.
I tested this file /opt/local/apache2/htdocs/index.html.sample by just changing the text and then checked the browser again.
Server: Apache/2.2.29 (Unix)
I want to remove that one and keep the latest version which is located in private/etc/apache2
Server version: Apache/2.4.9 (Unix)
How can I do this safely.
I managed to fix this
I ran ps aux | grep apache to see the apache processes
I then ran sudo apachectl stop
Then sudo killall -9 httpd to kill all apache processes
Then sudo apachectl restart
I went to the browser and typed localhost~/username/sitename
Bingo it works again, my system is using the correct version of apache again!

Does reinstalling Macports remove/destroy contents of /opt/local/ directory structure?

I'm running a MacPro G5 w/ 10.5.8. I ran:
sudo port selfupdate and then ran:
sudo port upgrade outdated
When it was all finished, I rebooted and apache2 was broken and would not serve PHP file any longer. If I replace the httpd.conf file, it will serve html files.
I finally gave up and restored the backup and the machine is running again. The problem is I have a second machine that I did the same thing on and don't want to go through the same process. I've read several posts about uninstalling/reinstalling Macports like this one from Kirk Roybal How to do a clean reinstall with macports?, but it doesn't say if this process will destroy or reset the contents of the /opt/local/ directory. Especially the MySQL DBs and htdocs contents. Does anyone know if this process is linked or destructive? I'll make backups of everything, of course, before trying anything.
SOLUTION:
I got it to work by making the php53 install work instead of going backwards. Here's what I did:
sudo port select --set php php53 (set MacPorts to use php53 instead of php5)
sudo port installed (Check to make sure php53-apache2handler is installed)
sudo port install php53-apache2handler (It wasn't and yours probably isn't either)
once that's done installing
php -v (check the version of PHP that's running)
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php mod_php53.so (activates php within apache)
this should append
LoadModule php5_module modules/mod_php53.so
to your /opt/local/apache2/conf/httpd.conf file (check it now)
There will also be a line like this
LoadModule php5_module modules/mod_php5.so
Comment it out or remove it so is doesn't interfere with new install
It should also move a copy of mod_php53.so to
/opt/local/apache2/modules
If it's not there, see php53-apache2handler install above.
Check your httpd.conf file for errors
/opt/local/apache2/bin/httpd -S
Finally, create/edit php.ini file to tell apache2 how to connect to MySQL database
cd /opt/local/etc/php53
sudo cp php.ini-production php.ini (for production machine use development for dev machine)
sudo cp php.ini php.ini.bak
Add the default socket paths to php.ini
pdo_mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock (may vary based on MySQL version. Check the /opt/local/var/run directory if not sure)
mysql.default_socket=/opt/local/var/run/mysql5/mysqld.sock
mysqli.default_socket=/opt/local/var/run/mysql5/mysqld.sock
If you are having problems connecting to MySQL, check for typos in the above paths FIRST. Trust me it will save you tons of time!
If all went according to plan, you should be able to restart the machine, test to make sure all ports started automatically and things should be working.
The files that you add (eg: MySQL DBs) are not destroyed by an update. If you modify files that are managed by MacPorts (eg: they are listed in 'port contents '), then those modifications will be clobbered by an update.
Some projects install config files as examples and have the user make the real config file so as to not clobber it with an update. It looks like the apache2 port follows this pattern. It installs /opt/local/apache2/conf/original/httpd.conf and then copies it to the real location of /opt/local/apache2/conf/httpd.conf at activation time only if the file does not exist.

Apache "LoadModule passenger_module" works when "apachectl -k start" is invoked from bin directory, but not with bash script

I'm using
mac OS 1.8.3
RVM 1.19.6
Ruby ruby 1.9.3p327
Apache 2.4
Phusion Passenger 3.0.19
After an error free install of Apache I launched the server and it worked.
I wrote a 'start_apache.sh' script:
#!/bin/bash
sudo /usr/local/apache2/bin/apachectl -k start
... which worked.
I then installed phusion passenger without error.
When I ran my start_apache.sh script, I got this error
httpd: Syntax error on line 504 of /usr/local/apache2/conf/httpd.conf:
Cannot load
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
into server:
dlopen(/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19/ext/apache2/mod_passenger.so,
10): Symbol not found: _unixd_config\n Referenced from:
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19/ext/apache2/mod_passenger.so\n
Expected in: flat namespace\n in
/Users/perry_mac/.rvm/gems/ruby-1.9.3-p327/gems/passenger-3.0.19/ext/apache2/mod_passenger.so
After following ++ a lot ++ of 'Can't loadModule' Q&A's, I tried
cd /usr/local/apache2/bin
sudo apachectl -k start
... and it worked.
Using the script still does not.
Can someone explain why?
Many thanks!
Maybe it has to do with the working directory. Try this:
#!/bin/bash
cd /usr/local/apache2/bin/ && sudo ./apachectl -k start
Maybe this is some issue with user profile. Could you check environmental paramentrs values?
Thank you rzymek.
Your insight lead me to try this:
perrys-MacBook-Pro:bin perry_mac$ ls
ab apxs dbmmanage envvars-std htcacheclean htdigest httpd logresolve
apachectl checkgid envvars fcgistarter htdbm htpasswd httxt2dbm rotatelogs
perrys-MacBook-Pro:bin perry_mac$ pwd
/usr/local/apache2/bin
perrys-MacBook-Pro:bin perry_mac$ which apachectl
/usr/sbin/apachectl
perrys-MacBook-Pro:bin perry_mac$
Here's what happened: I downloaded, built, and installed apache 2.4. Did not know mac OSX 10.8.3 still had a working apache installation. I had read some web posts about how Apple had "removed web sharing" from this OS version. Turns out that means they removed a GUI element, but left the server in place. As you can see, I now have two versions of apachectl and httpd. I am untangling the rest of the mess now. As a follow-up, if anyone has advice on how to best proceed, please comment below. Otherwise I am going to start by modifying $PATH and see how that goes.
ADDENDUM:
Looks like this lead to a component of my confusion:
http://www.modrails.com/documentation/Users%20guide%20Apache.html#_phusion_passenger_is_using_the_wrong_apache_during_installation
... but the link leads to no remedy (as of 5/5/2013). There must be an option to set during the phusion passenger installation to ensure it points to the desired apache installation, but I can't locate it.
In the end, I removed the ver 2.4 of apache that I built and reverted to the ver 2.2 that is included with the OS. So far, it's all working.

Resources