Errors after moving local Wordpress site outside of XAMPP\htdocs - php

Background
As someone who develops multiple websites I wanted to be able to serve each site from within its respective project folder in the filesystem, instead of serving them all under the htdocs directory.
So I moved my wordpress folder (whose site was usually accessed via localhost/wordpress) to my project directory, and followed the instructions in this answer to set up a virtual host with a DocumentRoot and Directory that matches the new location of the wordpress folder. This is the whole (uncommented portion) of my httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress"
ServerName localhost.irm
<Directory "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The Problem
The homepage can now be found at localhost.irm, but it's text-only, with no styles or images, and clicking on any page takes me to an "Object not found!" XAMPP page.
What I've Tried
Accessed the database with PHPMyAdmin, changing siteurl and home in the wp_options table to reflect the new domain
Used the WP-CLI tool to search-and-replace all database instances of the old domain with the new one
Unfortunately none of these solved the problem.

This seemed to be primarily caused by two problems:
The Site Ground Optimiser plugin from my live site that I wasn't even aware was activated on my local site. Deactivating using wp plugin deactivate sg-cachepress (the WP-CLI tool) solved that.
The following line in my .htaccess file, at the root of my Wordpress site:
RewriteBase /wordpress/
I assume it must have been necessary to add for my previous setup and I'd since forgotten about it. Either way, removing/commenting the line out entirely seems to have solved the rest of the problem.
I'm now able to access my website with all styles and images, just like I was before, with the advantage that my files are now being served from my project folder itself instead of from XAMPP\htdocs.

Related

Wordpress alongside Symfony - Error 404 page not found

We have a wordpress blog hosted in a different from our web application. For SEO concerns, we decided to rebuild the blog on the same server as our application.
It already has a Apache2 running with the root path directing to our Symfony application /web folder.
We installed Wordpress in var/www/wordpress, set the permissions on this folder for Apache2 and configured the DB connection. The homepage of our wordpress is visible on the /content path (www.mysite.com/content).
For that, I added a single to my existing apache2 conf :
Alias /content /var/www/wordpress
We started building the homepage, uploaded themes, everything works fine. But when we want to add a new page (ie. /content/blog), we get a 404. Resetting the permalinks does nothing. Setting the permalink mode to ?pageId=XXX allows us to see the new page, but that's not what we want.
Did I miss something in my apache configuration ? Any idea ?
Thanks
In case anyone stumble upon this looking for an answer, I had to add some configuration to Apache for my site :
<Directory /var/www/wordpress>
AllowOverride All
Order Allow,Deny
Allow from All
</Directory>
<Directory /var/www/wordpress>
Options FollowSymlinks
</Directory>

Why I can't correctly deploy this Laravel web site on my remote Linux server? Is it a virtual host configuration issue?

