Create laravel configuration file apache web server - apache2

to delete the public folder from my url I have seen that I have to edit the apache configuration file, but since I also have projects that are not developed with laravel I saw that there is the possibility to create a custom configuration file. Where should I put this file?

You could set up a virtual host to serve as your laravel project like below.
Just edit your Apache's httpd-vhosts.conf file and add something like:
<VirtualHost *:80>
ServerName project-laravel
DocumentRoot "YOURPATH/apache2/htdocs/project-laravel/public"
<Directory "YOURPATH/apache2/htdocs/project-laravel/public">
DirectoryIndex index.php
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Also you would have to edit your hosts file and add a line
127.0.0.1 project-laravel
Then, restart Apache and enter the project-laravel into your browser bar.

Related

403 Forbidden after changing DocumentRoot

So, I've tried running a domain, a sub domain and another domain on one machine. I've set up a conf file for every site:
<VirtualHost *:80>
ServerName websitea.com
ServerAlias www.websitea.com
DocumentRoot /var/www/html/weba
</VirtualHost>
<Directory /var/www/html/weba>
Order allow,deny
Allow from all
Require all granted
</Directory>
The same folder config can be found in apache2.conf as well (I tried experimenting with it) and it's the same config across all sites.
The issue is that after putting this DocumentRoot and disabling 000-default.conf I get 403 forbidden.
What I've tried doing so far:
Changing owner to www-data:www-data
Changing perms to 755/777
Putting the directory configurations in
apache2.conf or the website's conf putting all sites in 1 file
all kinds of directory settings (Options Indexes FollowSymLinks,
AllowOverride none/all, Require all granted, Allow from all, Order
Allow,Deny)
but none would work...
EDIT: I found out that the website goes to /www/var/html/ even though the domain is set to get to /www/var/html/weba, DocumentRoot pretty much does nothing in the configurations.
It seems you created a new virtual host configuration file on this path /etc/apache2/sites-available/
you need to enable the website virtual host conf file, for example, id website virtual host conf file name is 'websitea.conf'
then you need run below command
sudo a2ensite websitea.conf

Get Apache VHost to load index.html instead of web directory

I'm having no luck finding this question answered so I'm asking this myself.
To get my VHost working, I followed this answer. My (working) "httpd-vhosts.conf" file looks like this
<VirtualHost *:80>
ServerAdmin jesuscc1993#gmail.com
DocumentRoot "Z:/Projects/Web/MetalTxus Site"
ServerName metaltxus.test
ServerAlias www.metaltxus.test
<Directory "Z:/Projects/Web/MetalTxus Site">
#Options FollowSymLinks
Options Indexes FollowSymLinks
AllowOverride All
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
As far as I know, I should change "Indexes" with "-Indexes" to make the web load "index.html" instead of the web directory.
However, when I did that, my WAMPServer wouldn't start. It would if I removed "FollowSymLinks" option but then all I got was a "403 - Forbidden" page ("you don't have permission to access "/" on this server").
As looking for a solution got me nowhere, I used this as my last resource.
I'm using latest WampServer version in Windows 8.1. I want to test an AngularJS application.
If you need any more information, go ahead and ask.
Try this :-
<VirtualHost *:80>
ServerAdmin jesuscc1993#gmail.com
DocumentRoot "Z:/Projects/Web/MetalTxus Site"
ServerName metaltxus.test
ServerAlias www.metaltxus.test
<Directory "Z:/Projects/Web/MetalTxus Site">
AllowOverride All
Options Indexes FollowSymLinks
Require all granted
</Directory>
</VirtualHost>
The Require all granted is Apache 2.4 syntax where you were using Apache 2.2 syntax when using
Order deny,allow
Allow from all
Now all you need to do is place a file called index.html or index.php in the "Z:/Projects/Web/MetalTxus Site" folder.
I would suggest removing the space in the folder name MetalTxus Site its not absolutely necessary but it removes another possible complexity.
Also if you dont actually mean to give access to the site to The Universe try using
Require local
And if you want to be able to access the site just from other PC's on your internal network use
Require local
Require ip 192.168.1
ADDITIONAL SUGGESTION:
Also check httpd.con has thi sline uncommented
LoadModule dir_module modules/mod_dir.so
An has this
<IfModule dir_module>
DirectoryIndex index.php index.php3 index.html index.htm
</IfModule>

How to fix ERROR: Site domain.com does not exist, while adding subdomain to apache2?

