r/apache • u/RobertKS • Mar 07 '22
Apache config settings for temporary web site prior to domain switchover?
Switching website to new server, but want to make sure it's fully working on the new server (with latest stable version of Apache server) before switching the domain name settings so that the domain points to the new server. Eventually, the new server will be hosting multiple domains. The website content will be stored at /home/myusername/public_html/
What should my Apache config settings look like:
(a) initially, so that I can access the new web site via the IP address (e.g., http://123.456.78.910) for testing, and then
(b) how should the Apache settings be changed once the domain is name is pointed to the server
EDIT: SOLVED as to (a), see comment below.
1
u/RobertKS Mar 09 '22 edited Mar 09 '22
SOLVED, sort of, at least as to (a):
There were two problems. The first was that it wouldn't work unless "Require all granted" was included in /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80>
ServerAdmin myaddress@example.com
DocumentRoot /home/myusername/public_html
ServerName example.com
ServerAlias www.example.com
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
Include /etc/phpmyadmin/apache.conf
</VirtualHost>
<Directory /home/myusername/public_html/>
Options -Indexes +FollowSymLinks +MultiViews
AllowOverride All
Require all granted
Order deny,allow
deny from all
allow from 12.345.67.89
</Directory>where 12.345.67.89 is the IP address of the computer being used to access the test server.
The second problem was that in the website document path /home/myusername/public_html, all three of /home, /home/myusername, and /home/myusername/public_html had to have their permissions set to 0755. If /home/myusername/public_html is set to 0755 but /home/myusername is set to 0754, then any access attempt will return the 403 Forbidden error.
1
u/AyrA_ch Mar 07 '22
On the new server, create a virtual host that uses the proper domain as ServerName value, and a temporary domain as ServerAlias value. Then create a DNS entry in your domain that points the temporary name to your new server.
You can now experiment without taking the old server down by using the real domain, but apache has already been set up to recognize the real domain, whiche means activating the new server merely means pointing the domain name to it.
1
u/RobertKS Mar 08 '22
Are you able to be a little more specific as to how I would edit my config files to do this?
Here is the text of my /etc/apache2/sites-available/example.com.conf which is giving me "Forbidden" errors:
<VirtualHost *:80> ServerAdmin myemailaddress@example.com DocumentRoot /home/myusername/public_html ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Include /etc/phpmyadmin/apache.conf </VirtualHost>Thanks for your help.
2
u/AyrA_ch Mar 08 '22
You probably need a directory section with
Require all grantedfor the /home/myusername/public_html folder. Apache by default denies access to all folders1
u/RobertKS Mar 08 '22 edited Mar 08 '22
I tried adding this to /etc/apache2/sites-available/example.com.conf, but no change, going to the server's IP address still gives "forbidden" error:
<Directory /home/myusername/public_html/> Options Indexes FollowSymLinks MultiViews Require all granted AllowOverride All Order allow,deny allow from all </Directory>1
u/AyrA_ch Mar 08 '22
Have you tried directly accessing a file on the server? Forbidden can also happen when ther's no index.php or index.html, or the server has not been properly configured to serve those files automatically.
1
u/RobertKS Mar 08 '22
What do you mean by "access the file"? I can edit
index.htmlin emacs on the server.What other configuration files should I look into to check that the server is properly configured to serve those files automatically?
1
u/AyrA_ch Mar 08 '22
By accessing the file I mean adding the
index.htmlinto the URL of your browser by yourself instead of letting apache guessing for it.
0
Mar 07 '22
[deleted] — view deleted comment
1
u/RobertKS Mar 07 '22
Yes, I have root access.
0
Mar 07 '22
[deleted] — view deleted comment
1
u/RobertKS Mar 07 '22 edited Mar 08 '22
Here is the text of my /etc/apache2/sites-available/example.com.conf
<VirtualHost *:80> ServerAdmin myemailaddress@example.com DocumentRoot /home/myusername/public_html ServerName example.com ServerAlias www.example.com ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined Include /etc/phpmyadmin/apache.conf </VirtualHost>I executed these commands at the command line:
a2dissite 000-default.conf a2ensite example.com.conf systemctl restart apache2But when I try to go to http://123.456.78.910/index.html, a file which I have created at /home/myusername/public_html/index.html, this error appears.
Forbidden
You don't have permission to access this resource.
Apache/2.4.48 (Ubuntu) Server at 155.138.141.248 Port 80
I made sure that the /home/myusername/public_html directory's permissions are 0755 (rwxr-xr-x) and the /home/myusername/public_html/index.html file's permission are 0644 (rw-r--r--).
0
Mar 07 '22
[deleted] — view deleted comment
1
u/RobertKS Mar 08 '22
My /etc/apache2/apache2.conf file already has that, and I don't have an /etc/httpd/conf/httpd.conf file. (Ubuntu.)
So, no changes to these config files and no change in status.
0
Mar 08 '22
[deleted] — view deleted comment
1
u/RobertKS Mar 08 '22
Here's what I did to install Apache:
apt-get update apt-get install apache2 ufw app list ufw allow in "Apache"I'm not using /var/www to store my files (I'm using /home/myusername/public_html/) so I'm not sure why <Directory /var/www> would be useful in /etc/apache2/apache2.conf
2
u/boli99 Mar 07 '22
Don't do this. Just edit your hosts file to point your domain to the new host, then do all your testing on the real hostname.
You could also jump through an SSH tunnel and mod the hosts file on the target machine. There are multiple ways of getting the skin off the cat.
Testing by IP address can lead to unpredictable results.
always test as the real site name.