Apache serving 2 websites to one domain with path - php

I am new to this and I searched everywhere for a server routing method to be able to store 2 sites at different paths to a single domain. Most help I found refers to using virtual host to multiple domains, subdomains, IP etc. So far non of them fits what I need.
So I have the latest stack of Apache2, PHP, MySQL, on Debian-8 with 2 functional sites (databases, users, ...all OK) installed on sub folders of /html:
crm_site under /var/www/html/crm (storing a php script for project tracking)
and
wp_site under /var/www/html/wordpress (storing a wordpress website).
I want to be able to access them using the only domain I own (say www.example.com) which I already have set up to reach my server.
I was hoping that I would only need to add the path to my domain (www.example.com/crm/index.php or www.example.com/wordpress/index.php) and they will be served, but no matter what I add after the domain, the browser leads to the same place, showing the directory list in html (that is crm, and wordpress).
Can anyone tell me how can this be done? Thank you.

it sounds like you have everything setup correctly with the exception of your starting Directory.
It may be best to reword your question. This seems to be your situation (speaking from your perspective):
have a website at http://machine.domain.com
I want to set /var/www/html as my default directory
I want to set index.php as my default document
Once you view your issue this way, it is greatly simplified. A search engine can help you at this point.
To further guide you, doing said search for "apache set default directory" on Google, for instance, has the answer in bold. ... change the root directory of Apache or move the project to /var/www/html
You've already done this, right? So 1. and 2. above are done. If not, look at the following (which assumes apache2 package on Ubuntu latest. i've tested this in a docker container):
file: /etc/apache2/apache2.conf
contents:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
Change the above /var/www/ to /var/www/html/
Next, the .php serving issue. This is controlled by the DirectoryIndex directive as referenced here. Looking at it's contents shows that index.php is enabled by default.
example:
root#b62dsa09327e:/# grep -rnw '/etc/apache2/' -e "DirectoryIndex"
/etc/apache2/mods-available/dir.conf:2: DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
This takes care of 3. And now we're all out of issues in your original question.
Note: you may have to chown the directory to whatever apache2 is running as in the event you dropped files in there as root. You'll also have to restart apache in order to have the changes above reflect in the service.

Related

(proxy_fcgi:error) AH01071: Got error 'Unable to open primary script:' (No such file or directory)

