Configuring Apache Virtual Hosts Produces Strange Notices - php

I have what used to be a typical Apache 2.4 installation on an Ubuntu 16.04 LTS.
There is a /etc/apache2/sites-available/ directory where all configuration files are stored and from where one can enable sites.
Here is one of them titled localhost.conf
<VirtualHost *:80>
ServerName 127.0.0.1
ServerAlias sites.dev
DocumentRoot /var/www/sites/
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/sites>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
I have enabled this site. When I navigate to sites.dev, I see the contents of that directory being listed since it does not have an index.php file. So far, so good.
I then add a info.php file to the same directory which looks like this
<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>
Now, when I navigate to sites.dev/info.php, I see a blank page.
Furthermore, when I look at the /var/log/apache2/error.log, I see entries like these
[Tue Feb 05 22:21:44.281005 2019] [mpm_prefork:notice] [pid 2149] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operat$
[Tue Feb 05 22:21:44.281059 2019] [core:notice] [pid 2149] AH00094: Command line: '/usr/sbin/apache2'
[Tue Feb 05 22:24:55.006296 2019] [mpm_prefork:notice] [pid 2149] AH00169: caught SIGTERM, shutting down
[Tue Feb 05 22:24:56.064108 2019] [mpm_prefork:notice] [pid 2320] AH00163: Apache/2.4.18 (Ubuntu) configured -- resuming normal operat$
[Tue Feb 05 22:24:56.064149 2019] [core:notice] [pid 2320] AH00094: Command line: '/usr/sbin/apache2'
Could someone tell me what is happening? How can I fix this localhost and the local development environment?

I solved it using the following sequence of steps:
Install PHP 7 (even though it was already installed)
apt-get install php
apt-get install php-pear php7.0-dev php7.0-zip php7.0-curl php7.0-gd php7.0-mysql php7.0-mcrypt php7.0-xml libapache2-mod-php7.0
sudo a2enmod proxy_fcgi setenvif
sudo a2enconf php7.0-fpm
sudo service apache2 reload

Related

Windows WSL with Ubuntu LAMP - PHP not executing

I was about to test if Windows 10 Pro with WSL running Ubuntu LAMP stack is already a good options for web development.
I tested 2 guides:
https://www.freecodecamp.org/news/setup-a-php-development-environment-on-windows-subsystem-for-linux-wsl-9193ff28ae83/
https://nickjanetakis.com/blog/using-wsl-and-mobaxterm-to-create-a-linux-dev-environment-on-windows
First I tested with Nginx and PHP7.2 but I had the issue that PHP was not executed but displayed. Then I gave Apache2 a try with PHP7.0 and I have the same issue.
sudo a2enmod php7.0
Considering dependency mpm_prefork for php7.0:
Considering conflict mpm_event for mpm_prefork:
Considering conflict mpm_worker for mpm_prefork:
Module mpm_prefork already enabled
Considering conflict php5 for php7.0:
Module php7.0 already enabled
sudo update-alternatives --set php /usr/bin/php7.0
There was never a PHP5 installed and there is nothing in apache about PHP5.
/etc/apache2/mods-available contains
-rw-r--r-- 1 root root 867 Sep 2 15:31 php7.0.conf
-rw-r--r-- 1 root root 102 Sep 2 15:31 php7.0.load
/etc/apache2/mods-enabled contains the symlinks
lrwxrwxrwx 1 root root 29 Oct 22 12:03 php7.0.conf -> ../mods-available/php7.0.conf
lrwxrwxrwx 1 root root 29 Oct 22 12:03 php7.0.load -> ../mods-available/php7.0.load
php7.0.load contains
LoadModule php7_module /usr/lib/apache2/modules/libphp7.0.so
The module exists at this location.
Apache error.log looks also ok
[Tue Oct 22 14:06:32.548315 2019] [mpm_event:notice] [pid 1779:tid 140213335231424] AH00491: caught SIGTERM, shutting down
[Tue Oct 22 14:06:34.732188 2019] [mpm_prefork:notice] [pid 24776] AH00163: Apache/2.4.41 (Ubuntu) configured -- resuming normal operations
[Tue Oct 22 14:06:34.732298 2019] [core:notice] [pid 24776] AH00094: Command line: '/usr/sbin/apache2'
vHost
<VirtualHost *:80>
ServerAdmin admin#localhost.com
ServerName www.test.me
DocumentRoot /var/www/dev/test
<Directory /var/www/dev/test/>
Options Indexes FollowSymlinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error_www.test.me.log
LogLevel warn
</VirtualHost>
/var/www/dev is a symlink to the mounted windows user dev folder
lrwxrwxrwx 1 root root 19 Oct 22 11:30 dev -> /c/Users/name/dev/
Since Apache and Nginx have have the same issue it might be about the path to or the user/permissions but I couldn't find anything so far.
Would be nice if someone has an idea whats wrong.

