I am working on a project using ZF3 and my requirenment related to local server. Suppose user 'test' login on the system then url for that user should be http://test.10.1.1.55
I have already googled for this and found a post
Create subdomains on the fly with .htaccess (PHP)
For production environment subdomain is working properly but not for development environment. My server guys said to me this is not possible for local server so my question is this posible to create subdomains on local server like as live server?
e.g.
http://test.10.1.1.55
http://test1.10.1.1.55
Note: Local server means I am talking about a system that can be accessed from others system on browser.
If you are using apache on Linux then you would go to
cd /etc/apache2/sites-avaiable/
cp 000-default.conf subname.localhost
nano subname.localhost.conf
Modify DocumentRoot to the root folder of your subdomain
Underneath add
ServerAlias subname.localhost
ServerName subname.localhost
Then remove the entry for:
<Directory /var/www/html>
</Directory>
Save and exit
Then enable your new sub
sudo a2ensite subname.localhost.conf
sudo service apache2 reload
or
sudo service apache2 restart
Re-reading your question you may be able to just use test.localhost instead of the IP.
localhost is the url for your local server by default.
In this case, test.10.1.155 becomes a name, rather than an actual IP address.
You could edit your /etc/hosts file, to add all these named entries, mapped to the same local IP address.
Some additional help about the Hosts file:
https://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
Related
Good day guys in my application I want to change the normal http://127.0.0.1:8000/ that laravel uses to serve sites when one runs php artisan serve to example.com and this should have sub domains like app1.example.com and app2.example.com.
In the main time I have tried to create a virtual host for my site by creating a .conf file inside of etc/apache2/sites-available/example.com.conf and here is how it looks:
<VirtualHost *:80>
ServerAdmin webmaster#example.com
ServerName example.com
ServerAlias www.example.com
DocumentRoot /home/tangaye/sites/example/public/index.php
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
After doing that I enable the virtual host I created by running sudo a2ensite example.com.conf and sudo service apache2 reload to reload apache2 configuartions and sudo service apachIe2 restart from the on I added the address my site points to in /etc/hosts:
127.0.0.1 localhost example.com
127.0.1.1 tangaye
After doing all this when I run php artisan serve from my laravel site directory I still see my site being launch like this:
Laravel development server started: http://127.0.0.1:8000
After all I have done I expected to rather see this:
Laravel development server started: example.com
The worst thing is when I try to access example.com in my browser it tends to search for it on the internet.
At this point I don't really understand what really I'm doing. All I want is to be able to customize my site domain name LOCALLY and add other sub domains.
Will appreciate any help. Thanks!
You can't specify port numbers in /etc/hosts. There's no way to get around that part.
You should be able to just throw example.com after the localhost definition:
127.0.0.1 localhost example.com
and then it will also resolve to 127.0.0.1 ... then it's just a matter of name-based hosting configurations in Apache. Your file looks pretty good, but DocumentRoot is specifying a folder, not a file. Remember to do an a2ensite to enable your site (it's really just creating a symlink in sites-enabled pointing at the sites-available file) and restart Apache.
To avoid your browser interpreting a web address as a search term, you can prefix it with http://
Note that PHP's built-in development server and Apache are two completely separate ways to serve a PHP webpage/app.
php artisan serve is a rapid development tool, allowing for easy access to a PHP project without the need to set up a full-fledged web server (e.g. Apache). All you need is PHP and you can run Laravel or other PHP projects. (It's also important to note that this should be used for development only, never in production.)
Apache, on the other hand, is a full-featured web server, with all the bells and whistles, including virtual host management. And it works over port 80, so no need to add the port to your URLs.
If you want to use a named URL in your development environment, you should:
Install Apache
Configure Apache, including virtual hosts and PHP configuration.
Modify your hosts file to point your chosen development domain name to your local machine (or the machine serving your app, which could be a Vagrant box, Docker, etc. if you choose to use such tools).
Don't bother using php artisan serve at all.
I converted my project to a Laravel Project. And i created a new website. And it is working fine.
My real application is on .com domain. My Laravel project is on .net domain Two applications are in same server. (Server is centos)
i created and old directory and i moved my httpdocs folder on .com domain to old directory.
mv example.com/httpdocs example.com/old/httpdocs
and i moved my laravel project from .net domain to .com domain
mv example.net/httpdocs example.com/httpdocs
And i get in .com domain i'm recieving an error.
"No input file specified"
What should i do ?
Make sure you've pointed your web server to a public directory of your Laravel app. If you're using Apache, you should use something like this:
<VirtualHost *:80>
ServerName myapp.localhost.com
DocumentRoot "/home/vagrant/projects/myapp/public"
<Directory "/home/vagrant/projects/myapp/public">
AllowOverride all
</Directory>
</VirtualHost>
Then restart your web server.
Also, make sure all subdirectories and files were moved to a new directory.
If you own both domains and planning on keeping them, you can just add a cname record to point to the .net domain.
That way both domains will point to the same instance.
Or you can do the change on your /etc/nginx/sites-available/example.com.conf and do a sudo service nginx restart
I'm trying to create a copy of an existing Magento website on my localhost for developing purposes.
I followed all the steps listed here: Copy ec2 files to local
I also created a fake domain for my localhost so that there’s a “.” in it as I read somewhere this is required by magento. So now my localhost fake URL is something like: www.mysite.local
I have XAMPP installed on OS X 10.9.1 and I placed the magento filesystem as follows:
/Applications/XAMPP/xamppfiles/htdocs/magento/
In the database I added the local URL as follows:
update core_config_data
set value = ‘http://www.mysite.local/’
where config_id = 6;
and on local.xml I entered the following parameters:
<host><![CDATA[localhost]]></host>
<username><![CDATA[myusername]]></username>
<password><![CDATA[mypassword]]></password>
<dbname><![CDATA[mydatabase]]></dbname>
where localhost is just localhost, myusername is the username for the db I restored on my local XAMPP server, mypassword is the password for that same db, mydatabase is the name of the same db.
Still, when I browse to www.mysite.local/magento/ or www.mysite.local I don’t see anything appear.
What am I doing wrong?
Thank you so much!
If you're using a local server, here's some basic trouble shooting to help you debug:
Firstly, is the local server active? Can you visit http://localhost without it displaying server not found? If you can't, your local server is most not running. Try firing up xampp and launching Apache.
Secondly, it seems you're trying to create a virtual host for your local server. That's great! Virtual hosts allow you to create individual URLs for projects on the same server. E.g. http://myproject.dev.
However, you first need to make sure that the server understands what you're doing.
You will need to create a virtual host in your server if you haven't already.
I see you're using xampp. What you need to do is navigate to your xampp install, and edit your apache/conf/extra/httpd-vhosts.conf file, which is the file xampp recommends you use solely for virtual hosts.
Reading: Setting Up Virtual Hosts for XAMPP
For example, in Apache, a hosts config file may look like this:
# Base
<VirtualHost *:80>
DocumentRoot "X:/"
ServerName localhost
</VirtualHost>
# Project - Some Project of Mine
<VirtualHost *:80>
DocumentRoot "X:/projects/myproject/public"
ServerName myproject.dev
ErrorLog X:/projects/myproject/logs/apache.error.log
CustomLog X:/projects/myproject/logs/apache.access.log common
php_value error_log X:/projects/myproject/logs/php.error.log
</VirtualHost>
(navigating to myproject.dev displays the files in my X:/projects/myproject/public directory)
This answer is not to explain virtual hosts to you however. There are plenty of amazing resources online to help you get started with setting up your own.
Don't forget to restart your server when you add a virtual host!
If this is already set up, is your computer's hosts file set up to point to your server?
Your hosts file on your computer is used to tell it to do certain actions when you enter a matching url in your browser.
Reading: The Hosts File and what it can do for you
Reading: How to Edit Your Hosts File
For example, using the apache conf file settings above, my hosts file must also include:
# My project - Localhost
127.0.0.1 myproject.dev
It tells my computer to send the request to my local server (at localhost) when I use the URL myproject.dev. The local server then picks up the request, sees that you're accessing myproject.dev and checks if it has any virtual hosts matching that name. Well, whaddya know, it does! It then looks at the DocumentRoot setting for the location of the server files, and continues the process. Think of your hosts file as a local DNS of sorts.
If you've just added the site to your hosts file, it may take a few minutes to start resolving correctly. Wait a little, clear your browser cache and try again.
Finally, if these steps are done, and you're receiving nothing, it may be a server configuration problem, or a .htaccess issue.
If you're running on windows, you can check your event log for apache server errors. If you have set up logging on the virtual host, you can check those files to see if it's picking up your requests, and what it's doing with them if it is.
Most issues after that point will at least yield a visible error in your browser (or a blank page).
I hope this helps!
Also checking the magento error logs could tell you what the issue is, assuming it's actually hitting magento at all at this point.
As Sean mentioned above, one of the most common problems I've seen when copying a magento site is accidentally omitting the .htaccess file - make sure it's present in your site root.
If you tested your site before making the change to core_config_data, then you can also try deleting everything in var/cache and var/session. Also make sure that the web user has write permissions on var.
Regards
Hans
I want to run a localhost php website from some other system. I was able to run the website through the subfolder link as http://192.168.1.102/website. But I want it to run as the main site http://website.
Is there any way we can achieve this.
I have tried adding following in hosts file but didn't work.
host:
http://192.168.1.102/website website
I also tried to do following:
host:
192.168.1.102 website
httpd-vhosts.conf
<VirtualHost *:80>
DocumentRoot e:/wamp/www/website/
ServerName website
</VirtualHost>
Here the DocumentRoot path is the path on other pc.
In the system in which you are hosting your website ( I mean the one you are accessing via LAN ) you need to have below host entry
127.0.0.1 localhost
127.0.0.1 website
and in the system from where you are accessing this remote system need to have below host entry
192.168.1.102 website
192.168.1.102 is the ip address of the machine you are accessing , please change it accordingly
Also If you have problems in setting Up VHOST in WAMP you can verify your way with the below link it worked for me I often use to follow this link
Setting up WAMP server in windows along with virtual HOST
You need to edit the apache config for wamp to point its default root to your folder (not the vhosts but the main file) also you'll need to put wamp into online mode so it'll listen on the external interface not just localhost but I believe this is just a * in the config anyway to listen to all not just 127.0.0.1
In the /etc/hosts add an entry like this:
127.0.0.1 www.localhost
192.168.1.102 website
I have a website where I want users that sign up to get their own subdomain. This subdomain is virtual, and every subdomain uses the same web server files.
I use PHP and Apache, and I know about Virtual Hosts, but I'm wondering where I need to put the vhosts code. First, I don't have access to httpd.conf. Second, I want this to be done automatically upon registration.
I've read about virtual hosts, but didn't find anything that answers my questions. Is there anyone who can explain me how all this works together, or know where I can find my answers?
Can you tell apache to read an extra .conf file? (traditionally you store your vhosts in httpd-vhosts.conf)
if so, add something like the following and restart your webserver
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /abs/path/to/webroot
ServerName domainname.com
ServerAlias *.domainname.com
<Directory /abs/path/to/webroot>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
then in php, you can see which subdomain the user is requesting by inspecting:
$_SERVER['HTTP_HOST']
ie. if the user requests http://user1.domainname.com/index.php
$_SERVER['HTTP_HOST'] will have user1.domainname.com
you can then explode('.', $_SERVER['HTTP_HOST']) to inspect each segment.. etc.
You will need 3 thing for this:
1.
Set your DNS for *.yourDomain.com
2.
Add the ServerAlias directive to the apache configuration for this domain:
ServerName www.yourDomain.com
ServerAlias *.yourDomain.com yourDomain.com
Also make sure that you apache server has UseCanonicalName set to on (this is the default)
3.
Grep the subdomain name with PHP:
$nameChunks = explode('.', $_SERVER['HTTP_HOST']);
$subDomainName = $nameChunks[count($nameChunks) - 3];
(inspired by Janek's comment)
IF your Apache instance is configured for * aliasing, then there is no need to create a virtual named host - You can fake it with PHP by evaluating $_SERVER['HTTP_HOST'].
To determine if your Apache instance will handle it, edit your local /etc/hosts file (or windows equivalent - %SystemRoot%\system32\drivers\etc\hosts) so that the desired virtual name is pointing to your server.
For instance
# An example HOSTS file.
192.168.1.4 testserver testserver.com subdomain.testserver.com secondname.com
This assume that 192.168.1.4 is the IP of your server. Everything after that are alias's that the server can be called.
Then, as Janek suggested create a page that will echo $_SERVER['HTTP_HOST'] to see if it capturing the name correctly. If so, then all that is required is a DNS change and Apache can remain unchanged.
Otherwise without access to Apache.conf (this kind of implies that you don't have access to a lot of things) this will be difficult to pull off. The programming won't be - but the implementation will be.
Here's why:
Apache by default will serve up virtual hosts. But you do need access to the server's conf directory (often located in /etc/httpd/conf.d/) so you can create the virtual host "include" file (IF the Apache configuration is setup to include it - most recent installs should be).
You will need to be able to cycle Apache (restart). Without this the Virtual Host changes won't take affect.
You will need to be able to change the DNS. You can always change your local /etc/hosts file - but in order for visitors to get to your site, you'll need to be able to push through a DNS change. (Which may instantaneous - or it may take 24 hours to propagate).
The scripting certainly can be done (see Cpanel and WHM)
You will first of all need to setup the DNS server to resolve any subdomains to your main IP address, i.e. *.domain.com will have to resolve to your server's IP address. Then the web server needs to handle all incoming requests regardless of subdomain as well, invoking some PHP script. The PHP script can then simply figure out what domain was requested from the $_SERVER['HTTP_HOST'] header and act accordingly.
You're not actually "creating subdomains upon user registration".