Updating httpd.conf not working for permalinks - wordpress

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!

Related

Httpd only allows to access files that are directly created in the /var/www/html folder

I'm using Httpd for the first time and the final goal is to setup a wordpress instance on a local RHEL server (that has no external internet access).
So I installed httpd via yum and used touch hello.html inside the /var/www/html folder which worked fine and the file is available via browser. Now I started to move a html file from another computer via winScp to the root directory of the server and moved it with mv to the folder. I did also use chmod to set the correct access rights, but it didn't work.
How can I setup the server to serve these files? Atm I receive an 403 Forbidden error, so I assume I have to do something within the httpd config?
Would be very thankful for any help to get me onboard!
It's good practice to use a VirtualHost, and put the configuration in sites-enabled directory. You can of course just edit your httpd.conf and put the configuration in there. It's just not as flexible for administration.
Edit /etc/httpd/conf/httpd.conf using sudo.
Add IncludeOptional sites-enabled/*.conf at end of httpd.conf. Save and exit.
sudo mkdir /etc/httpd/sites-enabled /etc/httpd/sites-available
Using sudo, edit /etc/httpd/sites-available/mysite.conf and add the followingVirtualHosts` block:
<VirtualHost *:80>
DocumentRoot /var/www/html
ServerName mysite.domain
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now create the link for the config to the sites-enabled directory
sudo ln -s /etc/httpd/sites-available/mysite.conf /etc/http/sites-enabled
To restart Apache after completing the above, do
sudo systemctl restart httpd
The alternative is to add the VirtualHost block directly in httpd.conf, then re-start Apache.

wordpress in apache subdirectory get 404

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

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.

wordpress forbidden 403 error

After installing wordpress and following all the steps when I am go to http://localhost, I am gettong 403 Forbidden error.
How can I resolve this?
Ubuntu 14.04 is my OS.
In normal case changing permission and updating .htaccess should fix this issue, but in your case it is not working, so try to create a host entry and see if it is working. Else it will be related to the server configuration.
a. Create a new folder inside /var/www (example: wordpress - with proper permissions)
b. Copy all files from /var/www/html folder to /var/www/wordpress
c. Create a virtual host entry: sudo gedit /etc/apache2/sites-available/wordpress.conf
Add following contents:
<VirtualHost *:80>
ServerName wordpress
DocumentRoot /var/www/wordpress
<Directory /var/www/wordpress>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
allow from all
</Directory>
</VirtualHost>
d. Update hosts: sudo gedit /etc/hosts
Add new line: 127.0.1.1 wordpress
e. Activate new website: sudo a2ensite wordpress.conf
d. Restart apache: sudo service apache2 restart
Access http://wordpress from your web browser.

wordpress permalinks not working - htaccess seems ok but getting 404 error on pages

I updated the permalink structure to /%postname%/ and this updated my .htaccess with:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
But I still get 404 errors on the pages. Are there any other settings that I need to change?
Edit: if it helps the apache log seems to be looking directly in the permalinked folder. I.e.:
[Wed Oct 16 11:12:32 2013] [error] [client xx.xx.xx.xxx] File does not exist: /var/www/exampledomain/news, referer: http://exampledomain.com/
For other people landing on this page -
Another issue could be (If you are using Apache as your web server) is your httpd.conf or your sites-available/sitename.conf file needs editing.
Your web directory will need to allow the .htaccess file to override it's settings.
look for your web dir in the file - it will be in the bulk of the conf file or segregated into a VirtualHost section.
<Directory /path/to/site>
#add the following setting to allow .htaccess in your web dir to work
AllowOverride FileInfo
#other settings ---
</Directory>
This will allow you to set up WordPress URLs however you want, within WordPress.
***Edited - Thank You nietonfir For update. Use the least amount of privilege at first. If this doesn't work then replace AllowOverride FileInfo with AllowOverride All
There can be multiple things preventing the rewrite rule from working. My ubuntu server needed 3 things changed to get permalinks working.
In newer versions of apache2, you need to enable the module:
sudo a2enmod rewrite
sudo service apache2 restart
You may also need to modify the apache2.conf file.
sudo nano /etc/apache2/apache2.conf
Change your web directory override rule to AllowOverride All.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
After that, restart the service again.
The .htaccess file in the WordPress install directory needs to be owned or readable/modifiable by the webserver.
This can be accomplished by changing owner to www-data (usually the webserver user), or changing permissions.
sudo chown www-data /var/www/wordpress-install/.htaccess
OR
sudo chmod 664 /var/www/wordpress-install/.htaccess
Login to your Wordpress admin backend and save the permalink settings, and they should hopefully be working.
This is now solved. I hadn't enabled mod_rewrite. So I did this:
$ sudo a2enmod rewrite
Enabling module rewrite.
To activate the new configuration, you need to run:
service apache2 restart
$ service apache2 restart
* Restarting web server apache2
You would want to tell apache to follow your .htaccess file. You can do this by editing the apache.conf file
$sudo nano /etc/apache2/apache.conf
Scroll down to the line
By default it will be:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
change the value of AllowOverride to All so now it becomes:
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Press ctrl+x and press y to save the configuration file. In order to make this changes to server first enable the mod_rewrite by.
$ sudo a2enmod rewrite
And then restart the server
$ sudo service apache2 restart
Done!
Source: https://www.wst.space/riddling-with-wordpress-permalink-setup-issues/
use below .htaccess code, just put your project name (which is in www directory) in below code
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /project_name/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /project_name/index.php [L]
</IfModule>
# END WordPress
Thanks
I was facing with the same problem and had one more thing to look for.
Here is what you need to do for wordpress permalinks work properly:
Make sure you have the proper permission modes for files and folders in your wordpress directory:
sudo find . -type f -exec chmod 644 {} +
sudo find . -type d -exec chmod 755 {} +
For permalink structure make sure mode_rewrite is enabled in apache:
sudo a2enmod rewrite
sudo service apache2 restart
One more thing to check if this describes your problem:
htaccess and mod_rewrite are set up correctly
404 error on some permalinks but not others
Ensure that there are no existing .php files or directories in the same folder as your Wordpress install with names matching a Wordpress permalink.
For example, if you have the following Wordpress page permalinks:
example.com/name_one/
example.com/name_two/
and the directory containing your Wordpress install includes the following file:
name_one.php
then this will be the result:
http://example.com/name_two/ – this permalink will work
http://example.com/name_one/ – this permalink will NOT work
More importantly, the second URL will give a 404 instead of running name_one.php, meaning this problem is hard to diagnose, as it can give the same symptoms as an incorrectly written .htaccess file.
If you are setting up a new or cloned site on ubuntu, remember to symlink the site configuration file e.g. /etc/apache2/sites-available/your-file.conf to the /etc/apache2/sites-enabled folder so apache loads it.
Just run: sudo a2ensite your-file.conf, then sudo service apache2 reload.
sudo a2dissite your-file.conf to remove symlink i.e. disable config.
Users of WAMP (Windows): Some versions of WAMP (all versions?) do not enable mod_rewrite or permit following SymLinks by default. To enable the required functionality navigate to the apache/conf/httpd.conf file, open with a text editor and uncomment the line LoadModule rewrite_module modules/mod_rewrite.so (i.e., delete the hash/pound sign at the front of the line). Then further down in the same file there is a section that starts with the line "Options FollowSymlinks". Change the second line in that section from "AllowOverride none" to AllowOverride all. Save edited httpd.conf and restart all WAMP modules. Your permalinks should now work.
For more details, Fixing Permalink Problems
Yet another possibility: I just updated my macOS which always screws up the Apache config file. Among other things, I also had to re-enable the mod_rewrite module. Find the line that says,
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
And remove the hash so it says,
LoadModule rewrite_module libexec/apache2/mod_rewrite.so
If you are using Apache, double check no errors in Directory in VirtualHost, Apache wont warn you if you input an incorrect directory:
<Directory /var/www/html/site/wordpress>
Options FollowSymLinks
AllowOverride Limit Options FileInfo
DirectoryIndex index.php
Require all granted
</Directory>
<Directory /var/www/html/site/wordpress/wp-content>
Options FollowSymLinks
Require all granted
</Directory>

Resources