Whenever I use the following PHP code:
header('Location:/account/login.php');
It goes to the localhost/account/login.php but I wish it would go to the something like this: localhost/MyCurrentProject/account/login.php
Cause when in the webserver the code works fine, since the server considers the root the folder of my website. Is there a way to make this automatic?
I am using XAMPP on Windows, but the principle can be applied to Linux version.
XAMPP starts apache, and the folder with files to execute depends on its config. There are 2 main configs for that:
Virtual hosts config: <XAMPP>\apache\conf\extra\httpd-vhosts.conf
Base config: <XAMPP>\apache\conf\httpd.conf
You can play with ServerRoot & DocumentRoot values in them.
Related
guys I have a laravel project and its working fine. Every time I start the project by typing the command php artisan serve and then by typing the url localhost:8000 in my browser. But now I want to start my project only by typing the url localhost/projectname.
So I did a little bit of digging and found out a way to do this, I made it possible by changing the server.php file from root directory to index.php and copying the htaccess file from public folder to root directory`. This way my browser loaded only html file or php file but css files and js files were not loaded so I had to modify there link on the blade file for example:
Previously a style.css file was linked as:
<link rel="stylesheet" type="text/css" href="{{asset('front_end/assets/css/style.css')}}">
Now I link the same style.css file as below:
<link rel="stylesheet" type="text/css" href="{{asset('/public/front_end/assets/css/style.css')}}">
And It works fine.
But now I have found another problem, I have stored some files (images) in the the storage/app/public/myfolder directory so to access the files I had to use the command php artisan storage:link command and to access the files(images) from above mentioned directory from blade file I use the code below:
<img src="{{$url = Storage::url('myfolder/'.$company->logo_name)}}">
This code did worked only worked when I used to start my project using php artisan serve command. Now I its not linking so what should I do? And also can you guys tell me the way that I changed the server.php file to index.php is the right way or not? And what you guys do in your real projects?
Thank You.
When deploying a Laravel project you want your nginx or apache configuration to point to your public path of your project. Changing the server.php or index.php files are not necessary.
Apache Config Example:
<VirtualHost *:80>
ServerName project.dev
DocumentRoot "/home/vagrant/projects/project/public"
<Directory "/home/vagrant/projects/project/public">
AllowOverride all
</Directory>
</VirtualHost>
As you can see with this apache config example, it points to the public directory of your project.
You can achieve this locally by installing either Apache or nginx on your local machine.
I would recommend following Laravel's documentation guide on using Vagrant's Homestead to get an idea of how this is working before you decide to run this on a server. A link here
There is a couple of options you can take to achieve essentially the same goal. This depends on the machine you are running on and personal preference.
Laravel Valet for Mac
Laravel Homestead
WAMP for Windows
MAMP for Mac
You don't need to modify any file.
You need one of this:
Web server installed locally, Apache or Nginx
A Vagrant Virtual machine for running the project like in production environemnts like Homestead
Valet
If you decide to go with Web Server, you just need to consider to point to project/public folder instead of project.
Doing with one of this options, you won't need to modify the assets url, since public shouldn't be part of your url in any case.
First of all, don't do any tweaks in server.php file, it's fine.
To run your project with url like, http://localhost/my-project.dev or simply my http://project.dev, use WAMP or XAMPP (if working on a windows machine) and lamp for linux. You can also checkout Laravel's Homestead.
Then setup virtual host.
See this tutorial for setting up virtual host on WAMP - http://www.coderomeos.org/how-to-set-up-virtual-host-on-wamp-server
And don't put your assets in public/assets folder to prevent using storage link.
Laravel's documentation does not explicitly say where to execute "laravel new project_name"? Should it be executed at the webserver's root that is htdocs or www? I use WAMP server in Windows.
It should be executed at the parent folder of htdocs or www.
The laravel folder can't live in htdocs, as it will expose all sensitive files.
After that, you must map laravel_myapp/public to something as htdocs/myapp.
You can also symlink the laravel_myapp/public folder to where you want in htdocs.
Depending on your needs, but I would put it in htcdocs/www because is the default folder configured in apache by WAMP, anyway you can change the documentroot of your server if you want.
As long as you have the right folder permissions and the project is created under your root folder laravel shouldn't have any problem with that.
Hope this helps you :)
I am just starting to look at PHP and Apache servers (at the moment use Ruby on Rails). I am looking to get two simple index.php files rendering in the browser, but they will be two separate sites. I have installed everything I need to I believe.
So if I go to localhost I get the Apache2 Ubuntu Default Page. This might be such a simple question but where do I store my files and directories? I have been looking in /var/www/.
I would like to create 2 sample sites as previously said. Could anyone point out where I should be looking and how I differentiate the two sites?
/var/www/ is your root folder for apache so your localhost is pointing to www. To create 2 different website you will require to create 2 new folder in www folder e.g web1 and web2 then localhost/web1 will point to /var/www/web1 same will goest for web2.
You can also set virtual host to make your web url like web1.com and web2.com check here on how to set virtual host in ubnuntu https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-14-04-lts
First, I would like to welcome you in this beautiful world of PHP :)
Now look into this file : /etc/apache2/httpd.conf and locate for this config DocumentRoot "THIS_IS_YOUR_DOC_ROOT_RICHLEWIS".
You can change it to your favorite document root an d restart Apache, or simply put your files here(php, html, images...
I am trying to setup a basic apache 2 webserver just for testing purposes. I have apache 2 installed on Ubuntu 11.10. I can access the root directory on the webserver just fine by going to "localhost" in my browser. This is all located in the default directory: /var/www. However, the problem starts whenever I try to access the subdirectories of my webserver. So, for example if I goto "localhost/phpproject/", which has an index.php file listed in it (and I did test to make sure PHP was working correctly), all it seems to want to do in my browser is attempt to download a file when I type in the address instead of actually displaying anything.
I even tried to give full permissions on the subdirectory to make sure it wasn't just a permissions-related problem. Any ideas?
First of all, you shouldn't be keeping your development files in /var/www folder. Configure your apache to keep your web files within your home directory. In doing so, you don't have to have sudo privilege to edit files in /var/www. If you want to follow my setup, create a directory called www in your home folder /home/yourname/www. Look at my config of /etc/apache2/sites-enabled/000-default
http://pastebin.com/3gcE59Lh
It works good for me.
If you change your config like this, make sure to restart apache [sudo service apache2 restart]
Make sure that you installed PHP correctly and registered PHP in your Apache configuration.
This is the key here, it looks like it's sending you the index.php file, test a PHP file in the main folder behind this sub-directory and see if it tries to download it.
File Could just be:
<?php
phpinfo();
See if putting that in index.php in the parent folder gives you a phpinfo page or tries to download index.php.
If it tries to download it it's just that PHP is not configured in apache to handle files that end in .php
To configure it, add the following lines to your httpd.conf file
LoadModule php4_module modules/libphp4.so
#
# Cause the PHP interpreter handle files with a .php extension.
#
<Files *.php>
SetOutputFilter PHP
SetInputFilter PHP
LimitRequestBody 9524288
</Files>
AddType application/x-httpd-php .php
Make sure that you installed PHP correctly and registered PHP in your apache configuration.
The manual should explain the required installation steps in detail.
in Ubuntu you should install the LAMP option using tasksel at the CL. That will give you Apache, MySQL and PHP all working together. It sounds like you may have installed them separatley and have not configured PHP correctly. mime types determine the servers handling of specific file types.
apesa#ubunt$ sudo tasksel
Follow the prompts
EDIT:
We used to make all the config changes in httpd.conf. If you used package manager, like you did then you will have a distributed configuration environment. You will need to go to etc/apache2/mods enabled and look in the php.conf file. There are directions inside. It sounds like you need to make sure the web server understands the directories and FS locations. Look at #Chrispy example. You won't be using the first line as the php module in your env are loaded via php.load and the config is done in php.conf. That AddType directive is important and tells the server to exec your file instead of serving it. have a look. BTW, the Apache Project supports one of the best listservers out there at URL:http://httpd.apache.org/userslist.html
I installed wamp stack and then installed netbeans ide. The port number for apache is 100.
Created one PHP project at
C:\Users\aaa\Documents\NetBeansProjects\PhpProject2
and project URL http://localhost:100/PhpProject2/
When I click on run, I see the message "http://localhost:100/PhpProject2/index.php URL not found on the server".
What else I need to do to connect http://localhost:100/PhpProject2/index.php to C:\Users\aaa\Documents\NetBeansProjects\PhpProject2?
Please help.
You need to configure Apache's webroot to be C:\Users\aaa\Documents\NetBeansProjects (search for DocumentRoot in the file httpd.conf).
Or you can move/copy your files to the existing webroot, which may be something like c:\wwwroot.
Apache doesn't just magically know where you put your website files, and setting the URL inside NetBeans doesn't actually configure the webserver (I think it's just so that auto-generated links are right).
If you go to http://localhost:100/, what do you see? What is your web root? The folder needs to be in your web root, and I would be surprised if it is C:\Users\aaa\Documents\
I did a Google search for "wamp stack" and found a product by Bitnami... if this is the one you are using, the default web root is C:\Program Files\BitNami WAMP Stack\apache2\htdocs\. If that is indeed the case, then you'd need to move the NetBeansProjects folder to there. (source: http://bitnami.org/files/stacks/wampstack/5.3.6-0/wampstack.pdf page 7)
You need to look into aliasing. That will let you more or less assign directories in the url path to arbitrary directories on your file system.
You have to move your files to your root folder of the Apache installation (htdocs). You should refer to your WAMP installation for where that is located. Personally, I like to use XXAMP for installation.
Netbeans is just an IDE, it doesn't serve the files.