Serve php RESTful server with apache2 (ubuntu) - php

I have a ubuntu machine on which I want to run a php rest server. Here is my default config file:
ServerName localhost
<VirtualHost *:80>
DocumentRoot /var/www/html/otherSite
ServerName www.vlio20_paka.com
Alias /otherSite /var/www/html/otherSite
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/lbserver/public
ServerName www.vlio20_lb.com
Alias /lbServer /var/www/lbserver/public
<Directory /var/www/lbserver/public>
AllowOverride all
DirectoryIndex index.php
Require all granted
</Directory>
</VirtualHost>
In my public directory I have .htaccess file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I try to access the server http://MACHINE_IP/lbServer
I am getting Not Found error.
How can I make it work
(I am doing apache restart after each change in the config file)?
Update:
apache2 -t produced:
[Sun Jun 28 12:00:00.789522 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_LOCK_DIR} is not defined
[Sun Jun 28 12:00:00.789835 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_PID_FILE} is not defined
[Sun Jun 28 12:00:00.789970 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_RUN_USER} is not defined
[Sun Jun 28 12:00:00.790088 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_RUN_GROUP} is not defined
[Sun Jun 28 12:00:00.790240 2015] [core:warn] [pid 22089] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.794721 2015] [core:warn] [pid 22089:tid 140102153521024] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.795136 2015] [core:warn] [pid 22089:tid 140102153521024] AH00111: Config variable ${APACHE_LOG_DIR} is not defined
[Sun Jun 28 12:00:00.795200 2015] [core:warn] [pid 22089:tid 140102153521024] 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}
note: the first site is loading fine but the second gives a 404 error.

First this as almost nothing to do with a REST problem. It is a simple configuration error.
Second, for apache2 -t you should run . /etc/apache2/envvars before, because you need some envs variables loaded.
Then the configuration problem.
Your are defining 2 named based Virtualhosts, 1 with the name www.vlio20_paka.com and one with the name www.vlio20_lb.com. The first one is defined first, so if you use an unknown name it will be used, by default.
When you make a query this way:
http://MACHINE_IP/lbServer
the Host header used in your HTTP query is MACHINE_IP, so it's not www.vlio20_paka.com and not www.vlio20_lb.com. If you have no other default virtualhost (something you would find using apache2 -S) the first one will be used.
Let's have a look at the first one:
<VirtualHost *:80>
DocumentRoot /var/www/html/otherSite
ServerName www.vlio20_paka.com
Alias /otherSite /var/www/html/otherSite
</VirtualHost>
If we fall here the path searched on your disk will be DocumentRoot+url, so /var/www/html/otherSite/lbServer. You have a 404, chances are this path does not exists.
Note that your Alias instructions here simply tells Apache that a request to http://www.vlio20_paka.com/ and a request to http://www.vlio20_paka.com/otherSite would both point to the /var/www/html/otherSite/ directory, maybe not what you wanted to do.
Alias is simply a way to define some sort of url symlinks on the url-to-filesystem maps.
Let's now look the second VirtualHost, that you can only reach if you use the right name in your HTTP request, that is not requesting http://MACHINE_IP/lbServer but http://www.vlio20_lb.com/lbServer (for that you could an entry in your /etc/hosts file, on the machine running the http query).
<VirtualHost *:80>
DocumentRoot /var/www/lbserver/public
ServerName www.vlio20_lb.com
Alias /lbServer /var/www/lbserver/public
<Directory /var/www/lbserver/public>
AllowOverride all
DirectoryIndex index.php
Require all granted
</Directory>
</VirtualHost>
So here you set a DocumentRoot at /var/www/lbserver/public but also, via Alias, you tell Apache that a request to http://www.vlio20_lb.com/lbServer/ point to the same entry as http://www.vlio20_lb.com/.
Your best fix would be to add an entry in /etc/hosts a request your test websites with real names, so that you can use Name based VirtualHosting. Or use only one VirtualHost and try things with aliases, but that's usually far from the production settings.

The only thing I think of without seeing more of your config.
Change:
<Directory /lbserver>
DirectoryIndex index.php
</Directory>
To:
<Directory /lbserver>
DirectoryIndex index.php
Require all granted
</Directory>

