I'm using Vagrant provider for server, now look at my directories :
in my system:
https://i.stack.imgur.com/XCXIm.png
vagrant-site
-Project(/var/www)
--public (/var/www/html)
---index.php
now I created a sample .php file in Project folder then when I run vagrant and logged in vagrant ssh when I cd to /var/www ,that .php file doesn't exist there and I could not work with
include __DIR__ . '/../count.html.php';
this line of code not working because this file doesn't exist in /var/www but exist in my system
That index.php file it's work there is no Problem , but I want to create a php file outside of public directory that , just my self can access that , now when I create that file inside Project folder so now this file must be inside /var/www and when I use include command in my php code , php can not found that , I used file_exists() function and gave the path of php file function , now the function returned false then I check /var/www directory to check that php file exist or not , not exist!
I solved problem,
in vagrant file in Sync folders config section , I found out I can add more directories so I synced : ./Project to /var/www but remember,
something it will change after sync ,this directory : /var/www/html ,
that html folder inside apache2 it will remove and replaced with your public directory name (inside your device ,for me it was public ) public directory folder,
and now you need to change your root directory address inside 000-default.conf file in this Path: /etc/apache2/sites-available/000-default.conf after you change this restart apache2 service
DocumentRoot /var/www/html change this => /var/www/your public directory name
sudo service apache2 restart
I have an new Ubuntu server and I installed Apache and PHP.
I have two domains: example1.com and example2.com.
How can i prevent example1.com PHP scripts from seeing example2.com folders? and viceversa?
I wish example1.com could only read folders inside /var/www/example1.com/ and example2.com could only read folders inside /var/www/example2.com/ .
Even at this moment both example1.come and example2.com can see the contents of the entire disk /var/... /etc/... everything.
How can I correct the situation?
Thanks,
Gabriele
With this simple code I can see all the contents of the disk, even outside the domain folder:
$path = "/"; //or "/etc/" or "/var"
$scandir = scandir($path);
This is the VirtualHost configuration, it is the same for both sites, only the domain name and folder name changes.
<VirtualHost *:80>
DocumentRoot /var/www/example1.it/
ServerName example1.it
ServerAlias www.example1.it
<Directory /var/www/example1.it/>
Options -Indexes +FollowSymLinks
AllowOverride All
Require all granted
DirectoryIndex index.html index.htm index.php
</Directory>
</VirtualHost>
What you essentially want to do is to remove read/write/execute access to various folders. Apache is the application which parses your php code that you write above, so you should remove read/write/execute permissions from whatever username you have configured apache to run under i.e. www-data. This will prevent apache executing your above php code successfully as it will not have the necessary permissions to access those files/folders.
For security you shouldn't make apache the owner of any files in the /var/www folder. You should create a separate new user (with no shell) for each web app you store in the www-data folder and assign that new user as owner for all files and folders associated with that particular web app. In this way if Apache is compromised all your web apps and associated files are not compromised simultaneously.
Assign www-data as the group for files and sub-folders in /var/www , so that Apache can read and serve your web apps.
Give www-data read and execute permissions permissions for folders, only give www-data read permissions for files. In this way if Apache is compromised none of your files can not be modified by Apache.
//web app 1, set owner and group, do not set www-data as owner !
sudo chown -R web-app-1:www-data /var/www/app1
//web app 1, set appropriate permissions for all sub-folders as detailed previously
sudo find /var/www/app1 -type d -exec chmod 750 {} \;
//web app 1, set appropriate permissions for all files in sub-folders as detailed previously
sudo find /var/www/html/app1 -type f -exec chmod 640 {} \;
how run Laravel 5.5 project without localhost:8000 url?
my project name lms_manager
I want to load my project without localhost:8000 and php artisan serve command url and I want to load it localhost/lms_manager but I really don't know how do it,
please can I help?
You need to do some changes
1st : move lms_manager\public\index.php to main folder lms_manager\index.php
2nd : Change path in index.php you just moved, from
require __DIR__.'/../bootstrap/autoload.php';
To
require __DIR__.'\bootstrap\autoload.php'; In Windows
Or
require __DIR__.'/bootstrap/autoload.php'; In Linux
I assume you folder is inside htdocs so that you can run localhost/lms_manager
You need to do these changes on your files:
1) Goto C:\Windows\System32\drivers\etc and write this in hosts file
127.0.0.1 lms_manager.com (choose whatever name you like)
2)Goto C:\xampp\apache\conf\extra and write this in httpd-vhosts.conf file
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/lms_manager/public"
ServerName lms_manager.com
</VirtualHost>
I have created small blog application in laravel 5.2 .the app works whenever i run it using php artisan serve.
But without running artisan serve , when i access it from public folder for e.g. localhost/blog/public/addBlog it gives error page not found.
My routes.php has following lines
Route::get('addBlog','BlogsController');
It works fine with php artisan serve with visiting http://localhost:8000/addBlog
The solution is pretty simple. Laravel expects your public folder to be the root of the webserver / url / domain.
Using the serve command works since localhost:8000 is the root then.
Using the longer url doesn't work since your root is localhost/blog not localhost.
A fairly simple solution is to create a virtualhost, to explain how you can do this we would need to know what is running on your localhost (xampp? wamp?)
Nevertheless, the solution would be a virtualhost pointing to localhost/blog/public
Update
example for wamp virtual hosts
C:\Windows\System32\drivers\etc\hosts => open as admin and add
127.0.0.1 blog.dev
C:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf
<VirtualHost *:80>
ServerName blog.dev
DocumentRoot "C:\wamp\www\blog\public"
ServerAlias blog.dev
</VirtualHost>
It's basically the same for xampp, but the path to the vhosts conf is different
Don't forget to restart wamp/xampp after doing the changes. Then simply open http://blog.dev via browser and enjoy
Laravel expects the folder to be in the root of the application so set-up a virtual host and update your hosts file to match.
Use following command
sudo a2enmod rewrite
I had tried in to the ubuntu but i am not sure that will run in another os or not
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]