Windows WSL with Ubuntu LAMP - PHP not executing - php

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.

Related

Configuring Apache Virtual Hosts Produces Strange Notices

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

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.

Laravel 5.1 project deployement permissions issues

I am trying to deploy my laravel project. I have installed apache, mysql, php, composer and laravel and pulled my project into /home/spark and ran composer install. Now when I surf to my ip I only see the apache test page.
When I take a peek in my log files I see these 2 errors:
[Sun Nov 22 17:37:54.598627 2015] [core:error] [pid 16141] (13)Permission denied: [client 78.20.130.157:50142] AH00035: access to /index.html denied (filesystem path '/home/spark/public/index.html') because search permissions are missing on a component of the path
[Sun Nov 22 17:37:54.598708 2015] [core:error] [pid 16141] (13)Permission denied: [client 78.20.130.157:50142] AH00035: access to /index.php denied (filesystem path '/home/spark/public/index.php') because search permissions are missing on a component of the path
I have no idea how to fix the permessions. Anyone can help me out?
Thanks in advance!
Here's my spark.conf file for my virtualhost maybe it's not good either:
<Directory "/home/spark/public">
Require all granted
</Directory>
<VirtualHost *:80>
ServerName myurl
DocumentRoot "/home/spark/public"
ErrorLog "/var/log/httpd/spark-error"
CustomLog "/var/log/httpd/spark-customlog" Common
</VirtualHost>
the permissions on my files in /home/spark/public
drwxr-x--- 5 root root 4096 Nov 22 16:33 .
drwxr-x--- 13 spark apache 4096 Nov 22 16:35 ..
drwxr-x--- 2 root root 4096 Nov 22 16:33 css
-rwxr-x--- 1 root root 0 Nov 22 16:33 favicon.ico
-rwxr-x--- 1 root root 412 Nov 22 16:33 .htaccess
drwxr-x--- 2 root root 4096 Nov 22 16:33 images
-rwxr-x--- 1 root root 1786 Nov 22 16:33 index.php
-rwxr-x--- 1 root root 24 Nov 22 16:33 robots.txt
drwxr-x--- 3 root root 4096 Nov 22 16:33 uploads
Make apache the owner of all your application folders and files like so :
sudo chown -R apache:apache .
your current folder should be the application folder before running this command

My vagrant doesn't show any response with a error 500

I'm new with Vagrant, and I'm having trouble to up my Vagrant server with ZendFramework 2. Below goes my configuration file...
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = '2'
#script = <<SCRIPT
DOCUMENT_ROOT_ZEND="/var/www/zf/public"
apt-get update
apt-get install -y apache2 git curl php5-cli php5 php5-intl libapache2-mod-php5
echo "
<VirtualHost *:80>
ServerName skeleton-zf.local
DocumentRoot $DOCUMENT_ROOT_ZEND
<Directory $DOCUMENT_ROOT_ZEND>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
" > /etc/apache2/sites-available/skeleton-zf.conf
a2enmod rewrite
a2dissite 000-default
a2ensite skeleton-zf
service apache2 restart
cd /var/www/zf
curl -Ss https://getcomposer.org/installer | php
php composer.phar install --no-progress
echo "** [ZEND] Visit http://localhost:8085 in your browser for to view the application **"
SCRIPT
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = 'bento/ubuntu-14.04'
config.vm.network "forwarded_port", guest: 80, host: 8085
config.vm.hostname = "skeleton-zf.local"
config.vm.synced_folder '.', '/var/www/zf'
config.vm.provision 'shell', inline: #script
config.vm.network "private_network", ip: "0.0.0.0"
config.vm.provider "virtualbox" do |vb|
vb.customize ["modifyvm", :id, "--memory", "1024"]
end
end
When I try to acess the 8085 port I got a blank page with HTTP code 500, and in every rout I try to access, existing or not, I got the same error. Below goes my php version at Vagrant:
vagrant#skeleton-zf:~$ php -v
PHP 5.5.9-1ubuntu4.13 (cli) (built: Sep 29 2015 15:24:49)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies
with Zend OPcache v7.0.3, Copyright (c) 1999-2014, by Zend Technologies
vagrant#skeleton-zf:~$
And when I try to run any comand in apache, I got this:
vagrant#skeleton-zf:~$ apache2 -V
[Fri Oct 02 16:19:06.465441 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Fri Oct 02 16:19:06.466385 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Fri Oct 02 16:19:06.466830 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Fri Oct 02 16:19:06.469081 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Fri Oct 02 16:19:06.469143 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Fri Oct 02 16:19:06.474489 2015] [core:warn] [pid 5758] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}
My problem was a hidden 500 error message, because I didnt installed the php5-mysql package. The configuration is ok.

Is HHVM or PHP5 Zend running?

