I have a question about a bad practice in Laravel.
I have only one server folder available for Laravel (in IIS).
There, I have the production site.
If I want to add a copy for development and testing against the test database, where must I place it?
Inside the production's version public folder? I donth think because it's unsafe. Sure will be an obvious best practice for that.
You can open a new port for it.
Example:
Config Virtual host with Production site:
Create a configuration file our laravel production project by typing the following commands
cd /etc/apache2/sites-available
sudo nano production.conf
In the production.conf file created paste the following content to the file and close it after saving.
Replace laravelproduction.com with the domain name of your website inside the file.
<VirtualHost *:80>
ServerName laravelproduction.com
DocumentRoot /var/www/html/production/public
<Directory /var/www/html/production>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2dissite 000-default.conf (disable the default .conf file)
sudo a2ensite production.conf (enables the newly created .conf file)
sudo a2enmod rewrite (enables the rewrite)
Also, restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
Config Virtual Host With Dev site
Create a configuration file our laravel dev project by typing the following commands
cd /etc/apache2/sites-available
sudo nano dev.conf
In the dev.conf file created paste the following content to the file and close it after saving.
Listen 8100
<VirtualHost *:8100>
ServerName laraveldev.com
DocumentRoot /var/www/html/dev/public
<Directory /var/www/html/dev>
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Enable the newly created .conf file and disable the default .conf which is pre-created by apache and enable mode rewrite for this to function appropriately. These are the comand to help you do that.
sudo a2ensite dev.conf
Finally restart your apache server so that it can pick the changes that you have made by typing this command
sudo service apache2 restart
This is how I usually use it. I hope to help you. ^_^
Related
I was testing a clean Laravel 6 installation to migrate an old Laravel project in one Ubuntu 18.04 environment, no used with PHP projects before.
After install PHP, Apache, Mysql... I test one PHP page OK.
I set the permissioins to 777 in /var/www/html/ subdirectories.
I cloned my old Laravel App to migrate and did one clean Laravel 6 installation.
First, I loaded the default welcome page in Laravel 6. After, I put some routes and views from the old project and tried to load some of then, but I had errors of type:
page don't found
I checked the settings of Apache and if mod_rewrite was available... finally, I run the old project OK, but my Laravel 6 is dissapeared. I can see it in the disk, but if load the http://localhost/laravel/ directory I can't see it.
Edited
Content of /etc/apache2/sites-available/000-default.conf:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
What i can suggest you to try is to define one Virtual Host for each project in this way:
Put this (with proper information) inside /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
DocumentRoot "/var/www/html/YOUR_LARAVEL_PROJECT_ROOT/public"
ServerName yourProjectDomain.dev
<Directory "/var/www/html/YOUR_LARAVEL_PROJECT_ROOT/public">
AllowOverride All
Options FollowSymLinks +Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
And inside /etc/hosts put
127.0.0.1 yourProjectDomain.dev
Then check the permission on /var/www/html and each subdirectory (you can use cd /var/www/html && sudo chmod -R 777 * to set everything as readable, writable and executable).
Then clear the cache of the project (delete all the files inside the bootstrap/cache folder).
Then you should be able to access that project just using yourProjectDomain.dev on every browser inside your pc.
I install LAMP on my droplet in digital ocean, it did works good but now just tell "this site can't be reached, refused to connection" my IP is 157.230.139.112
My project worked well, however, from one day to the next, that simply appeared. I did not have anything important and decided to delete it and create a new droplet, however the same thing happens, I can make migrations and connect with the bd but only rejects the connection.
I did install composer, all the packages, configure my db and my etc/apache2/sites-enabled/000-default.conf and point to the public folder.
Am I doing something wrong?
Your apache server block might not be pointing to your laravel location correctly.
So, you might try configuring Apahce2 site configuration file for Laravel.
Run the command below to create a new configuration file called laravel.conf
sudo nano /etc/apache2/sites-available/laravel.conf
Copy paste the content below into the file and save it. Remember to replace 'Mywebsite' with your own domain name and directory root location.Remember to point to laravel public folder for security.
<VirtualHost *:80>
ServerAdmin admin#MyWebsite.com
DocumentRoot /var/www/html/MyWebsite/public
ServerName example.com
<Directory /var/www/html/MyWebsite/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Save the file and exit.
Enable the Laravel and Rewrite Module
Enable the VirtualHost by running ..
sudo a2ensite laravel.conf
sudo a2enmod rewrite
Alternatively, compare your localhost apache serverblock configuration with that on the server, ie. if you are running apache locally
I just installed an Ubuntu server on virtualbox and moved my laravel project to it's /html folder. After configuring Laravel.conf and my server, this is what I get to see:
It does not show the public folder, however I can visit it through /public, but no links are working. This is my Laravel.conf:
<VirtualHost *:80>
ServerAdmin admin#example.com
DocumentRoot /var/www/html/public
ServerName 192.168.1.104
<Directory /var/www/html/public>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Anyone knows what miskake I'm making?
For your first problem the public folder is not showing but you can visit it. this is because the .htaccess file is disabling directory listing withing public folder
For your second problem which is you are unable to visit laravel index page links this is because laravel rewrite url rules are not working and to enable them you sould enable apache2 rewrite module as follow :
sudo a2enmod rewrite
then restart your webserver
sudo systemctl restart apache2
now your problem should be fixed.
I have started working in laravel and using lampp. I have watched many tutorials that use a vhost to make user-friendly url. I want to do it on Ubuntu 16.04.
Following tutorial is not working for me:
https://ourcodeworld.com/articles/read/302/how-to-setup-a-virtual-host-locally-with-xampp-in-ubuntu
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName mywebsite.dev
</VirtualHost>
Setup a virtual host for a Laravel project
First, copy the default configuration file and rename it:
$sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/myVhost
open myVhost.conf file using this command:
$sudo nano /etc/apache2/sites-available/myVhost.conf
Add the directives:
assuming that the Laravel project is in /var/www/html/
ServerAdmin webmaster#localhost
serverName www.myAwesomeLink.com
DocumentRoot /var/www/html/laravel-app/public
<Directory /var/www/html/laravel-app>
AllowOverride All
</Directory>
so now the file will look something like this:
save and close.
Now add an entry in the hosts file:
$sudo nano /etc/hosts
add this line:
127.0.0.1 www.myAwesomeLink.com
save and close.
Enable site and the rewrite mode:
$sudo a2enmod rewrite
$sudo a2ensite myVhost.conf
Restart the server:
$sudo service apache2 restart
Serve the Laravel project:
open the project folder
php artisan serve
this will serve on port 8000 by default
you can also specify the port
php artisan serve --port=4200
Open the browser:
http://www.myAwesomeLink.com:8000
or any other specified port.
Source.
Its not working because the browsers have updated their security terms and policies including SSL certificates over .dev domains. just change your extension from .dev to something else like .localhost or .test.
<VirtualHost *:80>
DocumentRoot "/opt/lampp/htdocs/basicwebsite/public"
ServerName dev.mywebsite.test
</VirtualHost>
Also change the extension in /etc/hosts from .dev to .test.
127.0.0.1 dev.mywebsite.test
Also keep in mind to restart the service to load the new added virtual host i.e: restart the Apache server
Hope it helps.
I think you also need to add a host in /etc/hosts. Open the hosts file and add this line:
127.0.0.1 mywebsite.dev
You will need to restart server after this.
1.Create new file under this path /etc/apache2/sites-available/myweb.conf
2.Copy the following to the file
# Indexes + Directory Root.
DirectoryIndex index.php
DocumentRoot /var/www/html/mywebsite/public
ServerName dev.mywebsite.test
<Directory "/var/www/html/mywebsite/public">
Options All
AllowOverride All
Allow from all
</Directory>
3.Run "sudo a2ensite myweb.conf"
4.Add this line "Listen 80" to file "/etc/apache2/ports.conf"
5.Restart apache server
I know there are a lot of posts on this issue but none of them address the issue I'm having. I am trying to set up a virtual machine following a tutorial on Lynda.com.
Host is a Surface Pro 2 running Windows 10, guest is Virtual Box 5.0.4 with Ubuntu 14.04.3 LTS. People have had a lot of issues with VirtualBox on Windows 10 but mine installed just fine, I have made it all the way to installing Apache, MySQL etc and I'm able to access the Apache2 server status page on my local browser. I don't seem to be having any port issues and I've followed the tutorial's instructions which were step by step.
The issue I'm having is that I can't access the shared folder. I'm ready to configure PHP and I can't access a file placed in the shared folder, even though I've followed all the directions exactly. The shared folder shows up in the VM manager console with the correct path, but when I place a file in the shared folder and try to hit it through the browser on the host machine I get a 404 error. I've gone over the steps to configure the apache server several times, and it looks like I have everything correct:
**blakers**#sandbox:~$ cd /media/**sf_vbsandbox**
blakers#sandbox:/media/sf_vbsandbox$ id
uid=1000(blakers) gid=1000(blakers) groups=1000(blakers),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),108(lpadmin), 109(sambashare),**999(vboxsf)**
blakers#sandbox:/media/sf_vbsandbox$ **getent group vboxsf
vboxsf:x:999:blakers,www-data**
This is from sites-available/vboxsf.conf:
<VirtualHost *:80 *:8282>
ServerName sandbox
ServerAlias *.dev
LogLevel info
ErrorLog ${APACHE_LOG_DIR}/dev-error.log
CustomLog ${APACHE_LOG_DIR}/dev-access.log combined
RewriteEngine On
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /media/>
Order allow,deny
Allow from all
Require all granted
<Location /server-status>
SetHandler server-status
Order allow,deny
Allow from all
Require all granted
</Location>
UseCanonicalName Off
VirtualDocumentRoot /media/sf_%1
</VirtualHost>
Any help would be awesome!!
hi the problem is in this line :
VirtualDocumentRoot /media/sf_%1 , change this folder to be named like the folder that you are sharing. if its called "vbsandbox" then sf_vbsandbox.
you can confirm by:
ls -la /media/
then the folder name will be there.
you will have to restart apache at the end
sudo service apache2 restart