In ubuntu there is no binary httpd, apache2 used instead:
ricardo#zeus:~$ httpd -t
No se ha encontrado la orden «httpd», quizás quiso decir:
La orden «xttpd» del paquete «xtide» (universe)
La orden «https» del paquete «httpie» (universe)
La orden «http» del paquete «httpie» (universe)
httpd: no se encontró la orden
ricardo#zeus:~$ apache2 -t
Now , paste the command output ;-)

Related

Trouble configuring custom folder for site (Apache)

I'm trying to configure httpd on fedora, but my two day effort has gotten me nowhere.
I installed httpd and php, added the configuration file for the site, everything is fine. I try to load it and see "access denied." but I have already granted to the apache user and apache group 755 rights (on every folder along the path).
Errors in apache log:
[Mon Jun 06 20:25:18.088420 2022] [negotiation:error] [pid 12656:tid
12758] (13)Permission denied: [client 127.0.0.1:45920] AH00686: cannot
read directory for multi: /home/concasse_master/Desktop/sample/public/
[Mon Jun 06 20:25:18.089421 2022] [proxy_fcgi:error] [pid 12656:tid
12758] [client 127.0.0.1:45920] AH01071: Got error 'Unable to open
primary script: /home/concasse_master/Desktop/sample/public/index.php
(Permission denied)'
localhost.conf:
<VirtualHost *:8080>
ServerName localhost
DocumentRoot /home/concasse_master/Desktop/sample/public
ErrorLog logs/error.log
CustomLog logs/access.log combined
<Directory /home/concasse_master/Desktop/sample/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration

Currently, I am setting my local environment for a project.
Project runs on production environment with nginx server. But in the local development, using apache server. I've installed LAMP stack on my ubuntu machine. There is already a virtual host file provided and I have setup it. So far I've created xxx.conf file under /etc/apache2/sites-available.
The file includes:
<VirtualHost *:80>
ServerName xxx
DocumentRoot /home/ubuntuser/Downloads/xxx-master/public
<Directory "/home/ubuntuser/Downloads/xxx-master/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/xxx-error.log
CustomLog ${APACHE_LOG_DIR}/xxx-access.log combined
SetEnv ENVIRONMENT "development"
</VirtualHost>
I also created .htaccess file under /home/ubuntuser/Downloads/xxx-master/public. The content of this file downloaded from production environment.
The content of .htaccess file is:
RewriteEngine On
RewriteBase /
location ~ ^/site { rewrite ^/site(.*)$ https://local.xxx.com/$1 redirect;}
So, when I type local.xxx.com in browser, it gives 500 Internal Error.
So, I was defined xxx-error.log in virtual host config file. I've opened it. The content is:
[Tue May 28 22:23:33.231851 2019] [core:alert] [pid 5677] [client 127.0.0.1:56504] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: RewriteBase takes one argument, the base URL of the per-directory context
[Tue May 28 22:23:33.254608 2019] [core:alert] [pid 5678] [client 127.0.0.1:56506] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: RewriteBase takes one argument, the base URL of the per-directory context, referer: http://local.xxx.com/
[Tue May 28 22:33:22.300863 2019] [core:alert] [pid 6326] [client 127.0.0.1:56740] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration
[Tue May 28 22:33:22.317420 2019] [core:alert] [pid 6327] [client 127.0.0.1:56742] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration, referer: http://local.xxx.com/
So, I understand there is problem in the .htaccess but i don't know how to solve it.
You are using apache and in your .htaccess using the convention of Nginx.
Refer to latest documentation of apache2.4
To me it seems like you want to redirect use this
RewriteRule ^/site(.*)$ https://local.xxx.com/$1 or maybe this
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

Unable to get url mod_rewrite to work in xampp(windows 8)

No matter how much I tried to get url rewrite to work, it just keep failing and I have google searched alot and try alot of codes even here on stackoverflow and none of them worked for me and at the end of the day, am forced to ask for help.
I want, like, for example, when a user click on a link, I want the users' to be shown a pretty format of the website URL in the browser in the manner or structure in the manner of that of facebook, stackoverflow, wikipedia etc are doing like when a user visit localhost:jokes=edit?4, it formats it to jokes/edit/4 or something like that.
First thing I did was to setup Virtual host and the virtualhost I setup is this
#Directory structure
<Directory C:/alls>
AllowOverride All
Require all granted
</Directory>
#this is the default address of XAMPP
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/alls/ijdb/public"
ServerName ijdb.localhost
SetEnv NS_ENV variable_value
</VirtualHost>
And in the httpd.conf, I turned all
AllowOverride
to
all
and in the hosts file add this
127.0.0.1 ijdb.localhost
Then, create this in .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !d
RewriteRule ^.*$ index.php [NC,L,QSA]
Yet, when I click on any other link apart from the home link, it returns object not found.
My question is how can I solve it?
I use XAMPP3.2.2 which comes by default with apache 2.2.34
From the error log, this is what I saw there. I don't know if it has something to do with it anyway...
[Tue Sep 11 02:07:31.554559 2018] [ssl:warn] [pid 1012:tid 376] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Tue Sep 11 02:07:32.123856 2018] [ssl:warn] [pid 1012:tid 376] AH01909: www.example.com:443:0 server certificate does NOT include an ID which matches the server name
[Tue Sep 11 02:07:32.239860 2018] [mpm_winnt:notice] [pid 1012:tid 376] AH00354: Child: Starting 150 worker threads.
First make sure that rewrite_module is enabled or not. Go to apache bin and load modules list like cd c:\xampp\apache\bin && apache2.exe -M
Then modify your virtualhost as below:
<VirtualHost *:80>
DocumentRoot "C:/alls/ijdb/public"
ServerName ijdb.localhost
SetEnv NS_ENV variable_value
<Directory "C:/alls/ijdb/public">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Check c:\xampp\apache\logs\error.log file for more detail.