I'm trying to add subdomains to my home server.
svn.domain.com
trac.domain.com
Due to dynamic IP I use dyndns service, on top of that I have domain.com hosted somewhere else. I created CNAME for subdomains on remote host to point to my user.dyndns.org domain.
So now when I visit either of subdomains: trac or svn, I see "It works!" message.
This done, I created two virtual host files under /etc/apache2/sites-enabled
file1: svn.domain.com and file2: trac.domain.com
contents:
<VirtualHost *:80>
ServerName trac.domain.com
DocumentRoot = /var/www/trac/repos
<Directory /var/www/trac/repos>
Order allow,deny
allow from all
</Directory>
</VirtualHost>
And
<VirtualHost *:80>
ServerName svn.domain.com
DocumentRoot = /var/svn/repos
<Directory /var/svn/repos>
Order allow,deny
allow from all
</Directory>
</VirtualHost>
But I get error: ERROR: Site trac.domain.com does not exist!
what am I doing wrong?
I had this problem when upgrading from Apache 2.2 to Apache 2.4. The (ridiculous) solution was to ensure all files end with .conf, or a2ensite would ERROR: Site example does not exist!.
Also, when linked manually in sites-enabled, they would not even load without the .conf extension.
I also came across the same problem when I upgraded from Apache 2.2 to 2.4; all my virtual hosts suddenly broke and while trying to search for why this was the case, I stumbled across this question.
It turns out the reason is because of a difference between my old apache2.conf and the new apache2.conf. My old Apache 2.2 conf file had the line
Include sites-enabled/
whereas my new Apache 2.4 conf file had the line
IncludeOptional sites-enabled/*.conf
Lo and behold, when I changed the line to
IncludeOptional sites-enabled/
everything went back to normal.
Try moving the files to /sites-available. Then run a2ensite svn.domain.com and a2ensite trac.domain.com and reload Apache.
if you type a2ensite. it will prompt. Which sites do you want to enable (ie., after you put a .conf file in the sites-available and link it from sites-enabled.
a2ensite expect the full name of the conf file with the .conf extension
a2ensite ONLY accepts .conf files, so copy all sites in sites-available so the have a .conf extension (renaming didn't work itconfused the linkssomehow), erase the original files from sites-available AND sites-enabled. use a2ensite on the new files (you don't need to add .conf) and it all works, with our without the *.conf in /etc/apache2/apach2.conf
There must be some "memory" of the original file even when it is renamed -the symbolic link renames also, butthe erases & enabling "new" .con files works and you can then use a2dissite and a2ensite as before
1) remove all default site inside sites-enable
a2dissite <site-configuration-file-name>
2) take a closed look at your config file: start with a minimum properties like:
<VirtualHost [Domain]:80>
ServerAdmin webmaster#localhost
ServerName [Domain]
DocumentRoot [webAppPath]
<Directory [webAppPath]>
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/my_domain_name_error.log
CustomLog ${APACHE_LOG_DIR}/my_domain_name_access.log combined
</VirtualHost>
My solution for local server name is replacing:
sudo a2ensite serverName
with
sudo a2ensite serverName.conf

Local domain simulation with Apache2 and Yii

I'm trying to convert http://localhost/website to http://website.loc, but I'm not able to do that. Here's what I could do:
I edited /etc/hosts (I'm on Ubuntu) by changing 127.0.0.1 localhost to 127.0.0.1 localhost website.loc and saved changes
I created a new file named website inside /etc/apache2/sites-available with this content:
<virtualhost website.loc>
ServerName website.loc
DocumentRoot /home/myuser/projects/website/
<directory /home/myuser/projects/website/>
AllowOverride all
Options Indexes FollowSymLinks MultiViews
Order allow,deny
allow from all
</directory>
</virtualhost>
And I created a softlink to sites-enabled to enable this. After that, I restarted Apache.
By the way, I am using the Yii framework with any request to / redirected to /index.php, so index.php is not needed in the query.
So, when I write website.loc/ into chrome, it moves me to http://website.loc/site/login (the login index page, that's almost expected even if I was logged in as localhost, because the site url "changed" to website.loc, so the cookies are not shared), but the content is:
Not Found
The requested URL /website/index.php was not found on this server.
Apache/2.2.16 (Ubuntu) Server at website.loc Port 80
Am I doing something wrong? Thanks in advance, mates
Edit: It was all about the .htaccess inside /home/myuser/projects/website. It's RewriteBase was pointing to /website. Changing this to / and it worked like charm. Thanks #Chux for reminding me to check the .htaccess!
First, http://website.loc/index.php, check if that work. If that work, means that you need to create an .htaccess in your website root folder to enable that route format

cakephp - one framework, a few apps on localhost subdomain

How to prepare CakePHP framework to work for many apps in one CakePHP framework?
I want prepare structure folders like this:
app1/
app2/
app3/
cake/
vendors/
plugins/
index.php
I would like using http://app1.localhost/ do running app from app1/ folder?
It's possible?
Basically all you need to do is configure the app/webroot/index.php file of every individual app correctly to point to the correct ROOT/cake folder. The rest is Apache virtual host configuration to point the subdomains to the right app folder.
I'm running XAMPP but I'm assuming you're running something similar on your machine. Anyway, go into your apache\conf folder and open up the httpd.conf file. XAMPP has a file called apache\conf\extra\httpd-vhosts.conf that is better for adding Virtual Hosts.
So you'd want to enter the appropriate directives like so...
<VirtualHost *:80>
ServerAdmin postmaster#localhost
DocumentRoot "C:/path-to-your-app-webroot-folder-no-trailing-slash"
ServerName app.localhost
##ServerAlias www.dummy-host.localhost
ErrorLog "logs/app.localhost-error.log"
CustomLog "logs/app.localhost-access.log" combined
<Directory "C:/path-to-your-app-webroot-folder-no-trailing-slash">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Furthermore, if you're on Windows XP, you'll want to make an entry in your C:\Windows\system32\drivers\etc\hosts file of 127.0.0.1 app.localhost to resolve the sub-domain. That should get the job done.

Resources