wordpress in apache subdirectory get 404 - wordpress

I was trying to host a wordpress site in a sub-directory of my site. I use apache so I edited the 000-default.conf file with adding the following:
Alias /blog /var/www/html/wordpress
DirectoryIndex index.php
<Directory "/var/www/html/wordpress">
AllowOverride All
order allow,deny
allow from all
</Directory>
When I restart the server, and go to the site, say "example.com/blog", it shows a broken wordpress, with all the 404 errors for the ".js" files. It tried to look for them in the root site (example.com). Question is: how can I set it for the subdirectory site look for its files in example.com/blog?
For further information, my root host is a Symfony site (not a wordpress), and I'm running a AWS EC2 ubuntu server.

You need to enable the apache2 mod_rewrite module. You can do it by running the following command:
sudo a2enmod rewrite

Related

Updating httpd.conf not working for permalinks

I am unable to set permalinks to end with post names. I receive a 404 error. The closest I got is to set custom permalink to:
/index.php/%postname%
But this causes 'index.php' to show up in the URL. I also updated my httpd.conf to set the root dir to:
AllowOverride All
But it still does not work. My wordpress is hosted on AWS EC2 linux AMI.
Activate the mod_rewrite module with
sudo a2enmod rewrite
and restart the apache
sudo service apache2 restart
To use mod_rewrite from within .htaccess files (which is a very common use case), edit the default VirtualHost with
sudo nano /etc/apache2/sites-available/000-default.conf
Below “DocumentRoot /var/www/html” add the following lines:
<Directory “/var/www/html”>
AllowOverride All
</Directory>
Restart the server again:
sudo service apache2 restart
EDIT:
Found my htaccess file was missing. So followed the steps listed here :
https://wordpress.org/support/article/using-permalinks/#wheres-my-htaccess-file
Created htaccess in wp root which, on my server, was /var/www/html.
Added the required rewrite rules provided in the link above.
Set chmod on htaccess to 775
Set chown on htaccess to apache:apache
Restarted httpd service
Postname permalink now works!

WAMP server - How to host more Wordpress websites?

I want to host more WP sites on WAMP server at the same time.
How to do that?
I would recommend you to download XAMPP. Basically WordPress is built on PHP and XAMPP has support for PHP. First download it and configure it then go to the installation directory and go to xampp>htdocs> then make a new folder 'project' and then unzip the WordPress files in that folder. After that read the manual provided ant xampp's website and follow it. Basically you can build your WordPress website on Xampp.
EDIT
Oh sorry for not understanding the question properly.
Now do this.
step 1: host the different websites in htdocs/ folder in xampp. You can host many websites as you want.
step 2: Then go to xampp/apache/conf/httpd.conf and uncomment the line which says this. For uncomment delete the '#' character.
Include conf/extra/httpd-vhosts.conf
step 3: Go to xampp/apache/conf/extra/httpd-vhosts.conf
Create the setup like this
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/xampp"
ServerName xampp
#ServerAlias
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site1"
ServerName site1.com
ServerAlias www.site1.com
</VirtualHost>
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/site2"
ServerName site2.com
ServerAlias www.site2.com
</VirtualHost>
YES. You can make sub-folders in www and make different WP websites. But be careful with the database configuration. Installing WP does nothing but coping some PHP files to that specific folder. All the data is saved in database and inside that specific folder itself (E.g. config php files).

Error 503 Service unavailable

just started with Symfony2 and already have a problem that i can not solve.
Installed the Symfony2 demo app on a VPS with debian. but trying to open it give me a "503 Service unavailable".
I used 'symfony demo' to install to /var/www/symfony_demo/
then added a symdemo.conf file to /etc/apache2/sites-available that look like this:
NameVirtualHost XX.XXX.XX.XXX
<VirtualHost XX.XXX.XX.XXX>
ServerName symblog.dev
DocumentRoot "/var/www/symfony_demo/web"
DirectoryIndex app.php
<Directory "/var/www/symfony_demo/web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
XX.XXX.XX.XXX = public server IP
and activated it with a2ensite symdemo.conf
I thought that would work, but opening the IP give me the error message.
and trying to open app_dev.php give me not allowed to access this file
Could someone please give me a tip?
Nevermind. Looks like i fixed it. Following this tutorial: http://intelligentbee.com/blog/2013/08/07/symfony2-jobeet-day-1-starting-up-the-project/
just activate mod_rewrite with a2enmod rewrite and restart apache. that's it.

How to prevent WordPress setup in 'blog' subdomain, redirecting to 'www' when trying to finish Installation