PHP not running on VirtualHost after upgrading to OS X Yosemite

Upgraded to OS X Yosemite and now my virtualhosts are spitting out the PHP file contents instead of executing the file.
This works correctly:
http://localhost
This spits out the file contents onto the screen:
http://localhost/~MYUSERNAME
<?php phpinfo();
http://testing.dev spits out the
<?php and the contents of this file (which is WordPress)
apachectl -t
Syntax OK
/etc/apache2/extra/httpd-vhosts.conf
<VirtualHost *:80>
ServerName localhost
DocumentRoot /Library/WebServer/Documents/
</VirtualHost>
<VirtualHost *:80>
ServerName testing.dev
ServerAlias www.testing.dev
DocumentRoot "/Users/*/Sites/testing"
ErrorLog "/private/var/log/apache2/testing.dev-error_log"
<Directory "/Users/*/Sites/testing-env/">
Options Indexes FollowSymLinks
AllowOverride AlL
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
/etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
127.0.0.1 testing.dev
Why is it spitting out the PHP file instead of executing it?
running php -v gives me
PHP 5.5.3 (cli) (built: Aug 28 2013 13:28:31)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
with Xdebug v2.2.2, Copyright (c) 2002-2013, by Derick Rethans
error log shows:
[Mon Nov 17 17:30:08.338143 2014] [auth_digest:notice] [pid 3633] AH01757: generating secret for digest authentication ...
[Mon Nov 17 17:30:08.339341 2014] [mpm_prefork:notice] [pid 3633] AH00163: Apache/2.4.9 (Unix) PHP/5.5.14 configured -- resuming normal operations
[Mon Nov 17 17:30:08.339391 2014] [core:notice] [pid 3633] AH00094: Command line: '/usr/sbin/httpd -D FOREGROUND'
Upgrading OS X restores the Apache configuration files to their defaults. You’ll need to edit them again. From memory, this includes:
un-commenting the PHP handler so Apache executes files rather than serving them
Setting AllowOverride to All for your web root directory
un-commenting the line that loads the VirtualHosts configuration file
I had the same issue and found there was a missing configuration section in my httpd.conf. After adding the following and restarting Apache PHP files were processed correctly.
<IfModule php5_module>
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
</IfModule>

