Laravel has been frequently used by web developers and many are deploying it on hosting servers with common plans where there is only Apache available in a simple way.
Many times you are making a development version and do not want to remove the files from the root of your project and replace them with the beta version, among many other reasons.
In this article we will see how to use Laravel in Apache as well as how to use it, if you want, in the root of your project even though it is in a subfolder on the server.
So, to access Laravel in your browser, you can use the command:
Within a Laravel project.
To access directly from Apache, follow the steps below
First, let’s see how to access Laravel on Apache without needing: ~php artisan serve
~.
Or also, depending on your system:
mv meuprojeto /var/www/localhost/htdocs
, or any other case.
Some systems may have a different path, in my case (Gentoo) it is:
sudo vim /etc/apache2/vhosts.d/laravel.conf
.
And insert the content below:
Use the way to restart Apache according to your system. On mine it is:
sudo rc-service apache restart
.
Now, access the address corresponding to your project in the browser, but for the public
folder:
And note that your project is already running directly on Apache!
You may still want to access the project, but identify in the URL that it was redirected.
For this case, create a file named: .htaccess
in the root of your server, example:
And paste the content below, replace the name myproject
with the name of your project:
There are cases where you may need to restart Apache once again and other cases until you clear your browser’s cache:
Now test by accessing: http://localhost and you will be redirected to http://localhost/meuprojeto/public
Perhaps this is the most interesting part of this article, that is, something you won’t find in the Laravel documentation! 😃
If you want to access the project, redirect to myproject/public
, but without changing the URL, replace the content of .htaccess
with this content:
Change
myproject
to the name of your project.vim /var/www/html/.htaccess
I hope I helped, if in your case you have any problems, review the steps.
And don’t forget to share this article!
laravel apache webdevelopment php