I am very new in PHP and moreover in Laravel (I came from Java) and I am going totaly crazy trying to correctly deploy a Laravel 5.4 projects that works fine in my XAMPP local environment on my Linux server. The problem should be related to virtual host configuration but I can't find a solution also asking question and reading documentation.
In my local environment (I am using XAMPP on Windows) I have setted this virtual host into the C:\xampp\apache\conf\extra\httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/HotelRegistration/public"
ServerName laravel.dev
</VirtualHost>
So opening the laravel.dev URL I obtain the standard Laravel homepage (I have yet not replaced it with a landing page).
Then if I open this URL: http://laravel.dev/registration
I obtain the user registration page developed by me, this because I have this route into my web.php file into my project:
Route::resource('/registration', 'RegistrationController');
Then into my RegistrationController.php there is this method showing the resources/views/registration/index.blade.php view
public function index(){
return view('/registration/index');
}
In local environment, with the laravel.dev vhost pointing to the document root of my Laravel website, it works fine.
Now I have uploaded this Laravel website into my remote Linux server, into this folder: /var/www/html/HotelRegistration
But now my problem is that in this remote environment I had not virtual host (correct me if I am doing wrong assertion: from what I have understand the virtual host is used on the local environment to simulate a domain that Laravel need to point to the public folder, is it this reasoning correct?)
Anyway, this is the URL of the public folder of my deployed web site on my remote server:
http://89.36.211.48/HotelRegistration/public/
As you can see opening it the Laravel landing page is correctly shown, the problem is that I can access to the previous registration page, the only way that I have found is to open this URL:
http://89.36.211.48/HotelRegistration/public/index.php/registration
but it is pretty horrible and above all when the registration form is submitted it is generated a POST request toward this URL http://89.36.211.48/registration that end into a 404 Not Found error.
In the past I explained the situation here: What is wrong in the deploy of this Laravel application? Need I an effective domain instead the vhost used on my local environment?
but now I have do some changes to my Apache configuration followint the suggestion given in the previous post (adapting the answer to my folder structure).
So into this Apache folder /etc/apache2/sites-available I created and enabled the laravel.dev.conf related to my new vhost, having this configuration:
<VirtualHost *:80>
ServerAdmin mymain#gmail.com
ServerName 89.36.211.48
ServerAlias www.laravel.dev
DocumentRoot /var/www/html/HotelRegistration/public/
ErrorLog /var/www/html/HotelRegistration/storage/logs/error.log
CustomLog /var/www/html/HotelRegistration/storage/logs/access.log combined
<Directory /var/www/html/HotelRegistration/public/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
The path are related to where this website is installed on my remote server I am absolutly not sure if these configuration are ok, expecially about the ServerName value (I put here the IP of my server, is it correct?)
Then I enabled this virtual host using this statment:
sudo a2ensite laravel.dev.conf
and I restart apache.
Ok, the problem now is: what have I to do to correctly access to this website?
I still have the same problem, that is:
I still access to the Laravel landing page by this URL: http://89.36.211.48/HotelRegistration/public/
I still access to the registration form page by the horrible URL: http://89.36.211.48/HotelRegistration/public/index.php/registration
Submitting the form I still go to http://89.36.211.48/registration and obtain the same 404 Not Found error page.
So my doubts are:
Is it the virtual host correctly configured?
If it is correct what have I to do to correctly access to this web site? Need I a domain (if yes: what have to point this domain?) or can I use a path into my server in some way (something like: http://89.36.211.48/HotelRegistration/)
I am expanding my comment here.
Set folder structure like on image:
In index.php change paths like this:
line 22
require __DIR__.'/system/bootstrap/autoload.php';
line 36
$app = require_once __DIR__.'/system/bootstrap/app.php';
Thats all what I do when transferring Laravel app to server (and changing .env for database). Sometimes I have to change permissions for storage folders but thats it.

Wordpress Custom Menues

I am currently working on a wordpress multisite project. I have set up a working environment in localhost. In the main menu there is a links to home, so is in subdirectory sites. Now my problem is everything works find in testing server environments as the main site URL is myhost/xx/wordpress_site and sub directory sites are like myhost/xx/wordpress_site/sub_dir. In wordpress Appearance->menu you can only give a static url in the link URL field. What I am looking for is to give a method like site_url().”/sub_dir” in that field so I don’t have to manually alter all the site home URLs when I upload the site to it’s destination domain. Which can be any form?
Any simple solution regarding this problem its greatly appreciated.
Thanks a lot.
I would not recommend to change anything on wordpress code or site url configuration.
because when you will go to production you will have to change it back again.
It will be the best if you will setup the same site configuration on your localhost, you can use the following configuration for your apache server and host file so you will be able to
access your local site by your actual domain.
This way your settings will remain the same and all site links will be the same.
(rename mysite to your site url)
how to change host file:
http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
how to add virtual host apache:
http://httpd.apache.org/docs/current/vhosts/examples.html
Apache configuration:
<VirtualHost mysite.com:80>
ServerName mysite.com
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
host file configuration:
127.0.0.1 mysite.com
restart apache and you will be able to work on localhost like it is the productin server.
* Remove the following when you want to access the real server.

Root path in XAMPP

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.

What is the proper way to configure Magento + Apache while running multiple stores on multiple domains?

This question has been asked amply all over the internet and on SO -- The available answers are obscured by specific details about everyone's particular installation. Hopefully this question will help everyone, including me, understand this better.
My question is "How should we configure the Apache .conf file to handle multiple domains?"
(I know the answer "depends". Hopefully, 80% of the people out there are going to have a basic setup at first and then make it more complex later.) I hope that's a good assumption.
I'm comparing Magento's install to Wordpress. Under Wordpress, the "best way" to install it seems to be to put the whole core into a folder called /wordpress. Then, using Apache rewrite rules and permalinks, obscure the /wordpress folder. In a multi-domain situation, the Wordpress core smartly handles the whole process for you without much modification of the .htaccess files. Further, whatever modifications do need to be made, Wordpress can do it for you - or a plugin can. Gosh, I wish Magento was as easy to install as Wordpress. But it's not. (yet!)
Under Magento, the term "store" is very misleading when we think about URLs. So let's ignore it for now and just worry about the lowest level -- the "Store View". In my case, I have the following:
Main Web Site -> Main Web Site Store -> Default Store View
www.site1.com -> Main Store -> site1_english
www.site2.com -> Main Store -> site2_english
The first column is the domain.
The second column is the store --
misleading title for this discussion.
The last column is the "Store View".
As for where to physically place the files. Most people, including me, want to leave the Magento core alone. No changes at all. So we put that into the htdocs root as follows:
/var/www/html/magento
This is where everyone gets confused I think. The Linux distros are not consistent about where this location is. And worse, lots of people are trying to do this on an economical hosting account. I'm using EC2 myself. Ignoring all that... Stick /magento in your document root. The next thing you might add is a /wordpress folder. Yay. Do it later.
In my apache config, I have it setup like this:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "site1"
SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "base"
SetEnv MAGE_RUN_TYPE "site2_en"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/nowhere
</VirtualHost>
The /nowhere folder has an index.html that says "no where".
The situation that I'm seeing is as such:
Navigate to www.site1.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to www.site2.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to the IP address of my server -> Magento displays the Default Store View
The Default Store View's BASE URL is http://my.ip.add.ress
Here are my questions:
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
Why don't I ever get to my nowhere site?
Why does the www.site1.com keep redirecting to the Default Store View?
Some of the documentation out there talks about creating dedicated folder or copying around index.php or .htaccess. Or making our own .htaccess. In this article, I selected the Apache config file.
Why won't that work right?
Why does the www.site1.com keep redirecting to the Default Store View?
Go to
System->Configuration->General->Web
There you should find Base secure and Base unsecure URL for you store. Moreover to the upper left corner you should see the scope of your settings. So for each store view you should change(if possible) URL of your store view.
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
If I don't mistake in code you specify the code of the "object" you want to launch, and in type you specify the type of this object - store or website. But this is not 100% info.

Categories