How to add a website to the Apache Web Server - apache

I have installed a the following Drupal distribution on an Ubuntu virtual machine at /var/www/html.
https://www.drupal.org/project/social
The Composer script installs the project at /var/www/html/project-folder and index.php can be found in /var/www/html/project-folder/html.
Within the file /etc/apache2/sites-available/000-default.conf I have changed the document root to `/var/www/html/project-folder/html'.
Now when I visit the IP Address for the server, it does load the homepage of the PHP based website, but all of the links to other pages are broken, and none of the images can be found.
What is the correct way to add a new site to the Apache web server? Should a VirtualHost be used, or is it better to change the document root?
/etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/project-folder/html
</VirtualHost>

Related

Request to apache2 server always redirects to /var/www (Index of /) site

I am currently trying to setup an virtual hosts following this tutorial on DigitalOcean.
The dummy-site I am trying to serve is under /var/www/example/html/index.html. I have not registered an official domain but setup /etc/hosts/ to resolve example.com to the IP address of my server.
I created another conf file called example.conf under /etc/apache2/sites-available and enabled it with sudo a2ensite example.conf and disabled the 000-default.conf.
Now whenever I go to example.com in my browser I get served:
.
This is the same page I would get when directly going to the IP address of my server. Only when I got directly to example.com/example/html I get served the correct index.html.
My current config looks like this:
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /var/www/example/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And my /etc/hosts file on my laptop like this:
#<ip-address> <hostname.domain.org> <hostname>
<server-ip> example.com
There are some other folders inside /var/www/ as the company I rented the server from had some maintenance sites preinstalled, but that shouldn't matter in this situation. (See edit, this did actually matter).
It feels like I am missing something obvious here, but I can't find a solution for my problem.
Edit:
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.
The obvious thing I was missing, was that 2 additional sites where enabled by default as well.
One had the following contents:
# 10_froxlor_ipandport_<ip-address>.conf
# Created 28.11.2019 21:05
# Do NOT manually edit this file, all changes will be deleted after the next domain change at the panel.
<VirtualHost <ip-address>:80>
DocumentRoot "/var/www/"
ServerName <predefined Server name>
</VirtualHost>
After disabling all the other sites, the request to example.com actually went to the right index.html.
I figure, that the above enabled site actually matched the request coming from my browser and showed the www root directory.

Allow Cachet to run with other sites

I have installed the open source status page Cachet on my macbook's local web server and it works perfectly but during the set up it tells you to change your apache's virtual host to route all traffic to Cachet. I am trying to allow Cachet to run by going to the main domain but if I go to domain/test I would like it to go to another web page. I tried adding another vhost like this:
<VirtualHost *:80>
ServerName http://domain/test
DocumentRoot /Users/macbook/Sites/
</VirtualHost>
but this does not work, I just get error 404 when trying to reach /test page.
Cachet is built using the Laravel framework, so there is a front controller in the public/ directory. That's why you need to route all the requests to this file. But you do not need to route all the traffic of your server to Cachet, that's just the traffic of the site (Cachet), in order to /setup and others are executed by /public/index.php.
Your vhost file may be simple, below an example of what it could be.
It is a simple vhost configured in Mamp, on OSX.
<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/Cachet/public"
ServerName status.mysite.com
<Directory /Applications/MAMP/htdocs/Cachet/public>
AllowOverride All
</Directory>
</VirtualHost>
The routing to the public/index.php file is performed by a .htaccess file, so you don't have to write this configuration in your vhost. All you need to do in your vhost is to allow the .htaccess execution.
Note for local web server
If you want to use a custom domain name, you'll need to
update the /etc/hosts file to match the domain with your loopback IP
address.

laravel 5.2 500 error on apache 2.4 and Centos 7

I have apache 2.4 on my both local and server machine, local one use ubuntu 12.04 server use Centos 7. I try combine old fuzybox framework in '/var/www/html/projectx' directory and laravel 5.2 framework in '/var/www/html/projectx/api' directory.
project directories:
Local laravel /var/www/html/api/
Remote laravel /var/www/html/projectx/api/
permissions in server public folder setted 777 for test:
[user#xxx]# ls -l /var/www/html/projectx/api/
total 184
...
drwxrwxrwx 2 root root 4096 2016-04-13 13:22 public
...
My 'projectx.com' url open fuzybox app, when i go to url projectx.com/api I get api directory files and folders list, it show that http server work and i can reach api directory, but when I go to projectx.com/api/public I get error 500. On my local machine every works fine.
virtual host config:
<VirtualHost *:80>
ServerName projectx.com
ServerAlias projectx.com
DocumentRoot /var/www/html/projectx
ErrorLog /var/www/html/projectx/error.log
CustomLog /var/www/html/projectx/requests.log combined
</VirtualHost>
also I tried bottom virtual configurations but get some 500 error when go to projectx.com:
<VirtualHost *:80>
ServerName projectx.com
ServerAlias projectx.com
DocumentRoot /var/www/html/projectx/api/public
ErrorLog /var/www/html/projectx/error.log
CustomLog /var/www/html/projectx/requests.log combined
</VirtualHost>
You need to point your web server to a public directory to make Laravel work. For example, if you installed Laravel into /var/www/html/projectx/api/ directory, you can use these Apache settings.
DocumentRoot "/var/www/html/projectx/api/public"
<Directory "/var/www/html/projectx/api/public">
Do not forget to restart Apache after these changes.
Then just use simple routes for your API:
Route::get('api/getSomething', 'ApiController#getSomething');
And use URLs similar to this:
projectx.com/api/getSomething

The requested URL /services was not found on this server

I have a LAMP environment. Running Ubuntu 14.04
I have installed and configured everything correctly (or at least I think so) but only the homepage of my website loads.
My domain is www.codeclimb.com but if you navigate to any other pages I get this error
The requested URL /services was not found on this server.
Here is my vhost setting for apache.
<VirtualHost *:80>
ServerAdmin chris#codeclimb.com
DocumentRoot /var/www/codeclimb.com/public_html
ServerName codeclimb.com
ServerAlias www.codeclimb.com
</VirtualHost>
What can possibly be the problem? I can log into my wordpress admin panel but no content loads. I can only see the sidebar with links to "dashboard, posts, settings, ect..." but will not display content on the right side of the page.

How to add a virtual host on a folder that is located on another computer?

I have Zend Server installed on my machine (windows 7 home edition) and I´m trying to set up a virtual host on a folder that is located in our server. For some reasons, I can't set an apache web server in there, so it must be done in my own computer.
But I can't get it done. My virtual host setup in httpd-vhosts.conf is like this:
<VirtualHost *:8081>
ServerAdmin web#web.com.br
DocumentRoot "\Data\Websites\Online\TheClientName\Site"
ServerName clientname.local
ServerAlias clientname.local
ErrorLog "logs/clientname.log"
</VirtualHost>
And the hosts file:
172.17.10.1/Data/Websites/Online/TheClientName/Site clientname.local
I have checked the Apache log. There's a Warning:
Warning: DocumentRoot [C:/Data/Websites/Online/TheClientName/Site] does not exist
I got full access to this folder, and I have it mapped like a local drive. I tried to set the DocumentRoot as follows, but no luck; Apache does not restarts after setting the 'Z:\'.
"Z:\Data\Websites\Online\TheClientName\Site"
I wonder if there is a way to point this v-host to server folder. Any ideas?