Zend Framework - 500 Internal Server Error

Today I create my first project with Zend Framework but when I try to connect to my project I see only "500 Internal Server Error". I add some new rows in httpd.conf file:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\AppServ\www\data1\public
ServerName my_ip
</VirtualHost>
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:\AppServ\www\data1\public
ServerName http://my_ip
</VirtualHost>
And that is my htaccess file:
RewriteEngine On
#RewriteBase data1/public/
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
RewriteRule !\.(js|ico|gif|jpg|png|css|swf|html|pps)$ index.php [NC,L]
order allow,deny
allow from all
I read more topics for this problem but for now problem is not solved.
That is my error.log file(from server):
[Wed Aug 08 01:46:02 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
PHP Warning: PHP Startup: Unable to load dynamic library 'C:/AppServ\\php5 \\ext\\php_exif.dll' - \xd3\xea\xe0\xe7\xe0\xed\xe0\xf2\xe0 \xef\xf0\xee\xf6\xe5\xe4 \xf3\xf0\xe0 \xed\xe5 \xe5 \xed\xe0\xec\xe5\xf0\xe5\xed\xe0.\r\n in Unknown on line 0
[Wed Aug 08 01:46:02 2012] [notice] Apache/2.2.8 (Win32) PHP/5.2.6 configured -- resuming normal operations
[Wed Aug 08 01:46:02 2012] [notice] Server built: Jan 18 2008 00:37:19
[Wed Aug 08 01:46:02 2012] [notice] Parent: Created child process 2392
[Wed Aug 08 01:46:02 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
[Wed Aug 08 01:46:02 2012] [warn] NameVirtualHost *:80 has no VirtualHosts
PHP Warning: PHP Startup: Unable to load dynamic library 'C:/AppServ\\php5\\ext\\php_exif.dll' - \xd3\xea\xe0\xe7\xe0\xed\xe0\xf2\xe0 \xef\xf0\xee\xf6\xe5\xe4\xf3\xf0\xe0 \xed\xe5 \xe5 \xed\xe0\xec\xe5\xf0\xe5\xed\xe0.\r\n in Unknown on line 0
[Wed Aug 08 01:46:02 2012] [notice] Child 2392: Child process is running
[Wed Aug 08 01:46:02 2012] [notice] Child 2392: Acquired the start mutex.
[Wed Aug 08 01:46:02 2012] [notice] Child 2392: Starting 64 worker threads.
[Wed Aug 08 01:46:02 2012] [notice] Child 2392: Starting thread to listen on port 80.
[Wed Aug 08 01:46:15 2012] [alert] [client 46.40.124.225] C:/AppServ/www/data1/public/.htaccess: Invalid command 'RewriteEngine', perhaps misspelled or defined by a module not included in the server configuration
Thanks for posting the error log.
From the looks of it, you don't have mod_rewrite loaded.
Find your httpd.conf file and locate the line:
#LoadModule rewrite_module modules/mod_rewrite.so
Remove the # sign from the beginning of the line.
Next, add a new section to httpd.conf that looks like this:
<Directory "C:/AppServ/www/data1/public">
Options FollowSymLinks
AllowOverride All
</Directory>
The AllowOverride directive is important. By default, .htaccess files are not processed unless allowed. This line allows .htaccess files in that named directory.
After making those changes, restart Apache and then try loading your ZF page again.
First of all, a better debugging. Add
ErrorLog "PATH_TO/zfapp-error_log"
CustomLog "PATH_TP/zfapp-access_log" combined
to your virtualhost. Restart apache and reload your page. The files will be created in the specified path. There will be an exact error message wich will help you debug further.
I just had the exact same problem and the solution by drew010 did fix it indeed!
However, it seems Apache config structure changed, so the method to enable the missing module is slightly different:
$ cd /etc/apache2/mods-enabled
$ sudo ln -s ../mods-available/rewrite.load ./rewrite.load
This confirms you have the right stuff going:
$ cd /etc/apache2/mods-enabled
$ cat ./rewrite.load
LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so
Cheers!

Categories