I can't able to see the .htaccess file - php

am using Digitalocean VPS
I can't see the .htaccess file
/etc/apache2/sites-available# ls
000-default.conf default-ssl.conf dindudu.conf script.conf site.conf
how to make the .htaccess file .

Use ls -a.
ls without parameters does not list file names beginning with a dot.
And have a look at man ls.

You can simply create a new file named .htaccess in your public directory eg. /var/www/html and start using it ..
Please note you might have to mention Allowoveride All in you apache config or your virtual host file ..
Please refer this link for this https://www.digitalocean.com/community/tutorials/how-to-use-the-htaccess-file

Related

Could not find .php file in /var/www in apache server

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

How to change LAMPP webserver root document?

How to change LAMPP webserver root document? The default is localhost/xampp/ in /opt/lampp/htdocs But I have a different folder in the /opt/lampp directory and there I have my main website document which I want to load by default. How can I do this? I tried to edit the httpd.conf file in the /opt/lampp/etc and so far I did this but it doesnt seem to work : I commented out 229 line (DocumentRoot "/opt/lampp/htdocs") and added DocumentRoot "/opt/lampp/folder" and also commented by prepending # 231 line (<Directory "/opt/lampp/htdocs">) and added <Directory "/opt/lampp/folder>". What I did wrong or what else needs to be done?
You have to restart your server after editing the config file.

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]

Change Apache rootdir to symlink, getting 403 Error

I'm new to .php and servers and all this craziness (and StackOverflow) but I've downloaded Apache and I'm trying to symlink a PHP code folder to the Apache root directory. My Apache root was var/www/html and my PHP code folder is Documents/PHPStuff. I renamed var/www/html to var/www/html2 and I made a symlink in var/www/ called 'html' which links to Documents/PHPStuff, thinking if I renamed the symlink to the name Apache is looking for then it would work.
It doesn't.
When I try to access my test file in Documents/PHPStuff called 'helloworld2.php' in my browser with 'localhost/helloworld2.php' I get a 403 Forbidden Error.
I've been messing with permissions on the symlink and in the PHPStuff directory, changing them to 777 and stuff but it hasn't worked. I also changed my httpd.conf file by changing FollowSymlinks None to FollowSymlinks All. Nothing has worked yet so this was my last resort.
Try to don't touch your http.conf. Instead, edit files from conf.d path.
To grant access to your home paths, edit your /etc/http/conf.d/userdir.conf to activate user dir option, like:
<IfModule mod_userdir.c>
#UserDir disabled
UserDir public_html
</IfModule>
<Directory "/home/*/public_html">
AllowOverride All
Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec
Require method GET POST OPTIONS
</Directory>
then, restart your apache.
Now, you have to create a directory /home/$USER/public_html and create into it the symlink to your ~/PHPStuff, like
ln -s ~/PHPStuff ~/public_html/PHPStuff
You can move PHPStuff to ~/public_html/ instead create the symlink.
Ensure that your homedir have 711 permissions, public_html have 755 and the dirs and files inside PHPStuff are readable by everyone.
Finally, type into your web browser
http://localhost/~user ('user' is your system username)
and you will see your PHPStuff listed. You can type
http://localhost/~user/PHPStuff
to view the PHPStuff content directly.
Good luck!
You shouldn't need to do all of that.
This is how I set up my symlinks.
When I install apache, it's web directory is located at /var/www/html which doesn't really need to be changed.
Then, I create a folder called public_html, you can call it PHPStuff, doesn't matter. What matters is that the folder is inside your home directory, so /home/your_username/PHPStuff
Then link that directory to /var/www/html
sudo ln -s ~/PHPStuff /var/www/html/$USER
You can then access ~/PHPStuff by going to your browser, and typing:
http://localhost/your_username
Which will give you access to ~/PHPStuff
After you do that, set proper permissions:
sudo chmod -R 777 ~
Then make sure apache allows symlinks by going to /etc/httpd/conf/httpd.conf and editing this portion Directory "/var/www/html"
And make sure you have these:
Options Indexes FollowSymLinks
AllowOverride All
Restart apache and everything will work.
You need to make sure apache has access to the folder that the symlink is pointing to, try running:
chmod a+x /home/your-username /home/your-username/Documents/PHPStuff

Can't make Laravel 4 to work on localhost

