Fresh Laravel install displays 403 Forbidden in Nginx - php

I have created a fresh Laravel application by using composer create-project command. Then I put all the folders and files in /usr/share/nginx/html/, which is the default document root for my nginx server. However everytime I runs the http://localhost, it keeps displaying 403 Forbiden. I tried creating a testing index.php (<? php_info();) and it worked fine.
I've read somewhere that I need to set the containing folder (/html), as well as the app/storage folder permission to 777 but still no luck.
Please help me. Thank you in advance.
Here is the nginx default.conf

Laravel projects serve from the <projectName>/public directory. Make sure your nginx config is set up to look there for your index file and NOT in your <projectName> folder only.

Would you edit your question and paste your server config there?
I think it may because index.php is not in the index file list. check these lines:
index index.html index.php;
or
try_files $uri $uri/ =404;

The accepted answer is correct - Laravel services from the public folder and you need to tell nginx to look there - but also a little vague if you're bumping up against this problem. When you create new sites on a Homestead installation by adding them to your .yaml file and using vagrant provision or vagrant up --provision, the created nginx conf file will need editing before Laravel will serve files correctly.
Go to your CLI, and enter Homestead using vagrant ssh or homestead ssh. It will ask for your password, which by default is "vagrant".
Once you're in the virtual machine, type the following commands:
sudo nano /etc/nginx/sites-enabled/your-site-name-here
Then add /public to the end of the existing root near the top of the file (it'll be something like /home/vagrant/projects/your-site to begin with and save in Nano (ctrl+s), then exit nano (ctrl+x).
Once you've exited Nano, restart nginx using sudo nginx -s reload. Your routing will now work!

Related

Bedrock with MAMP can't install WordPress

I have MAMP installed on my Mac with MacOS HighSierra 10.13.4.
I have ran composer create-project roots/bedrockin my /Applications/MAMP/htdocsfolder.
I have started up my servers via the MAMP UI. When I surf to http://localhost:8888/MAMPI get the MAMP startpage so everything seems to be working fine.
When I go to http://localhost:8888/bedrock I get a list of my files and dirs in my bedrock folder:
Index of /bedrock
Parent Directory
.env
.env.example
.gitignore
CHANGELOG.md
...
This is what my .env file looks like:
DB_NAME=adatabase
DB_USER=auser
DB_PASSWORD=apassword
# Optional variables
# DB_HOST=localhost
# DB_PREFIX=wp_
WP_ENV=development
WP_HOME=http://localhost:8888/bedrock
WP_SITEURL=${WP_HOME}/wp
I am wondering what I am doing wrong since I don't see the WordPress installation page.
It looks like apache, by dint of MAMP's default config, isn't serving from the correct directory for a bedrock project.
According to the bedrock docs, you should:
Set your site vhost document root to /path/to/site/web/ (/path/to/site/current/web/ if using deploys)
So, you'll need to modify your MAMP config to serve this project not from /Applications/MAMP/htdocs/bedrock, but from /Applications/MAMP/htdocs/bedrock/web.
You will need to click Set Web & MySQL ports to 80 & 3306 via MAMP > Preferences > Ports.
Then http://localhost/bedrock
Please let me know if this works :)

Run cockpit cms on dokku

I'm trying to run cockpit cms which comes with a dockerfile on a dokku server. The deploy is OK however I can't accces the site. I get a 403 in the browser and in the logs it says:
AH01276: Cannot serve directory /var/www/html/: No matching DirectoryIndex (index.php,index.html) found, and server-generated directory index forbidden by Options directive
I assume I need to set $_SERVER['DOCUMENT_ROOT'] somewhere?!?
Where do I set this and to which path do I set it?
Can I set this as an ENV? Is it /home/dokku/appname?
Thanks for your help!
P.S.: I'm new to both dokku and cockpit cms.
I ran into the same issue and noticed that var/www/html folder was empty after entering in my dokku apps container. Copying files fixed 403 errors but create an issue on install to create database files in storagefolder.
So, i just added these lines in Dockerfile :
...
# Dokku fix
COPY . /var/www/html
RUN chmod -R 777 /var/www/html/storage
VOLUME /var/www/html
...

Apache + PHPMyAdmin - Redirect directory to subdomain

So im running Apache on Ubuntu 16. I have phpmyadmin accessible via a directory because thats how it does it by default (e.g. to access phpmyadmin, I have to go to www.mydomain.com/phpmyadmin)
I wrote an Apache VHost to make it accessible via a subdomain as shown here in my Vhosts:
http://pastebin.com/raw/tyZGbsSC
This works and now I can access phpmyadmin via a subdomain (phpmyadmin.mydomain.com) but the problem is that it is still accessible through the directory (www.mydomain.com/phpmyadmin)
How to i stop this?
There should be a conf file phpmyadmin.conf in /etc/apache2/conf-enabled which contains the following line
Alias /phpmyadmin /usr/share/phpmyadmin
Just comment out that line by putting a hash
#Alias /phpmyadmin /usr/share/phpmyadmin
and restart apache.
That should do the job.
You probably have the server-wide configuration enabled in /etc/apache2/conf-enabled
user#host:~ $ sudo a2disconf phpmyadmin
should disable it for you, or just remove /etc/apache2/conf-enabled/phpmyadmin.conf

