I've created a blog, it's a homework of my web application class. The teacher asked us to host it. I'm the only one who have decided to host the server at my own PC, which is always switched on.
I'm running this server in Windows 10. I'm using XAMMP.
I've created a domain name at no-ip.com. After hours of fighting against the configurations, I've got the website working in my computer, in my LAN and finally, the whole Internet too.
I know the worst have been over. So it's just a silly thing I want to fix. I have my website inside this directory: C:\xampp\htdocs\wordpress
If I want to access to it, I must write http://IP/DNS.ddns.net/wordpress
I want to get rid of the "/wordpress"
I would like to access to my website with the specific ddns I have created without having to type /wordpress at the end.
I'm sure this have a name but I can't guess it right now, and I don't know how to configure this for Windows 10. I'm still learning it in another subject, but it's for Linux and Windows Server (IIS). The most alike is Linux (Apache) but the files and directories are different.
Can you help me, please? Thanks in advance!
You should set DocumentRoot variable]1 in apache to the proper path.
For example if you have
DocumentRoot "c:/www"
<Directory "c:/www">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
You should edit it to be
DocumentRoot "c:/www/wordpress"
<Directory "c:/www/wordpress">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
And restart apache
I've created two independent symfony projects and I've moved them to my prod server, for example:
project1.example.com [/var/www/project1/web]
project2.example.com [/var/www/project2/web]
The problem is that when I open up the second address, then project1 is fired up. I checked /var/www/project2/web/app.php and seems it's properly executed, but for some reason, symfony loaders use /var/www/project1/ path. Of course the cache folders were cleared.
Any ideas how to diagnose the problem?
UPDATE
Apache config files:
/etc/apache2/apache2.conf
/etc/apache2/sites-enabled/project1.conf + /etc/apache2/sites-enabled/project2.conf
UPDATE 2
Strange thing, this morning the situation has reversed. Both addresses show site from project2 now. No config nor project files were modified.
You'll need to enable Virtual Hosting in Apache.
Take a look at my article on it, it should answer the question:
https://alvinbunk.wordpress.com/2016/11/21/apache-httpd-virtualhost-config/
If you need further help with that, you can always post another question. I use this all the time.
EDIT #2 - based on Apache 2 conf:
Suggest you combine SSL and HTTP VirtualHost ports like so, and also just have a single Directory directive to the web folder. There are other redundancies in the conf file. Please read some documents first about the Apache config files before asking questions.
<VirtualHost *:443 *:80>
...
<Directory /var/www/project1/web>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
...
</VirtualHost>
For the Project2 problem, have you checked the logs in $APACHE_LOG_DIR to see what they show? I think logs are usually in /var/log; there's probably an httpd subdirectory with the httpd logs. You need to make sure there is an incoming GET request for project1.example.com.pl. If not, you'll need to check all your hosts files to see they are setup correctly.
I've had this problem for a while, and have unsuccessfully searched far and wide for an answer.
<img src="/images/test.jpg" />
Gets an image from (root path - in my case in production in LAMP)
htdocs/images/test.jpg
Whether it's called from htdocs/index.php or htdocs/foo/bar/index.php
I use XAMPP in development, and inside htdocs have project folders, so the method described above although will work when live requires me to alter it to:
<img src="/projectName/images/test.jpg" />
when working locally.
To make this simpler i define a constant BASE, which in development I use:
define('BASE','/projectname/)
And then when it's live I change to:
define('BASE','/')
<img src="<?php echo BASE;?>images/test.jpg" />
This is obviously really annoying and ends up causing several issues. Please can someone shed some light on this situation, what I'm specifically looking to do is use root path in my image/script sources but for:
<img src="/images/test.jpg" />
when called from htdocs/projectName/foo/test.php
to look for the image in:
htdocs/projectName/images/
Is this possible?
An alternate way to handle this is with the use of Virtual Hosts.
A virtual host acts like a second version of localhost that works specifically for a subfolder. For example, you could set up Apache so that when you visit http://example (no .com or anything), it shows you the content from http://localhost/example/. All CSS and JavaScript and links would act as if they were operating from the root folder of a website, since the leading example folder has been trimmed out of the URL.
I can't find a walkthrough that I used to use for XAMPP, but here a similar one that covers all of the main points. It was written for Windows, but I imagine that there are similar mechanisms that you can use for LAMP:
To summarize, here's what the article tells you to do:
Enable Virtual Hosts within Apache
Set it up so that when you visit example, you are sent to 127.0.0.1
Configure Apache so that when someone visits 127.0.0.1 (but the name of the website is example), then it shows content from the example folder.
This is how your production site (which is a single server with multiple websites) has a different "root" for each website.
Have you ever thought about the base-tag in the header of your html content? http://www.w3schools.com/tags/tag_base.asp
<head>
...
<base href="<$path />">
...
</head>
get base path:
$path = $_SERVER['SERVER_NAME'] == 'production.host' ? '/' : 'projectName';
You can either try the solution provided by others in this thread (which are programming solutions), or as an alternative, I do something different (a setup solution).
For me, I like to create an independent environment, in which my projects and development files are separate from XAMPP as much as possible (I am using XAMPP, but the principle applies to other hosting environments). This allows me to easily install new updates for XAMPP whenever they become available without worrying about my projects, and also I like to have all my projects in one folder dedicated to development. This development folder will contain projects for web, mobile, and other environments.
The way I set it up, is I have a c:\dev\ folder, that will contain a list of my projects, each project is on its own. So, for example, c:\dev\project1\, c:\dev\project2\ and so on.
Now, after I create those folders for development, I make sure that the httpd-vhosts.conf file (located at c:\xampp\apache\conf\extra\) and the hosts file (located at c:\Windows\System32\drivers\etc\) have the correct references.
Lets assume that one of my projects is called project1. and it is typically located at c:\xampp\htdocs\project1 then I would normally access it via the browser as http://localhost/project1
However, in order to have an independent environment, and as explained earlier, I would create a development folder in the c: drive called c:\dev, then I would move project1 into it, and ended up with c:\dev\project1
Then, to access this project via typing project1.dev in the web browser, I appended the httpd-vhosts.conf file located at c:\xampp\apache\conf\extra\ as follows:
<VirtualHost project1.dev:80>
ServerAdmin admin#project1.dev
DocumentRoot "C:/dev/project1"
ServerName project1.dev
ServerAlias www.project1.dev
ErrorLog "logs/project1.dev.error.log"
CustomLog "logs/project1.dev.access.log" combined
<Directory "C:/dev/project1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
Also, I have to update the hosts file (located at c:\Windows\System32\drivers\etc\, and add the following entry:
127.0.0.1 project1.dev
127.0.0.1 www.project1.dev
(where 127.0.0.1 is the same as your localhost. Also note that you have to add the second entry in the hosts file for the www alias).
This allows me to access my project as: http://project1.dev
Once this is set, I can now write my code consistently for both my development and production environments, and my references to the root will work just fine.
Also, with this setup, I do not care if I need to update my XAMPP or switch to LAMP or anything else, all I care about is making sure I take care of one file only, which is my setup file httpd-vhosts.conf. And as I mentioned, I always prefer having a separate folder for development, and I can have different types of projects in the development environemt, for example, mobile projects, web projects, ... etc.
Hope this helps.
Note about multisite (subdomain setup)
If you would like to setup a multisite (subdomain setup), then after you enable WordPress for multisite according to the WordPress instructions, you have to do the following:
Assuming you want the following structure for multisite:
project1.dev
www.project1.dev (this is an alias to project1.dev)
sub.project1.dev (this is another setup, subdomain)
Then you have to add the following entry to httpd-vhosts.conf
<VirtualHost sub.project1.dev:80>
ServerAdmin admin#project1.dev
DocumentRoot "C:/dev/project1"
ServerName sub.project1.dev
ErrorLog "logs/sub.project1.dev.error.log"
CustomLog "logs/sub.project1.dev.access.log" combined
<Directory "C:/dev/project1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
And update the hosts file to include
127.0.0.1 www.project1.dev
Note that DocumentRoot points to the same directory for both the main site and the subdomain site.
Repeat the process for each new subdomain you add in your WordPress network.
I think the best way to do this is with a baseurl, set your baseurl in your config and use it for external files.
$config = new Config();
public $baseurl = "http://dev050.nl";
You can use it then as
$config->baseurl;
And maybe this is something interesting for you:
http://twig.sensiolabs.org/
hope it helped.
I do a similar thing to switch databases between my dev server and the hosting server if it's any use to you. No reason why it shouldn't work for a base URL.
// db connect
if($_SERVER['SERVER_NAME'] != "dev.mydomain.org"){
try{
$pdo = new PDO('mysql:host=mysql.***.net;dbname=***;charset=utf8', '***', '***');
}catch(PDOException $ex){
header('Location: error_db.php');
}
}else{
try{
$pdo = new PDO('mysql:host=localhost;dbname=***;charset=utf8', '***', '***');
}catch(PDOException $ex){
header('Location: error_db.php');
}
}
A possible solution could be to use mod_rewrite to automatically change the path on you development server
RewriteCond %{HTTP_REFERER} ^https?://localhost/testsite/
RewriteCond %{REQUEST_URI} \.(jpg|gif|png|bmp)$
RewriteRule ^ /testsite/$1
I believe the above mod_rewrite rule is correct but it would be best to verify this yourself.
I am currently working on a website where the core of the website is in PHP. I now want to write a bunch of applications on top of that core, and was hoping to do it in Rails. I saw a couple things online where you could set single folders to be handled by PHP, (example: http://macdiggs.com/2007/06/29/using-php-inside-rails-structure-on-apache/) but I am hoping to do the opposite, have single folders that are handled by Rails, and then the rest is handled by PHP. For example, having ourwebsite.com/blog as a Rails app, but ourwebsite.com and ourwebsite.com/internal are all in PHP. What kind of Apache configurations would let this happen?
(As a bonus, my server is managed by Plesk, so I am concerned about making straight changes to the apache configuration. I have root access, so I can do it, but I am worried that Plesk might get mad)
EDIT: I should also mention, I am using Subdomains as part of my application, so I would really prefer to have something like ourwebsite.com/rails_app. If that is the only option, I can go that route, but I would prefer not to.
If you want the PHP app to be default application and only use Rails for a subdirectory, this Apache configuration should work for you:
DocumentRoot "/path/to/your/php/app/html"
ProxyPass /some_resource http://127.0.0.1:3000/some_resource
Note that your rails application would be running on port 3000 and you will need the ProxyPass Apache module installed.
I am working on a project and its having some blog in php ie wordpress and application in rails. Just configured it an hour before. Might help you.
<VirtualHost *:80>
ServerName abc.com
DocumentRoot /home/me/apps/my_rails_app/current/public
</VirtualHost>
<VirtualHost *:80>
ServerName blog.abc.com
DocumentRoot /home/me/apps/abc/wordpress
<Directory "/home/me/apps/abc/wordpress">
Options +Indexes FollowSymLinks
AllowOverride All
Allow from all
Order allow,deny
</Directory>
</VirtualHost>
Please help, how do I configure apache (wamp) in windows when I want to use symfony as my php framework, I followed the guide(pdf) from the symfony site. But I end up with this when I access http://127.0.0.1:8080/:
But I end up with this, when I try to access http://localhost/sfproject/web/frontend_dev.php
What is the correct url to access when I want to start using symfony?
I installed symfony on:
C:\dev\sfproject\lib\vendor\symfony
And the projects are in:
D:\Programs\wamp\www\sfproject
I added the lines below on my httpd.conf.
I've done it by left clicking the wampserver tray icon->apache->httpd.conf
I got the code below from the pdf file, and just modify it to match the directory.
#Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8080
#This is the configuration for your project
Listen 127.0.0.1:8080
<VirtualHost 127.0.0.1:8080>
DocumentRoot "D:\Programs\wamp\www\sfproject\web"
DirectoryIndex index.php
<Directory "D:\Programs\wamp\www\sfproject\web">
AllowOverride All
Allow from All
</Directory>
Alias /sf C:\dev\sfproject\lib\vendor\symfony\data\web\sf
<Directory "C:\dev\sfproject\lib\vendor\symfony\data\web\sf">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
I also didn't install symfony using svn. I just copy pasted the downloaded symfony 1.4.zip. Then extracted the contents. It basically looks like this:
Please don't limit your answer to my question, I've just started installing symfony today. So if you have something to tell to a beginner like me, then please do, thanks.
You are getting the correct page! Just missing CSS/Images.
This bit in your config looks wrong:
Alias /sf C:\dev\sfproject\lib\vendor\symfony\data\web\sf
<Directory "C:\dev\sfproject\lib\vendor\symfony\data\web\sf">
Those two directories should match whats in your DocumentRoot i think...
Try
Alias /sf D:\Programs\wamp\www\sfproject\lib\vendor\symfony\data\web\sf
<Directory "D:\Programs\wamp\www\sfproject\lib\vendor\symfony\data\web\sf">
Alternatively:
Copy lib/vendor/symfony/data/web/sf to your web/ folder so that there is a web/sf folder with the same contents as the lib/vendor/symfony/data/web/sf one.