I would like to configure laravel to whenever a user accesses domain/api he actually accesses the public folder
I have tried the following
1.Created a file laravel.conf with
<VirtualHost *:80>
ServerName ipaddress/api
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/api/public
<Directory /var/www/html/api>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then
sudo a2dissite 000-default.conf //disabled defaul loading
sudo a2ensite laravel.conf
sudo a2enmod rewrite
sudo service apache2 restart
But now the above fails
But on the virtualHost configuration when i make servername to ipaddress without api whenever i visit the ip address it reads api/public but i would like it to read api/public whenever a user visits
ipaddress/api.
What else do i need to add?
I was following
This tutorial
I'm not an expert on Apache configurations, so I'm not sure what's different between what you have and what the tutorial used.
However, I have a similar setup for my websites, however mine looks a little different:
DocumentRoot /var/www/website/public
<Directory /var/www/website/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
Put into context of your configuration:
<VirtualHost *:80>
ServerName ipaddress/api
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/api/public
<Directory /var/www/html/api/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Perhaps give that a try and see if that helps.
Related
I have unizped codeigniter on /var/www/control_cuotas indx.php is placed on that folder and I settrd up a new virtualhost on apache on the 000-default.conf file whith this code
<VirtualHost *:81>
<Directory /var/www/control_cuotas>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/control_cuotas
ServerAlias www.control_cuotas.test
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
But I cannot acces to localhost:81 its Unable to connect and the serve rwas restarted before I tried to access
For example:
<VirtualHost *:80>
ServerName your_project
DocumentRoot "C:/wamp64/www/your_project"
<Directory "C:/wamp64/www/your_project/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
Let's try one more time.
Make sure all your VirtualHosts define a ServerName. Failure to do so will mean trouble as you add more hosts.
<VirtualHost *:80>
DocumentRoot /var/www/control_cuotas
ServerName control_cuotas.test
ServerAlias www.control_cuotas.test
ServerAdmin webmaster#localhost
<Directory /var/www/control_cuotas>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Don't forget to enable the above config in Apache adding it to the sites-enabled list. Then restart Apache.
The file /etc/hosts should look like this at a minimum
127.0.0.1 localhost
127.0.0.1 control_cuotas.test
127.0.0.1 www.control_cuotas.test
Other VHosts should also be represented in this file.
You can also add entries for ipV6 if you want, but it is not a requirement in most cases. (The main case is that you have disabled communication using ipV4.)
<VirtualHost *:80>
ServerName oj.mbstu.ac.bd
ServerAlias www.oj.mbstu.ac.bd
ServerAdmin webmaster#oj.mbstu.ac.bd
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
/etc/hosts
127.0.0.1 oj.mbstu.ac.bd
103.28.121.75 oj.mbstu.ac.bd
<VirtualHost *:80>
ServerAdmin yourname#localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
This is the proper configuration, but as i can see your document root /var/www/ includes the html, just remove the conf document and include you own index.
Then just restart the apache server
sudo service apache2 reload
I have the same configuration and set up only the versions of Apache2 are slightly different. I have set up /api to load the /public.
So, locally (apache 2.4.18)
mysite.local correctly loads /var/www/mysite/application
mysite.local/api correctly loads /var/www/mysite/public
mysite.local/api/subdirectory correctly loads /var/www/mysite/public
I want to replicate this on a hosted dev server (Apache 2.4.7) however I am getting the following:
mysite.devserver.com correctly loads /var/www/html/mysite/application
mysite.devserver.com/api correctly loads /var/www/html/mysite/public
mysite.devserver.com/api/subdirectory incorrectly loads /var/www/html/mysite/application
Local mysite.conf file (working)
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName mysite.local
ServerAlias www.mysite.local
Alias /api /var/www/mysite/public
<Directory /var/www/mysite/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/mysite/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Dev server conf file (not working)
<VirtualHost *:80>
ServerName mysite.devserver.com
ServerAdmin webmaster#localhost
Alias /api /var/www/html/mysite/public
<Directory /var/www/html/mysite>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
RewriteEngine On
</Directory>
DocumentRoot /var/www/html/mysite/application
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I have also tried to add the Alias into mods-enabled but its not making a difference. The code is the exact same, same .htaccess files in both instances.
I've created a Laravel Project, which I have deployed previously with apache2, and working great.
As I finished with my latest deployment, I found that no external CSS was being loaded when I was done with. So I did a check on all step many times over, but I don't think I have missed on anything.
However, upon running with php artisan serve everything works fine.
Here is my virtual_host config file:
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public/index.php
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
In virtualhost configuration, you should try using
<VirtualHost *:80>
ServerAdmin admin#project
DocumentRoot /var/www/html/project/public
ServerName example.com
ServerAlias www.example.com
DirectoryIndex index.php
<Directory /var/www/html/project/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Remove public folder from <Directory> and also remove index.php from DocumentRoot.
I installed a laravel project to /home/user/development. The project is called rpm (/home/user/development/rpm). I also have another project that I have been using at /home/public_html. It's called mgmt (/home/user/public_html/mgmt). I can navigate just fine to mgmt via localhost/mgmt. It's conf file in sites-available is
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/public_html/
<Directory /home/user/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/rpm-error.log
CustomLog ${APACHE_LOG_DIR}/rpm-access.log combined
</VirtualHost>
Now my laravel project (rpm) does not work. Navigating to localhost/rpm gives a 404.
It's conf file looks like this
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/development/rpm/public/
Alias /rpm /home/user/development/rpm/public
<Directory /home/user/development/rpm/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/rpm-error.log
CustomLog ${APACHE_LOG_DIR}/rpm-access.log combined
</VirtualHost>
What could be the problem here? Both of those config files have symlinks in the sites-enabled folder.
Modify the first conf to this. Discard the second conf.
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /home/user/public_html/
Alias /rpm /home/user/development/rpm/public
<Directory /home/user/public_html/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
<Directory /home/user/development/rpm/public/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/rpm-error.log
CustomLog ${APACHE_LOG_DIR}/rpm-access.log combined
</VirtualHost>