After some struggle, I finally installed Facebook HipHop Virtual Machine in Ubuntu. It is running under FastCGI (Apache 2.22). Below, the service status:
marcelo#marcelo-VirtualBox:~$ service apache2 status
Apache2 is running (pid 3330).
marcelo#marcelo-VirtualBox:~$ service hhvm status
* hhvm is running
marcelo#marcelo-VirtualBox:~$ sudo service hhvm restart
* Restarting HHVM FastCGI Daemon hhvm [ OK ]
marcelo#marcelo-VirtualBox:~$
The same machine has PHP5 module enabled and configured in Apache.
Question:
I want to make sure that I am really rendering PHP code using HHVM and NOT Zend Framework.
All my PHP scripts are running on the webserver. But, when I disable PHP5 module using sudo a2dismod php5 the web server starts to render Internal Server Error.
Does HHVM need PHP5 module enabled to run? Supposedly, since I am using FastCGI, my answer is no. On the other hand, I think that my pages are being rendered by Zend and not HHVM.
What am I missing here? How can I make sure that I am really running HHVM? (in my mind, a clear test is to disable PHP5 module, but, as I said, when I disable, php stops working in the web browser).
If .php is not running with PHP5 module disabled does it means that my HHVM is not properly configured?
P.S.: The script that I am testing is a default Hello World example: <?php echo 'Hello World.'; ?>.
And, It works when I run from command line:
marcelo#marcelo-VirtualBox:/var/www$ sudo hhvm hello_world.php
Hello World.
marcelo#marcelo-VirtualBox:/var/www$
EDIT
Apache error.log:
marcelo#marcelo-VirtualBox:/var/log/apache2$ cat error.log
[Wed May 07 14:02:10 2014] [notice] FastCGI: process manager initialized (pid 2627)
[Wed May 07 14:02:10 2014] [notice] Apache/2.2.22 (Ubuntu) mod_fastcgi/mod_fastcgi-SNAP-0910052141 configured -- resuming normal operations
[Wed May 07 14:04:52 2014] [error] [client 127.0.0.1] (2)No such file or directory: FastCGI: failed to connect to server "/var/www/fastcgi/hhvm.fastcgi": connect() failed
[Wed May 07 14:04:52 2014] [error] [client 127.0.0.1] FastCGI: incomplete headers (0 bytes) received from server "/var/www/fastcgi/hhvm.fastcgi"
[Wed May 07 14:04:53 2014] [error] [client 127.0.0.1] File does not exist: /var/www/favicon.ico
marcelo#marcelo-VirtualBox:/var/log/apache2$
(Apparently, I should have 'hhvm.fastcgi' file. I only have the directory. Is anything wrong here?)
/var/www directory:
marcelo#marcelo-VirtualBox:~$ ls -l /var/www
total 20
drwxrwxrwx 2 root root 4096 May 6 23:45 fastcgi
-rw-r--r-- 1 root root 31 May 6 21:57 hello_world.php
-rw-r--r-- 1 root root 177 May 6 17:47 index.html
-rw-r--r-- 1 root root 21 May 6 17:50 info.php
-rw-r--r-- 1 root root 0 May 6 17:49 info.php~
drwxr-xr-x 13 997 1001 4096 May 6 18:13 mediawiki-1.22.6
marcelo#marcelo-VirtualBox:~$ ls -l /var/www/fastcgi/
total 0
marcelo#marcelo-VirtualBox:~$
- FastCGI configuration:
I added the lines below, as suggested here: https://github.com/facebook/hhvm/wiki/FastCGI, at the end of apache2.conf file. In other words, after all 'mods-enabled' were already loaded.
# fastcgi added by M. Sardelich
<IfModule mod_fastcgi.c>
Alias /hhvm.fastcgi /var/www/fastcgi/hhvm.fastcgi
FastCGIExternalServer /var/www/fastcgi/hhvm.fastcgi -socket /var/run/hhvm/socket -pass-header Authorization -idle-timeout 300
<Directory "/var/www/fastcgi">
<Files "hhvm.fastcgi">
Order deny,allow
</Files>
</Directory>
AddHandler hhvm-hack-extension .hh
AddHandler hhvm-php-extension .php
Action hhvm-hack-extension /hhvm.fastcgi virtual
Action hhvm-php-extension /hhvm.fastcgi virtual
</IfModule>
To make sure that you are in fact running HHVM, run the following command:
phpinfo();
It should produce HipHop as the output, instead of the normal php info.
To check for it programmatically, you can use the following (also mentioned here):
if (defined('HHVM_VERSION')) {
echo "ruuning HHVM";
}
As correctly noticed (thanks #Petah), my FastCGI config was wrong.
I changed it to the snippet below (from here: http://www.mediawiki.org/wiki/HHVM/Vagrant) and everything is working! (add it to your apache2.conf or httpd.conf file)
<IfModule mod_fastcgi.c>
Alias /hhvm.fastcgi /var/www/fastcgi/hhvm.fastcgi
FastCGIExternalServer /var/www/fastcgi/hhvm.fastcgi -host 127.0.0.1:9000 -pass-header Authorization -idle-timeout 300
<Directory "/var/www/fastcgi">
<Files "hhvm.fastcgi">
Order deny,allow
</Files>
</Directory>
AddHandler hhvm-hack-extension .hh
AddHandler hhvm-php-extension .php
Action hhvm-hack-extension /hhvm.fastcgi virtual
Action hhvm-php-extension /hhvm.fastcgi virtual
</IfModule>

Categories