I have a VPS running WHM and Cpanel. I have multiple domains hosted there. Say one of them is example.com
What I am intending to do is have two versions of the application.
Production: example.com > /public_html/
Development: staging.example.com > /public_html/staging/
Right now, I am trying to deploy my application to the development environment, i.e to the staging folder.
Envoyer, with a lot of struggle with my hosting provider, is working fine. It's uploading the files as expected. The only issue now is the symbolic link current
Right now the folder structure is:
-staging
- releases
-release1
-release2
- current
My subdomain clearly points out to the staging folder, which will lead it to display all the contents of the folder rather than the application.
Since the application is inside the release folder, how do I make sure that my application runs when we hit the subdomain.
Do I have to modify my virtual hosts file in Apache?
Laravel requires the root for the domain (configured in the relevant apache vhost conf file) to be it's 'public' folder. This is where it's entry point index.php is.
Edit the apache vhosts conf file as per below
<VirtualHost *:80>
ServerName example.com
DocumentRoot "/home/user/public_html/public"
<Directory "/home/user/public_html/public">
Options Indexes FollowSymLinks
AllowOverride all
Allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName staging.example.com
DocumentRoot "/home/user/public_html/staging/public"
<Directory "/home/user/public_html/staging/public">
Options Indexes FollowSymLinks
AllowOverride all
Allow from all
Require all granted
</Directory>
</VirtualHost>
For example.com you install your laravel application into /home/user/public_html folder.
As part of the laravel install it will create the 'public' folder.
For staging.example.com you install your laravel application into /home/user/public_html/staging folder.
Don't forget to restart the web server so it picks up the new configuration.
If you do not have the ability to change the vhost configuration mentioned above, you can use .htaccess file in your public_html folder (note the leading full stop which makes it a hidden file). The following is dependant on your hosting provider allowing .htaccess overrides.
Add the following to the .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
If domain has been set up correctly by the host to point to /home/username/public_html when entering http://example.com then it should automatically call public/index.php.
You will need to do the same in public_html/staging folder.
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 installed backup of website from live server to localhost in xampp. But when I run the project I mean that when I type localhost/folder its shows php info file. I don't know why this happening. Can anyone guide me?
You'll have to configure virtual host on xampp in
C:\xampp\apache\conf\extra\httpd-vhosts.conf
<VirtualHost myproject.test:80>
DocumentRoot "C:\xampp\htdocs\myproject\public"
<Directory "C:\xampp\htdocs\myproject">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Also add this to hosts file in
C:\Windows\System32\drivers\etc
127.0.0.1 myproject.test
Change myproject with the name you want.
I need to set up my Larave project inside another PHP project to access that project using https://example.com/laravel-project
Because I need to use the same domain for the new Laravel project.
For that, I used apache VirtualHost configuration like below,
<VirtualHost *:80>
ServerName example.com
DocumentRoot "C:/Wamp/vhosts/example"
Alias /laravel-project "C:/Wamp/vhosts/example/blog/laravel-project/public"
<Directory "C:/Wamp/vhosts/example">
allow from all
order allow,deny
AllowOverride All
</Directory>
</VirtualHost>
Now routes are working fine but query strings not working well. seems every url missing query strings.
https://example.com/laravel-project?test=value
But Laravel App didn't identify test query parameter.
How can I fix this problem?
The issue was not in VirtualHost configuration, It's in .htaccess file configurations. Updating RewriteRule with [QSA] flag, solved query string missing issue.
RewriteRule ^ index.php?$1 [L, QSA]
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'm starting to learn how to set up a lamp on a vps, and i'm trying to run a laravel project.
This is my 000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
Alias /laravelproject /var/www/laravelproject/public
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
I'm trying to access using the /laravelproject and it works cause i'm redirected to a login page ip/laravelproject/login (like I set using the middleware for not logged users and it works on my local homestead virtual machine). But i got a 404 file not found error. Not a pretty designed laravel one, but a raw and ugly server error
Not Found
The requested URL /laravelproject/login was not found on this server.
Apache/2.4.10 (Ubuntu) Server at '' Port 80
Of course i don't have any laravelproject.com domain to set up, i want to access it simply with my_server_ip/laravelproject.
How can i set up a virtualhost or an alias to run it with all the routes working?
You could also try enabling apache mod-rewrite if not enabled yet.
sudo a2enmod rewrite
sudo systemctl restart apache2
You'll need to make sure the /var/www/laravelproject/public directory is set to AllowOverride All (which I believe you have taken care of by setting /var/www to All). Then make sure the .htaccess file in your public directory is correctly set up: https://github.com/laravel/laravel/blob/master/public/.htaccess
this is because Apache is looking for /public/login/index.html which is not a file. Laravel's .htaccess redirects these requests appropriately, but it has to be in your public folder and Apache has to AllowOverride
edit:
<Directory /var/www/laravelproject/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>