I'm trying Laravel for the first time after reading an announcement of the Laravel4 beta releasing.
I followed these steps I installed composer and laravel with all the dependencies it needed. I put the laravel inside my ~/public_html directory - as I'm used to do it with Codeigniter, but I think something's wrong here.
If I point to the browser to http://localhost/~carlo/laravel-develop/, it just displays the content of the directory.
Then, while on the filesystem I had a laravel-develop/public folder, it didn't appear on the browser.
I've found that changing the .htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
resulted in an error when I try to access the public folder.
The error:
ErrorException: Warning: file_put_contents(/home/carlo/public_html/laravel-develop/app/config/../storage/meta/services.json): failed to open stream: Permission denied in /home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
another one:
/home/carlo/public_html/laravel-develop/vendor/laravel/framework/src/Illuminate/Filesystem/Filesystem.php line 77
then a long list of errors. The last one is:
require_once('/home/carlo/public_html/laravel-develop/start.php') in /home/carlo/public_html/laravel-develop/public/index.php line 53
Try to change the folder permissions for the storage folder using the terminal:
chmod -R 777 storage
More info on this matter can be found here.
Your errors resulted because laravel couldn't write to the app/storage folder. The rest was just a stack trace. In order to make the storage folder writable, cd into your app folder and then run:
chmod -R 777 storage
Production way, moderate complexity for people not familiar with Unix, but more secure:
Go in super user mode (sudo -s or su).
Create group web (groupadd web)
Add you main user to group web (suppose your user is cool_user, so run usermod -a -G web cool_user)
Add php-fpm or web server user (if php is used as a SAPI module) to web group (for example, on CentOS php-fpm utilize apache user name, so in most cases this will work: usermod -a -G web apache)
Change your project root directory group owner to web recursively (chgrp -R web /path/to/project/root/)
Grant recursively write permission for group (chmod -R g+w /path/to/project/root/
Optionally To allow all newly created by apache (or some other) user files and folders be accessible from your user, make them receive group ownership same as their parent folder by setting groupid bit recursively on your project root directory (chmod -R g+s /path/to/project/root/).
Voila!.
Fast and dirty way, for those who doesn't care about security and want make it works at any cost, not secure:
Go in super user mode (sudo -s or su).
Grant recursively full permission (read, write, execute) for all users (chmod -R o=rwx /path/to/project/root/
In my case I resolved this error by modifying in file /app/config/app.php the default setting:
'url' => 'http://localhost',
to my local custom virtualhost host url:
'url' => 'http://mydomain.local',
This seemed to be THE essential change that resolved the issue (I also chmod'ed the storage folder, as suggested here)
hope this helps some of you..
further to above, if you're using a virtualbox/vagrant VM type environment, then on my Mac I needed to issue the chmod on the host (mac) system but on my Windows box, it was fine issuing the chmod direcly on the VM.
You need to add: Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
You need to read the installation documentation:
http://laravel.com/docs/installation#configuration
Pay attention to the bit here:
Laravel requires one set of permissions to be configured - folders within app/storage require write access by the web server.
There is also other stuff thats useful in that document, so make sure you read it all.
I had the same problem, here is how I solve it:
In your httpd-vhosts.conf files you need to add the configurations to your folders, this is what I have in mine
<VirtualHost *:80>
ServerAdmin your#mail.com
DocumentRoot "/home/carlospublic_html"
ServerName carlos.local
<Directory "/home/carlos/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>>
The webroot of your server should point to the /public folder of your Laravel installation. This is where the index.html file recides from where Laravel is initialized.
First, this answer here will help you with permissions. Second, you may need to add RewriteBase ~/carlo/public_html/laravel-develop to your .htaccess since you're running it out of a home directory.
Hey I got this error too and changing the write permissions didn't seem to work either. It turned out I needed to change the User and Group settings in apache's httpd.conf file. Here's a good tutorial for it: Enable Write Permissions for the Native Built-In Apache in Mac OS X Lion
Checking on the Requirement for the LR4, your local server must have these:
PHP >= 5.3.7
MCrypt PHP Extension
Otherwise, will fail. I am facing this trouble also and now looking for an updated PHP and its extension for my XAMPP.
I like this method better than changing permissions to 777.
Set Apache to run as you.
In terminal type id to get uid=123(Myname).
Open /etc/apache2/httpd.conf and edit it to use your username.
<IfModule unixd_module>
User Myname
Group staff
</IfModule>
Back to terminal: sudo apachectl restart
I ran into this problem a few minutes back and using sudo chmod -R 777 storage seemed to help make the storage/meta/services.json writable. Just to add to what everyone has been saying. This worked for me.

Categories