I have a main site http://www.example.com that's written in another language (Ruby/Rails). I want a wordpress blog installed in http://blog.example.com. I have control over the server and DNS.
I have created the necessary CNAME record for the 'blog' subdomain. But after setting up apache and restarting it, when I visit http://blog.example.com, for the final installation steps, I'm redirected to http://www.example.com/wp-admin/install.php.
Also now when I try to visit the main site http://www.example.com, I'm being redirected to the above wordpress install page.
How can I make it work like this: the blog should only reside in blog.example.com path, and the main site should be accessible via http://www.example.com.
Removing the www subdomain is not an option as it's been like that for awhile for the main site. It might be ok, if somehow a redirect can be setup from www to non-www url, though I'm not aware how to set it up.
Please suggest.
Here's the main site's apache conf:
<VirtualHost *:80>
ProxyPreserveHost On
ServerAdmin webmaster#localhost
ServerName http://www.example.com
ServerAlias example.com
DocumentRoot /home/apps/example/current/public
<Directory /home/apps/example/current/public>
AllowOverride all
Options -MultiViews
</Directory>
#RewriteEngine On
#Redirect / http://example.com/
</VirtualHost>
Here's the apache conf for the wordpress under 'blog' subdomain:
<VirtualHost *:80>
ServerName blog.example.com
ServerAlias blog.example.com
ServerAdmin webmaster#localhost
DocumentRoot /home/apps/example_blog/wordpress_blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/apps/example_blog/wordpress_blog>
AllowOverride All
</Directory>
</VirtualHost>
WordPress has domain references in the database and the code which will throw your permalinks off and cause bad redirects. These renegade URLs should appear as 404's on your root domain (example.com). If not I'd double check the root domain with the sub domain removed from the vhosts.
I don't see any issues with your current vhost configuration. I would also try testing the domains in isolation if you suspect its vhost related. I suspect its a WordPress site url issue.
Assuming the database records are incorrect.
Log into phpMyAdmin or other database manager.
Select your WP database.
Go into the wp_options table (wp_ prefix may be different).
Look for the record's with option name = "siteurl" & "home".
Edit these records to reflect your new domain name.
Here's the WordPress documentation on how to switch a sites urls schema.
Document
Your problem is likely deep in various DB references throughout your WP project. I've run into this problem deploying WP before. You'll need to edit the DB directly to fix the issues.
Export your WordPress DB with phpMyAdmin or SequelPro (something that gets you a clean .sql file)
Use a text editor like Sublime or Atom, search for "www.example.com" and replace all with "blog.example.com" then save.
Upload DB to prod location and you should see these errors go away.
This should not happen if your virtual host is configured correctly
but still as your tables are not created so you can only do one try with this step :
you can add in your wp-config.php file the following parameter
define('wp_site_domain', 'blog.example.com');
This will force the wordpress to follow blog.example.com

Hosting multiple domains in Apache2 - how?

Although I’ve found related articles on stackoverflow, I have seen various suggestions which I’ve tried out but I still experience problems, so that’s the reason why I’m posting this.
I have a question which involves DNS, Debian, Apache2 and Wordpress. I’ve been struggling with this for some time now and haven’t been able to solve it. My current conclusion is that 2there is something with my dns and apache virtual host definitions”, but, as I said I’m far from sure.
This is what my config looks like:
two domains which I “own” hosted by moniker.com - let’s call them domaina and domainb
a hosted vps with Debian, apache2 and wordpress. The vps has ip x.y.z.t
each domain has three ‘A’ records defined: ‘*’, ‘#’ and ‘www’
URL rewrite enabled (a2enmod rewrite)
Wordpress installed and links created to the wordpress directory for both document directories specified in the virtualhost directives below
Both ‘domaina’ and ‘domainb’ point to my vps and this is working ok. However, what I’ve been unable to solve is to have the vps handle “multiple virtual hosts”. I thought I would be able to handle this by using virtual hosts in Apache. For that purpose I’ve defined two sites under /etc/apache2/sites-available which looks like this:
(file: /etc/apache2/sites-available/domaina.com)
<VirtualHost x.y.z.t:80>
ServerName domaina.com
ServerAdmin me#domaina.com
DocumentRoot /var/www/domaina.com
DirectoryIndex index.php
<Directory /var/www/domaina.com/>
AllowOverride all
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
(file: /etc/apache2/sites-available/domainb.com)
<VirtualHost x.y.z.t:80>
ServerName domainb.com
ServerAdmin me#domainab.com
DocumentRoot /var/www/domainb.com
DirectoryIndex index.php
<Directory /var/www/domainb.com/>
AllowOverride all
Order deny,allow
Allow from all
</Directory>
</VirtualHost>
Now, when I try to address the sites above from a web-browser I end up at the default apache directory with the index.html file rendered in the browser instead of arriving at the two different wordpress configurations. Obviously there’s something wrong with my thinking around “VirtualHosts” and/or DNS-configurations…
I forgot to mention that I've made loads of /etc/unit.d/apache2 restarts... Sorry...
Frankly speaking I’m lost here and any help on this would be very much appreciated.
Cheers
If you did restart apache and its still not working please respond, as I have experienced similar issues with Apache, especially when getting the virtual host to work. I realise your running on Debian which is different to WAMP, but this is what I do when opening a new virtual host.
First I add the domain to the windows system 32 drivers etc hosts file, it allows for intranet
127.0.0.1 domainname and this stops the url from looking to the web.
Then I have to add the corret directories to the www/your folder.
Just inside the root folder there ought to be a directory called vhosts,
I had to make totaly empty instances of the conf files with just the filename of the virtual hosts inside it so that the changes you made to the httpd-vhosts.conf works.
So what you will need to do is find the wamp/bin/apache/Apache2.2.21/conf/extra/httpd-vhosts makes sure that you have the one from the conf/axtra and not conf/orginal.
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/**name of the folder**"
ServerName **as_inserted_in_hosts**
<directory "c:/wamp/www//**name of the folder**">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</directory>
</VirtualHost>
Save. Apache stop all services, I also have to restart the service running the intranet in windows to update the changes to the hosts file and then restart apache.
This is what I have to do so that when I open localhost from Apache it allows me to see the links appear under virtual hosts as well as the directories appearing under your projects.
Have a look at this tutorial... Explains how to set up virtual hosts
Do you have a NameVirtualHost directive in your apache2.conf anywhere? You'll need that to enable virtual hosting. It can go in apache2.conf or any file included by apache2.conf. On my server I've got it in ports.conf.
NameVirtualHost *:80
See http://httpd.apache.org/docs/2.2/vhosts/name-based.html#using

Resources