Wordpress - Blank pages and 200 http response on Debian using Nginx and php5

I'm trying to start a Wordpress site on my Debian server, using Nginx and php5. I followed different tutorials but stuck : the server is responding 200 http responses to any url typed from the domain name, mes-affaires doot xyz . My browser is showing a blank page, but no error too.
As the server is responding 200 responses I'm not getting any error log in the Nginx log files which is a problem to know what to do.
Any idea why it's showing a blank screen or how I could spot the current error?
Thanks
Your problem can be caused by many factors:
1. A poorly configured nginx (Read Configuring Nginx)
2. A permission problem (Read step 5 of Configuring Nginx)
3. A missing php module that you can find out enabling PHP error_reporting (Read Pages are still blank? Php error_reporting
September)
Configuring Nginx
Nginx works a little differently from Apache and if you do not use a management panel, the procedure is a bit complicated.
1. sudo apt-get install nginx php5-fpm mysql mysql-dev next activate mysql sudo mysql_install_dband run the setup script sudo /usr/bin/mysql_secure_installation
2. Create a folder in /var/www with your site name (mkdir mess-affaires)
3. go to /etc/nginx/sites-available and create a file with the same name as your domain (touch mess-affaires.xyz)
4. Open your new file with an editor (nano mess-affaires.xyz) and add these lines:
server {
listen 80;
root /var/www/mess-affaires;
index index.html index.htm index.php;
server_name www.mess-affaires.xyz mess-affaires.xyz;
location / {
try_files $uri $uri/ /index.php?q=$request_uri;
}
location ~ .php$ {
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
include fastcgi_params;
}
}
4.1. After this you need to link it to your sites-enabled folder using:
sudo ln -s /etc/nginx/sites-available/mess-affaires.xyz /etc/nginx/sites-enabled/mess-affaires.xyz
Nginx set a default file for example in your sites-available, delete it to avoid the "conflicting server name error":
sudo rm /etc/nginx/sites-enabled/default
4.2. Restart your nginx installation with sudo service nginx restart
5. Set permission to your folder sudo chown -R www-data:www-data /var/www/mess-affaires/ and make sure that everyone is able to read your new files sudo chmod 755 /var/www o to your folder /var/www/mess-affaires and upload the wordpress installation, now you see the website.
If you still don't see anything, see the point 6
6. If you do not see anything, go to your terminal and type:
chmod -R 777 /var/www/mess-affaires
Configuring mysql/phpmyadmin with nginx
Wordpress is a web application that require a mysql database, go to install it!
1. sudo apt-get install phpmyadmin
2. sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/html
3. Now we must now allow the mcrypt module in php sudo php5enmod mcrypt
4. restart phpfpm sudo service php5-fpm restart
5. visit http://YOUR_SERVER_IP/phpmyadmin, log-in and create a new database for your wordpress installation
Pages are still blank? Set php error_reporting
If your pages are still blank, enable php error_reporting.
To do this you can try two ways:
Set error_reporting from your php files
Open your Wordpress index.php and put these lines to the very top of your page (after
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
Set error_reporting from php5-fpm.conf
Open with an editor your php5-fpm-conf, try one of these directories:
/etc/php-fpm.d/mydomain.conf
/etc/php-fpm.conf
If you sing my guide, you have not the native php installation but php5-fpm and you can configure your .conf file error params like this:
; enable display of errors
php_flag[display_errors] = on
php_flag[display_startup_errors] = on
If you use a native php installation, set your config error_reporting like this:
; enable display of errors
display_errors = On
display_startup_errors = On

How to run Laravel without Artisan?

I have PHP with Apache2 and I want to run Laravel Framework without Artisan but I can't! Does anyone know how to run Laravel without Artisan?
I've solved the problem. The problem was in my htaccess and in mod_rewrite (Apache2). Now I can connect to my application only by typing localhost/public..
If anyone wants to make the application public, the more easy and fastest way is:
Rename the "server.php" file in root directory, in "index.php"
Move your .htaccess from public folder to root directory
Make your directory accessible to Apache2 (set correct file/folder permissions).
Thanks to all users for help! :)
Important Edit
Consider using Apache Virtual Hosts (pointing the virtual host to the /public Laravel folder) instead of renaming server.php to index.php because by doing this you will need to prefix "public/" when you use the Laravel's asset() function in your views.
When working with other devs, who are using a different configuration, this might be a big problem because they will be able to see the assets while you will not (or viceversa).
I am using xampp in mac
inside htdocs / run following command:
$ laravel new myblog
After successfully creation run following and do following:
sudo chmod -R o+w storage/
Change server.php to index.php (# root directory)
copy .htaccess from public to root directory
(optional) in resources / app.blade.php → Change to
<link href="{{ asset('public/css/app.css') }}" rel="stylesheet">
run following
http://localhost/myblog/
Easy solution without any code alterations
Point your domain to public/ folder of laravel project.
Enjoy!
~OR~
Create .htaccess in project folder and add below code. This code will rewrite domain to public/ folder of your laravel project
RewriteEngine on
RewriteRule ^(.*)?$ ./public/$1
Hope this is helpful.
Laravel framework is such a pain in the ass for startup PHP guys who are not much oriented about what the hell composer is, and where .phar files are coming from and what are they, and why "Artisan" is trying to ruin your PHP life.
Most people are looking for a PHP framework where all you have to do is download, extract and code.
Nevertheless to make things work, you just need to install Laravel through Composer:
composer global require "laravel/installer=~1.1"
Anyway, you can download Composer from http://getcomposer.org/
After you install Laravel through Composer, navigate to your local server's directory. You might want to use "CD" (Change directory) to do this. (I'm speaking of CLI, whether you're in BASH(Linux) or CMD(Windows))
Then create your very first Laravel project by typing this in command line:
laravel new mywebsite1
Replace "mywebsite1" with your first project name.
And there you go, you're ready to hit the Laravel road.
In my case, I'm still using Windows XP in such development and shifts back to Ubuntu Trusty whenever I feel like I want to smell Linux scent.
So Composer installs "Laravel installer" in:
%userprofile%\Application Data\Composer\vendor\bin
So I make a backup copy of this directory so the next time I use Laravel on other unit with no internet connection, I just have to extract it, and run:
laravel new [myprojectname]
within the same directory and copies the resulting folder to my XAMPP's htdocs or WAMP's www folder.
Anyway I'm just sharing my approach for those with no 24/7 internet connection at home :p
After all it's still best for everyone to read the documentation on how to properly install Laravel: http://laravel.com/docs/5.0/installation
For Windows Users Its very easy to change and run laravel projects on your normal project urls :
1. "server.php" to "index.php" .
2. copy ".htaccess" from public to root directory.
there you go with your normal URL .
localhost/project_name
Artisan is simply a command line interface. It is made to do things like create and run migrations and automate building certain objects within your Application, etc. Essentially, it's only made to help facilitate creating and working on your Application, not run it.
If you are having issues actually getting the Application to run, it is likely a problem with either your PHP or Apache, not Artisan.
Just Follow 3 Step ;
Change File Name : change serve.php to index.php inside your Project name folder.
Move .htaccess file Bring ".htaccess" file to main root [inside your Project name folder ].
Restart your local server. Your are just 1 click away . Restart all services of xampp or wamp
Enjoy
For an aternative maybe you can run it under a virtual host. All you need is just create a new virtual host with your project/public directory as a DocumentRoot.
In my case, I am using XAMPP under Mac OS. These are the steps on how to achieve that:
Enable virtual host config
Ensure virtual host config was enabled, else you can enable it through this file: /Applications/XAMPP/xamppfiles/etc/httpd.conf
$ sudo nano /Applications/XAMPP/xamppfiles/etc/httpd.conf
Remove the hash "#" of this following line
# Include /Applications/XAMPP/etc/extra/httpd-vhosts.conf
Add a new virtual host
$ sudo nano /Applications/XAMPP/xamppfiles/etc/extra/httpd-vhosts.conf
The add a new virtual host (e.g: newproject.dev)
# Virtual host of newproject.dev
<VirtualHost *:80>
ServerName newproject.dev
DocumentRoot "/Users/your-username/newproject/public"
<Directory "/Users/your-username/newproject/public">
Options Indexes FollowSymLinks Includes execCGI
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Note: /Users/your-username/newproject/public is the location of your project.
Update your hosts
$ sudo nano /etc/hosts
Add this following setting:
# Host of newproject.dev
127.0.0.1 newproject.dev
Restart your Apache, go to your browser and your project should be available on http://newproject.dev
I got mine to work by adding the following block to my apache vhost conf file
<VirtualHost *:8003>
ServerName myproject
DocumentRoot "/path/to/myproject/public"
</VirtualHost>
and running sudo chown -R daemon storage from my project root
Well , the easy way is
1) create a new folder"Project" and copy all files except public folder content to project folder
2) copy all files of public folder to root
and you can run laravel without artisan.If you rename server.php and copy .htaccess , it may make trigger some error when you try to run auth artisan command.I experienced problem with auth command.
Laravel with Vue.JS
If you are using vue.js with Laravel and your app is not working without php artisan serve, you need to create a virtual host. This is a simple two-step process for windows.
Step 1: Update you hosts file at C:\Windows\System32\drivers\etc with,
127.0.0.1 dev.example #You can rename according to your app
Step 2: Update you vhosts file with,
I am using Apache which is installed in D:\ so my path for vhosts file is at
D:\xampp\apache\conf\extra
<VirtualHost *>
DocumentRoot "D:\xampp\htdocs\example\public" ##Your path
ServerName dev.example ##Your URL according to what you set in hosts file in step 1
<Directory "D:\xampp\htdocs\example\public"> ##Your path
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
That's it, now you can just visit your app at http://dev.example/
Install and setup Laravel on your local (meaning your local machine).
Once done, copy all files to your hosting.
Create a .htaccess file on your Laravel's root directory. This is to access it without the "public" on the URL.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]

Categories