How to set virtual directory for php - php

I am learning php. I am learning through by looking at structure of existing web site. I can configure it correctly.
I dont how to set the virtuall directory for web site. Like ASP.NET you have either host the site on IIS or you can use local ISS. Is there any such thing with PHP.
I am using eclipse for development.

If you're only running a single site on your Apache server, then you simply have to set the DocumentRoot and Directory entries to match your document root.

Related

How to deploy a developed laravel project to a remote server to be an intranet application?

I am sort of new in web development and so sorry if the question is a little out of place or too simple. I just finished developing my first web application using Laravel and it is meant to be used as an intranet application for a specific facility. I developed the application on my windows machine, and now we are moving forward with deployment, I have remote access to the server of the facility (windows server 2012). However, the server does not have internet connection so I can only copy, paste (or any other offline operation), and so I installed XAMPP offline and simply copy pasted the project files in the htdocs directory of the server, then I added the server name in the following files
"C:\xampp\apache\conf\extra\httpd-vhosts"
"C:\Windows\System32\drivers\etc\hosts"
like so:
in "C:\xampp\apache\conf\extra\httpd-vhosts"
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs"
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/proj/public"
ServerName www.something.com
</VirtualHost>
in "C:\Windows\System32\drivers\etc\hosts"
127.0.0.1 localhost
127.0.0.1 www.something.com
After doing so the application starts normally, but of course the database needs to be configured as well in the server, and so here are my questions:
1-Is this the right way to go about doing something like this, or is there a better way of doing it (in terms of overall criteria such as security, maintainability....etc)?
2-If this is the right way, then should I just copy paste the database from my machine to the server or should I ask them to provide internet access to the server so that I can install composer, git and other tools that allows me to automatically generate the database from the code?
3-If i continue using it this way modifying the code will be extremely tiresome, since every time I edit something I will have to follow which files were edited in my machine and correspondingly change them in the server, and so what is the right way to go about maintaining the application? Or is it only possible using internet connection in the server?
I am sorry if the question is too long I am just new in this and would like to get an overall idea on deployment of web applications, of course if there is any other way of doing this that is totally different I am happy to know about it.
You should have the required info for database connetction, such as host, port, username, password and database name.
Once you have them, just edit the .env file in your remote project directory to match those info.
Then run php artisan migrate which will create the database and all the tables. You don't need internet connection to do that.
Since your remote machine doesn't have internet connection, you can just copy all files from your local directory to the remote machine. Composer will just install everything into the vendor directory, but if you copy it as well you don't need to run composer.
To speed up the process a little you can use WinSCP that will allow you to synchronise your local and remote directory. Of course this is not a best practice, but in your case is a huge help.

How to work on server without the site being actually online?

I have a wordpress site, I need to work on it on my server but i don't want the site to be online in any way shape or form. i want to complete the site completely and only then launch it, how can i do this?
thanks,
edit: im currently using xampp, but facing issues, so i want to shift to my server.
Take the wordpress files out of the documentroot (where your files are displayed from)and put them in some temporary document and set up virtualhosts on your server so that you can have more than one documentroot so you can test it in your browser but it wont be live.
You could use something like MAMP or WAMP, MAMP works on both windows and macs, these are local server environments which you install on your own computer. You can then develop them on your computer and once finished, upload the files to the production server. This is quite common practice.
If however, you want to use your server you could block all connections which do not come from your own IP Address. For example in your .htaccess file you could put:
order deny, allow
deny from all
allow from 111.222.333.444
If it was me working on development of a WordPress site I would do it one of 2 ways:
1) Either create a new VirtualHost and password protect it
2) Use a local instance of Apache to serve the WordPress installation locally.
Option 2 is probably the handiest. Pushing the new site live is then a simple case as uploading the theme directory to the live environment and enabling it, provided you keep all relevant files within the theme directory.
Apache can be installed using either LAMP (for Linux) or WAMP (for Windows)

Pointing my domain to a php application in wamp