I've read countless forum posts about this but none of the answers seem to help my situation. Here's the log excerpt:
[proxy_fcgi:error] [pid XXXX] [client redacted] AH01071: Got error 'Unable to open primary script: /home/user-account/public_html/www/index.php (No such file or directory)'
I've verified manually that this file is readable through SSH; also, other non-php files can be accessed through the browser.
My directory structure is as follows:
/home/user-account
/home/user-account/apps
/home/user-account/apps/old
/home/user-account/apps/current
/home/user-account/public_html
/home/user-account/public_html/old > symlink to > /home/user-account/apps/old
/home/user-account/public_html/test > symlink to > /home/user-account/apps/current
/home/user-account/public_html/www > symlink to > /home/user-account/apps/current
I have 2 subdomains on 'domain.com':
old.domain.com
test.domain.com
Therefore due to how cPanel/WHM/Apache writes out their virtualhosts (considering the ServerAlias directive), the resulting domain structure is:
old.domain.com
www.old.domain.com (I ignore this)
test.domain.com
www.test.domain.com (I ignore this)
domain.com (.htaccess redirects to www.domain.com)
www.domain.com (This is the domain with the issue; also domain.com would be an issue if not for the redirect)
Up until now I've been developing my wordpress website under a real directory /home/user-account/public_html/test. The site is in perfect working condition. Then I decided to go live. I moved the real folder to it's current location (/home/user-account/apps/current) and symlinked /home/user-account/public_html/test to it. I restarted Apache and verified the test.domain.com site still operated as expected (testing out the symlink). Feeling confident in the symlink setup, I removed my original symlink of /home/user-account/public_html/www (pointing to my old rails app at /home/user-account/apps/old) and created a new one pointing to /home/user-account/apps/current. This is when the issue started.
httpd.conf:
The only appreciable difference between the test subdomain and the main domain (with www aliased) is that the test subdomain's auto-generated directives point to the true aliased folder location (DocumentRoot/Directory/ScriptAlias all use /home/user-account/public_html/test). I believe this was because I had used cPanel to create a subdomain which had to point to a directory within /home/user-account/public_html. But the main domain's auto-generated directives all point to /home/user-account/public_html instead of /home/user-account/public_html/www.
However, apache 2.4 allows me to include custom virtualhost config options by placing my custom.conf files in the appropriate directories. So I don't need any of them for the test subdomain but I had to use them for the main domain; I know they're working because the error log (found at the top of this post) shows it's using the proper DocumentRoot. Here's an excerpt from the std custom.conf to show that in addition to setting the DocumentRoot I also override the other autogenerated directives explicitly:
DocumentRoot /home/user-account/public_html/www
<IfModule mod_include.c>
<Directory "/home/user-account/public_html/www">
SSILegacyExprParser On
</Directory>
</IfModule>
<IfModule alias_module>
ScriptAlias /cgi-bin/ /home/user-account/public_html/www/cgi-bin/
</IfModule>
<IfModule ssl_module>
<Directory "/home/user-account/public_html/www/cgi-bin">
SSLOptions +StdEnvVars
</Directory>
</IfModule>
File permissions:
I haven't changed the file permissions from their original setup and I've already verified they're correct. Again, test.domain.com was working as expected. It's only (www.?)domain.com that isn't.
Other 'fixes' that did nothing:
Rebuilding/restarting PHP-FPM (ineffective)
SetHandler/ProxyOverride (SetHandler is automatically created for me by rebuildhttpdconf and I don't expect it's the issue as it's working for the test subdomain; ProxyOverride doesn't seem to do anything)
Set up wordpress .htaccess (already in place and matches what is shown here. Again, test subdomain is working and it's an alias just like www is)
Server stats:
EasyApache 4 with
Apache 2.4.43
mod_proxy_fcgi
PHP 7.3
php73-php-fpm
Whatever you consider, remember that there's practically no difference between the files in the test subdomain vs the main domain (.htaccess included); they're both aliased to the same directory. The only difference I can see is that test is a registered subdomain and therefore httpd.conf handles it slightly differently than the main domain. However I can't just add a 'www' subdomain through cPanel - it won't let me - probably because it aliases www anyway.
I've been clawing around trying to fix this and my public website has been down for 24+ hours so I would greatly appreciate any help you can provide!
Addendum:
I don't know if it's relevant (it didn't seem to affect my old rails app), but under WHM > Manage SSL Hosts, my main domain and www subdomain point to a document root of /home/user-account/public_html, whereas my subdomains point to the correct respective directories.
I also tried setting the vhost on the main domain to use the test directory (same as the test subdomain) but it's giving me the same error. I don't think it's a permission/file issue.
I also created a test.php file in the /public_html directory in order to test out a direct access. It still erred out and logged:
AH01071: Got error 'Unable to open primary script: /home/user-account/public_html/www/index.php (No such file or directory)', referer: https:// domain.com/test.php
And the answer is that I had to set the doc_root through the PHP-FPM Configuration for the given domain. Why? I don't know - if someone can shed some light on this I'd rather not have to do things through the FPM configuration and set it through Apache if possible. I don't have to do this for subdomains...

Two symfony projects on one server/domain

I've created two independent symfony projects and I've moved them to my prod server, for example:
project1.example.com [/var/www/project1/web]
project2.example.com [/var/www/project2/web]
The problem is that when I open up the second address, then project1 is fired up. I checked /var/www/project2/web/app.php and seems it's properly executed, but for some reason, symfony loaders use /var/www/project1/ path. Of course the cache folders were cleared.
Any ideas how to diagnose the problem?
UPDATE
Apache config files:
/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/project1.conf + /etc/apache2/sites-enabled/project2.conf
UPDATE 2
Strange thing, this morning the situation has reversed. Both addresses show site from project2 now. No config nor project files were modified.
You'll need to enable Virtual Hosting in Apache.
Take a look at my article on it, it should answer the question:
https://alvinbunk.wordpress.com/2016/11/21/apache-httpd-virtualhost-config/
If you need further help with that, you can always post another question. I use this all the time.
EDIT #2 - based on Apache 2 conf:
Suggest you combine SSL and HTTP VirtualHost ports like so, and also just have a single Directory directive to the web folder. There are other redundancies in the conf file. Please read some documents first about the Apache config files before asking questions.
<VirtualHost *:443 *:80>
...
<Directory /var/www/project1/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
</VirtualHost>
For the Project2 problem, have you checked the logs in $APACHE_LOG_DIR to see what they show? I think logs are usually in /var/log; there's probably an httpd subdirectory with the httpd logs. You need to make sure there is an incoming GET request for project1.example.com.pl. If not, you'll need to check all your hosts files to see they are setup correctly.

Owncloud not available after installation on Ubuntu server 14.04

With the goal to install owncloud (version 6.0.3-0) on my ubuntu server (14.04), I followed this guideline:
http://doc.owncloud.org/server/6.0/admin_manual/installation/installation_source.html
After having this completed, the /var/www/owncloud folder exists with the following content:
3rdparty core index.html occ robots.txt themes apps cron.php index.php ocs search version.php config data l10n public.php settings console.php db_structure.xml lib remote.php status.php
Visiting
http://localhost
results in a site like this: https://assets.digitalocean.com/articles/lamp_1404/default_apache.png indicating, that the apache-server works.
Visiting
http://localhost/owncloud
leads to server error 404: "Not Found".
Meanwhile, I tried the installation (owncloud 6.0.3-0) on my laptop (Ubuntu 13.10) to compare results. Skipping the above guidelines, just installing owncloud using the package-manager works out of the box, while the content of /var/www/owncloud results only in config data
Since it works on my laptop, I have the suspect, that I screwed up some configuration on my ubuntu server. Even so, reinstalling apache2 (including purge) did not help.
Do you have any ideas, where to start over?
This is because Apache 2.4's default web root is /var/www/html as opposed to /var/www. ownCloud's default installation ends up in /var/www/owncloud, which is outside of the web root.
I first solved this by creating a symbolic link at /var/www/html/owncloud, but I found it cleaner to simply change Apache's document root to /var/www/owncloud. If you want to preserve the owncloud subdirectory, you can point it to /var/www and get rid of /var/www/html and its contents.
Edit /etc/apache2/sites-enabled/000-default.conf (and/or the appropriate configuration for the SSL site in the same location, depending on your setup) to point DocumentRoot to /var/www or /var/www/owncloud, whichever works for you.
I just figured this out myself, so it may warrant further configuration changes. I will update this post if/when I figure out more tweaks need to be made, but it seems to be working for me, anyway.
Also this has nothing to do with programming and really belongs on superuser.com or perhaps serverfault.com.
This would be more appropriate as a comment as I'm completely clueless as to the solution, but the strange system of SO doesn't allow me to post comments. I have an idea that may not help but just want to confirm that it's not the problem.
Have you tried the following URL?
http://localhost/owncloud/index.html
The first thing that came to mind is that there is a problem with your Default Document settings.
If the above works, you can fix it so you don't have to define the HTML file in the URL by creating a .htaccess file in your server root directory with the contents being:
DirectoryIndex index.php index.html index.htm default.html default.htm home.html
Hope this helps.

Django and PHP simultaneous use

I have an Apache server with PHP support. I also installed Python with mod_wsgi and with mysql-connector. Besides I installed Django. Now, I want to try to use PHP and Python simultaneously at the server side. The catch is, I worked with PHP for a couple of years and I see that it is becoming less and less popular, so I plan to port some of my PHP-code to Python-code, or just to try it, to see how they work together. So, I now have a site located at C:\Apache\htdocs and I created a first Django project at C:\WebPython\djsite. Inside djsite I have djsite folder and four files _init_.py, settings.py, urls.py and wsgi.py. In my site I want to address both to PHP handlers (or scripts) and to Python scripts, so, I guess, the problem is in how to config httpd.conf. I looked through many forum threads here at stackoverflow and outside, but still I can't make it work. Now, my httpd.conf looks like this:
...
ServerName localhost
<Directory "c:/Apache/htdocs">
Options Indexes FollowSymLinks
</Directory>
<IfModule dir_module>
DirectoryIndex index.html index.htm index.php
</IfModule>
...
You should see this question then:
PHP script inside Django template
It has a link to this:
http://animuchan.net/django_php/
Running PHP with Django would be a mess though.
Hello Like Every Body Else Said Its A terrible idea but Refer To Django Documentation adding this to http.conf on your apache2 and tweek
the wsgi.py file will work
WSGIScriptAlias / /path/to/mysite.com/mysite/wsgi.py
WSGIPythonPath /path/to/mysite.com<Directory /path/to/mysite.com/mysite>
<Files wsgi.py>
Require all granted
</Files>
</Directory>
and change
If multiple Django sites are run in a single mod_wsgi process, all of them will use the settings of whichever one happens to run first. This can be solved by changing:
in wsgi.py, to:
os.environ["DJANGO_SETTINGS_MODULE"] = "{{ project_name }}.settings"
or by using mod_wsgi daemon mode and ensuring that each site runs in its own daemon process.
Fixing UnicodeEncodeError for file uploads
If you get a UnicodeEncodeError when uploading files with file names that contain non-ASCII characters, make sure Apache is configured to accept non-ASCII file names:
export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'
A common location to put this configuration is /etc/apache2/envvars.
See the Files section of the Unicode reference guide for details.
See More At https://docs.djangoproject.com/en/dev/howto/deployment/wsgi/modwsgi/

How to run PHP application out of localhost?

I got this task form school, to make a PHP web application. But I don't really understand what this requirement might mean
It should be possible to run this application outside the domain root
e.g. sample URL: http://localhost/task/.
I searched a little bit on the internet but was not able to find anything that I could understand ?
I have wamp, and the folder where is my sites is wamp/www/task
When they say "outside of domain root" it means that you should not be forced to go to
http://localhost/yourfile.php
but you could put it in a subdir, like
http://localhost/task/yourfile.php
What they want you to do is harder to guess, but it could mean that you need to be able to run it in any subdir, so take care of you imports to be able to handle that (e.g.: not hardcode the dir you're working in).
Domain root seems to be at localhost, this just means it should be easy to rename your web application folder and make it still work at anywhere.
# http://localhost/task
$ cd wamp/www/
# http://localhost/task2 - should be accessible without you needing to change anything
$ mv task task2
From technical point of view, you should use relative path for all your links and images as well as external resources such as javascript / css files
you can set vitual host for your web server & access your PHP Application likw www.oorja.local
in the wamp server, just add below code at end of your httpd.conf file, which allow you access your PHP application without localhost, Document root and Directory have your physical pathe of your application directory.
ServerName oorja.local
DocumentRoot E:/LAMPSYSTEM/wamp/www/oorja/public
<Directory E:/LAMPSYSTEM/wamp/www/oorja/public>
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>

Categories