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

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.

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!

How to trace site route in apache

UBUNTU + APACHE
I am running a few wordpress sites on one server (that I inherited) using VirtualHosts, and I need to configure ssl certificates for each site.
Before starting to set up certificates for each site, I tried entering each domain with the https prefix on the browser and noticed it redirects me to a site (with an invalid certificate) that is supposed to be disabled and does even show up when I run
apachectl -t -D DUMP_VHOSTS
I tried configuring the virtualhost entries for one of the sites with the valid certificate and it still goes to same old site. How can I completely disable and remove that site and the invalid certificate? I cannot find it anywhere on the server.
My Virtual host looks something like this
NameVirtualHost *:443
<VirtualHost *:443>
ServerName www.yoursite.com
DocumentRoot /var/www/site
SSLEngine on
SSLCertificateFile /path/to/www_yoursite_com.crt
SSLCertificateKeyFile /path/to/www_yoursite_com.key
SSLCertificateChainFile /path/to/DigiCertCA.crt
</VirtualHost>
If you want to disable a virtual host configuration you just need to do:
sudo a2dissite sitename
sudo systemctl restart apache2
and the issue should be resolved

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 Apache Vhost Example

I'm trying to install wordpress but i'm confused as to how the Apache Vhost should look.
Ideally i'm after a vhost setup that adds additional security (make sure referrer is correct when doing comments)
I cant seem to find this anywhere (i'm not the best searcher)
It's pretty straight forward
from http://ubuntuforums.org/showthread.php?t=794248:
create a new site(vhost) configuration at /etc/apache2/sites-available/ (replace with whatever you want besides default) something like this should work
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot /path/to/new/site
ServerName www.example.com
</VirtualHost>
enable your new site
sudo a2ensite <site name>
restart apache to listen on your new port and load your new site
sudo /etc/init.d/apache2 restart
This guide for vhosts using mamp will help you with the setup! This saved me a lot of time.

Resources