I have WAMP installed in a machine and I have only one application in the www directory. SO I want localhost to point to my application directly.
In short, if I hit the
http://localhost/
in my browser i want my application to open. I don't want my application url to be like
http://localhost/application/
Can anyone help me out to do the configuration changes.
Thanks,
Uttam Dutta
Put the files for your application in the directory that your DocumentRoot points to instead of in a subdirectory (called application in your example) of that directory.
This answer should also be helpful, if you'd prefer to keep your files where they are now and point the DocumentRoot to the files instead.
Also, you may consider making a virtual host for each of your projects. Read about creating virtual hosts for localhost here.

Zend and web hosting - subdirectory appearing as root

I have learned how to create a simple website with the Zend Framework. Now suppose I want to put it on some web hosting server. In my ZF project, I have a folder named public, which I want to appear as the root of the URL. I want my site to be visible and accessible as
http://www.mysite.com
while being served from a page like /public/index.phtml or similar.
How is this done?
If You want domain like www.mysite.com, u must buy somewhere one (for example ovh.org), there is not free *.com domain.
After that u could direct domain to your host computer (nice free hosting: 60free.ovh.org). There is PHP of course, so i think you could install Zend there.
You have to put the public_html files you're using with Zend_Framework in the root folder of your host. The host server will give you a folder which will be the root for that domain, put in there and you will not have /public/index.phtml in front of your domain name.
Do you already have a hosting server or are you looking for one?
Usually you can achieve your goal by using the tools provided by your hosting provider, some allow you to change the directory from which http://www.yoursite.com is server, set that to /public and you are done.
It really depends on the provider.
You'll need to deploy the entire Zend Framework directory structure to the host you end up using. In your Zend Framework directory structure, you have your public directory. This directory will need to be the one that your web server looks at as your document root. The setup for this is probably different based on which host you use. Some will have web interfaces and others will force you to edit an httpd.conf file.
I'm using Rackspace for our site and the default web location is /var/www/html/. We've deployed the entire site here so we have the following directories:
/var/www/html/application
/var/www/html/library
/var/www/html/public
/var/www/html/scripts
We then had to change our Apache config to point to /var/www/html/public instead of /var/www/html.

/var/www/ folder structure for PHP project

I'm using MAMP just for my development environment and haven't really understood the folder structure of /var/www/project-name/ on a web server. I'm wondering whether you're meant to point the web server to the htdocs folder or it's supposed to point to the root of the project folder?
The reason I ask is because libraries are meant to exist outside of the htdocs folder for security purposes, but how are they pointed to from the web application itself? Surely the web application can't access folders outside of the htdocs folder if the web server is pointing to the htdocs folder for the web application?
A simple solution is to have a folder structure like so:
/var/www/project-name/
+ webroot/
+ libraries/
Point your apache2 DocumentRoot to the webroot directory. Keep all the libraries that you don't want accessible from the web in the libraries directory. In your php code, use the include directive to access the libraries code.
The trick is to understand that php can include any file on your system it has read access to. A person browsing your website can only access files inside your webroot directory.
If you have multiple vhosts on the same server, it's pretty common to have each site in a directory under /var/www, and each of these have a htdocs folder, which is mounted as the web root. You can then have logs and application-specific libraries in a folder above the web root. Eg.:
/var/www/lolcats.com
/var/www/lolcats.com/htdocs
/var/www/lolcats.com/htdocs/index.php
/var/www/lolcats.com/lib
/var/www/lolcats.com/log
PHP can access any file in the filesystem for which the apache server user has the correct permissions. On a linux box running apache without virtual hosts, /var/www is a common place to use for your htdocs directory.
You place the libraries in PHP's include_path which is inaccessible to the general user.
It is a googd idea to map your local websites in directories in the same way as your domains work.
Often you have multiple websites on a single web hosting account, so setup virtual hosts to mirror the setup.
If your shared hosting is:
/var/www/root
/var/www/root/website1
/var/www/root/website2
/var/www/root/website3
Create 3 vitual hosts on your local PC but keep an identical file structure.
Also, use conditions in your config files to setup the site deifferently depending on the server file structure, to ensure the same config file works on both setups. This means you keep your one-step build process.

Categories