Apache not working after macOS Mojave update

Ok, after update macOS from High Sierra to Mojave, Apache with PHP stop working properly, so I did everything as is said in this guide - https://getgrav.org/blog/macos-mojave-apache-multiple-php-versions
but after that, still apache not working properly, sometimes working, sometimes not, and its says in browsers ERR_CONNECTION_REFUSED or other errors like 404 or 500.
In apache log is:
[Tue Oct 02 15:02:23.209423 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:02:23.255957 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:02:23.256008 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
[Tue Oct 02 15:14:37.626645 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:14:37.674603 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:14:37.674672 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
[Tue Oct 02 15:28:40.715060 2018] [mpm_prefork:notice] [pid 14579] AH00173: SIGHUP received. Attempting to restart
[Tue Oct 02 15:28:40.752117 2018] [ssl:warn] [pid 14579] AH01909: www.example.com:8443:0 server certificate does NOT include an ID which matches the server name
[Tue Oct 02 15:28:40.766009 2018] [mpm_prefork:notice] [pid 14579] AH00163: Apache/2.4.35 (Unix) OpenSSL/1.0.2p PHP/7.2.10 configured -- resuming normal operations
[Tue Oct 02 15:28:40.766052 2018] [core:notice] [pid 14579] AH00094: Command line: '/usr/local/opt/httpd/bin/httpd'
I have faced similar issue with PHP 5.6 as it was running fine before Mojave upgrade. I did the following to resolve the issue successfully:
Run the command below
sudo nano /etc/apache2/httpd.conf
make sure the below modules are uncommented:
LoadModule authz_core_module libexec/apache2/mod_authz_core.so
LoadModule authz_host_module libexec/apache2/mod_authz_host.so
LoadModule userdir_module libexec/apache2/mod_userdir.so
LoadModule include_module libexec/apache2/mod_include.so
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
I have added the missing one in httpd.conf
Check the right php module for you (PHP 5.6 ot 7.x) and load the required module too by adding the line or commenting/uncommenting the lines
LoadModule php5_module libexec/apache2/libphp5.so
OR
LoadModule php7_module libexec/apache2/libphp7.so
Comment the one not needed by adding "#" to start of line
Run below commands for apapche restart and test
a. sudo apachectl restart
b. apachectl configtest
Check for any errors there
For PHP 5.6:
In case you were having the php 5 with brew already in system before upgarde and the above changes gives error as below
"httpd: Syntax error on line 180 of /private/etc/apache2/httpd.conf: Cannot load libexec/apache2/libphp5.so into server: dlopen(/usr/libexec/apache2/libphp5.so, 10): image not found"
Then search for libphp5.so in the system and if found copy it to "/usr/libexec/apache2/"
In my case command was
sudo cp ./local/Cellar/php#5.6/5.6.25_1/libexec/apache2/libphp5.so /usr/libexec/apache2/
This all made things working in my system
Further to adang's reply i also had to uncomment this line:
Include /private/etc/apache2/extra/httpd-userdir.conf
in order for it to know what user directories were available.
Within /private/etc/apache2/extra/httpd-userdir.conf
I had to uncomment this line:
Include /private/etc/apache2/users/*.conf
then:
sudo apachectl restart
I had the same issue after installing the Mac OS Mojave.
I have done the following steps and it worked with me:
brew update
then:
brew upgrade
I have edited /etc/apache2/httpd.conf by uncommenting the following line:
LoadModule php7_module libexec/apache2/libphp7.so
Open the terminal and restart the apache server:
sudo apachectl restart
you might find the post on this link helpful
I followed the instructions in the above answers and still got a 403 Forbidden when trying to access my /Users/myuser/Sites/ folder. To fix this I had to change the user in /etc/apache2/httpd.conf from _www to my own user.
To do this edit your httpd.conf file using your favorite editor /etc/apache2/httpd.conf. Look for:
User _www
replace with your user:
User myuser
then restart apache:
sudo apachectl restart
because the topic is the httpd.conf messed up after Mojave upgrade I got also this error during sudo apachectl configtest
Could not reliably determine the server's fully qualified domain name, using XXX. Set the 'ServerName' directive globally to suppress this message
I found out the #ServerName localhost:80 in the httpd.conf was comented out, uncommenting resolved my issue.

WAMP 403 forbidden from external sources

I have read a ton of threads here and elsewhere but none of the suggestions have worked. I installed the latest version of WAMP 64 bit on a fresh install of Windows Server 2012 R2.
I created a subdirectory within the www directory called andrew. In that is an index.html file.
I added the following to the hosts file:
127.0.0.1 andrew
::1 andrew
I added the following to the httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "c:/wamp64/www/andrew"
ServerName andrew
<Directory "c:/wamp64/www/andrew">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
I uncommented the virtual hosts line in httpd.conf
I stopped and started net dnscache
I restarted the WAMP services
I "Put Online" the WAMP server
Regardless, when I access the server from another machine like [server IP address]*/andrew/index.html I get a 403 Forbidden error.
Here is the apache error log ("[SERVER IP]" is really the server's actual IP):
[Fri Apr 22 17:10:32.628356 2016] [mpm_winnt:notice] [pid 4680:tid 424] AH00422: Parent: Received shutdown signal -- Shutting down the server.
[Fri Apr 22 17:10:34.656507 2016] [mpm_winnt:notice] [pid 4444:tid 312] AH00364: Child: All worker threads have exited.
[Fri Apr 22 17:10:34.672087 2016] [mpm_winnt:notice] [pid 4680:tid 424] AH00430: Parent: Child process 4444 exited successfully.
[Fri Apr 22 17:10:34.921723 2016] [auth_digest:notice] [pid 4724:tid 416] AH01757: generating secret for digest authentication ...
[Fri Apr 22 17:10:34.952892 2016] [mpm_winnt:notice] [pid 4724:tid 416] AH00455: Apache/2.4.17 (Win64) PHP/5.6.16 configured -- resuming normal operations
[Fri Apr 22 17:10:34.952892 2016] [mpm_winnt:notice] [pid 4724:tid 416] AH00456: Apache Lounge VC14 Server built: Oct 11 2015 11:49:07
[Fri Apr 22 17:10:34.952892 2016] [core:notice] [pid 4724:tid 416] AH00094: Command line: 'C:\\wamp64\\bin\\apache\\apache2.4.17\\bin\\httpd.exe -d C:/wamp64/bin/apache/apache2.4.17'
[Fri Apr 22 17:10:34.952892 2016] [mpm_winnt:notice] [pid 4724:tid 416] AH00418: Parent: Created child process 4388
[Fri Apr 22 17:10:35.140157 2016] [auth_digest:notice] [pid 4388:tid 312] AH01757: generating secret for digest authentication ...
[Fri Apr 22 17:10:35.171357 2016] [mpm_winnt:notice] [pid 4388:tid 312] AH00354: Child: Starting 64 worker threads.
[Fri Apr 22 17:10:49.899265 2016] [authz_core:error] [pid 4388:tid 1040] [client 73.82.23.97:57193] AH01630: client denied by server configuration: C:/wamp64/www/andrew/index.html
[Fri Apr 22 17:10:50.055249 2016] [authz_core:error] [pid 4388:tid 1040] [client 73.82.23.97:57193] AH01630: client denied by server configuration: C:/wamp64/www/favicon.ico, referer: http://[SERVER IP]/andrew/index.html
I am now thinking it has to do with some setting on Windows 2012 Server, but I can't figure it out. Help.
Because Apache doesn't know to associate the IP address with your virtual host, it uses the main server settings. Probably you don't need a virtual host at all, but try this anyway:
<VirtualHost *:80>
DocumentRoot "c:/wamp64/www/andrew"
ServerName andrew
#of course, enter your IP address here
ServerAlias 1.2.3.4
<Directory "c:/wamp64/www/andrew">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
please don't forget to edit phpMyAdmin.conf file. It will save your time to face 403 Error (403 Forbidden). You should set Require all granted into it as follows (indipendently by used phpMyAdmin version):
Alias /phpmyadmin "c:/wamp64/apps/phpmyadmin5.0.2/"
<Directory "c:/wamp64/apps/phpmyadmin5.0.2/">
Options +Indexes +FollowSymLinks +MultiViews
AllowOverride all
Require all granted
# To import big file you can increase values
php_admin_value upload_max_filesize 128M
php_admin_value post_max_size 128M
php_admin_value max_execution_time 360
php_admin_value max_input_time 360
</Directory>

Apache not serving php files

So I'm trying to get my LAMP stack to work in my Macbook. I've apache setup but PHP is not working. I've installed php55 with Brew and loaded the module in my httpd.conf file like this:
LoadModule php5_module /usr/local/opt/php55/libexec/apache2/libphp5.so
I've checked if the libphp5.so was at the location the module is pointing and it was there.
If I check my apache error.log I get the following message:
[Sat Apr 23 21:36:59.307093 2016] [ssl:warn] [pid 7231] AH01873: Init: Session Cache is not configured [hint: SSLSessionCache]
[Sat Apr 23 21:36:59.358254 2016] [auth_digest:notice] [pid 7231] AH01757: generating secret for digest authentication ...
[Sat Apr 23 21:36:59.360623 2016] [mpm_prefork:notice] [pid 7231] AH00163: Apache/2.4.18 (Unix) LibreSSL/2.2.6 PHP/5.5.34 configured -- resuming normal operations
[Sat Apr 23 21:36:59.360661 2016] [core:notice] [pid 7231] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
I'm missing something but I'm not quite sure what at this point.
Did you also update your Apache config to recognize .php extensions?
AddType application/x-httpd-php .php
or
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
add the following line to your httpd.conf:
AddHandler application/x-httpd-php .php
after apache restart everything should work

Invalid command 'VirtualDocumentRoot'

I tried to configure my virtual PHP Devserver to use a part of the domain to serve different Directory's depending on the domain the request comes from... I guess that apache's missing the Virtual alias Module. I just can't figure out how i can check if it is there and if not how I can Install it... Below you'll find the site config file I was working on when I run a2dissite on it Apache Starts up just fine It's only when i enable vboxsf that it fails on startup/reload or whenever runs "configtest" on it's configuration...
Here is /etc/apache2/sites-available/vboxsf.conf
<VirtualHost *:80 *:8080>
ServerName sandbox
ServerAlias *.dev
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/dev-error.log
CustomLog ${APACHE_LOG_DIR}/dev-access.log combined
RewriteEngine On
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /media/>
Order allow,deny
Allow from all
Require all granted
</Directory>
<Location /server-status>
SetHandler server-status
Order allow,deny
Allow from all
Require all granted
</Location>
UseCanonicalName Off
VirtualDocumentRoot /media/sf_%1
</VirtualHost>
The output from sudo service apache2 reload
* Reloading web server apache2 *
* The apache2 configtest failed. Not doing anything.
Output of config test was:
AH00526: Syntax error on line 30 of /etc/apache2/sites-enabled/vboxsf.conf:
Invalid command 'VirtualDocumentRoot', perhaps misspelled or defined by a module not included in the server configuration
Action 'configtest' failed.
The Apache error log may have more information.
And tail /var/log/apache2/error.log
[Wed Mar 04 17:05:43.698449 2015] [mpm_prefork:notice] [pid 1172] AH00169: caught SIGTERM, shutting down
[Wed Mar 04 17:28:35.880536 2015] [mpm_prefork:notice] [pid 2604] AH00163: Apache/2.4.10 (Ubuntu) PHP/5.5.12-2ubuntu4 configured -- resuming normal operations
[Wed Mar 04 17:28:35.880657 2015] [core:notice] [pid 2604] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 04 17:32:39.675812 2015] [mpm_prefork:notice] [pid 2604] AH00169: caught SIGTERM, shutting down
[Wed Mar 04 17:32:40.788348 2015] [mpm_prefork:notice] [pid 2715] AH00163: Apache/2.4.10 (Ubuntu) PHP/5.5.12-2ubuntu4 configured -- resuming normal operations
[Wed Mar 04 17:32:40.788487 2015] [core:notice] [pid 2715] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 04 17:32:58.596151 2015] [mpm_prefork:notice] [pid 2715] AH00169: caught SIGTERM, shutting down
[Wed Mar 04 17:32:59.706649 2015] [mpm_prefork:notice] [pid 2787] AH00163: Apache/2.4.10 (Ubuntu) PHP/5.5.12-2ubuntu4 configured -- resuming normal operations
[Wed Mar 04 17:32:59.706763 2015] [core:notice] [pid 2787] AH00094: Command line: '/usr/sbin/apache2'
[Wed Mar 04 17:49:48.283025 2015] [mpm_prefork:notice] [pid 2787] AH00169: caught SIGTERM, shutting down
... or defined by a module not included in the server configuration
You are most likely missing the mod_vhost_alias plugin for apache.

Categories