mod_rewrite, links, virtual hosts - php

It seems that I'll never get along with mod_rewrite...
I'm in the typical scenario:
homepage_one.tld/impressum.php --> domain.tld?content=impressum
homepage_one.tld/projects.php --> domain.tld?content=projects
homepage_one.tld/projects/canvas.php --> domain.tld?content=projects&project=canvas
I'm developing offline, using Ubuntu Server Edition on an VMware. That means, the local domain for my homepage_one to test is: _http:///localhost:2180/homepage_one/index.php
Later it will be _http://homepage_one.tld.
<Directory /var/www/homepage_one>
RewriteEngine on
RewriteRule ^([^/]*)\.php$ index.php?content=$1 [QSA,L]
RewriteRule ^projects/(.*)\.php$ index.php?content=projects&project=$1 [QSA,L]
</Directory>
All css / image links are *broken * now, when I'm asking for the url: _http://localhost:2180/homepage_one/projects/canvas.php
(It looks for "homepage_one/projects/canvas/style.css" instead of "homepage_one/style.css"
most answers at stackoverflow concerning this issue are: use absolute links. I tried it, but to test it offline, my absolute link would be /homepage_one/style.css and i would have to change ALL links, once I publish the website. I also tried to use the html-base tag. But this didn't work eigther.... any ideas?

Johannes this is really an answer to your answer :-) The conventional way to list entries is IP name name, e.g.
127.0.0.1 localhost mysite.vm subdomain.mysite.vm blog.mysite.vm
or whatever.
I also find port forwarding a total pain. I always use a bridged or host-only network. My Windows/WMware skills are a bit rusty as I gave up on both about 5 years ago, but this VMware page describes how to do it if you are using VMware Workstation. You can do the same with a VMware appliance but you have to start tweaking the VMX file. As I said in my blog article, which I recommend that you read, I find just easier with VBox.
In a bridged network, if you host NIC's MAC address is 00:23:18:dd:88:88 and your VM's is 08:00:27:FE:FE:FE then the VMware network driver programs the host NIC to respond to both but then passes the 08:00:27:FE:FE:FE packets onto the VM's virtual NIC. Hence the VM participates on the network just like any other PC and looks like a PC/server to any other devices. I run all my home devices on a 192.168.1.0/24 private address space, so I just statically allocate IPs for my VMs in 192.168.1.192/26.
The great advantage of bridged and host-only networks is that you can use the default port 80, and that if you want you can also (temporarily) override your DNS entry for your myprodsite.com to point to your VM, so that any absolute coded http://myprodsite.com/ URIs will then point back to the VM during testing.
Hope this helps :-)

Solution (thanks to #TerryE):
Edit C:\Windows\System32\drivers\etc resp. /etc/hosts (linux)
127.0.0.1 my_homepage1.vm
127.0.0.1 my_homepage2.vm
in my case, using port forwarding to different VM's, I can reach them, as followed:
my_homepage1.vm:2180 --> VM1
my_homepage1.vm:2280 --> VM2
now I can just use VirtualHosts, as on my production Server, and go with absolute links.

Related

Apache 2 start Wordpress instead of standard file

how to startup to wordpress instead of standard apache 2 file
I'm a complete noob when it comes to webdevelopment. I decided to find out how it worked a bit.
I created an apache 2 server on my raspberry pi model 3b plus. I installed a mysql database, and installed wordpress under /var/www/html/wordpress. I did it all according to this tutorial online. Only gave my database a different name and so on.
The only thing missing in the tutorial is how to now let my ipadress point to wordpress instead of index.html. My plan is to host a very simple wordpress site on my raspberry pi. And let my domainname point to the ip of the raspberry through a portforward on my router. So I need to start wordpress on the raspberry instead of the standard apache 2 files. Just to clarify extra: when I enter the Rpi adress into my browser now, it directs me to the "it works!" index.html file from apache2. I want it to go to the wordpress site I created when I enter the Rpi's ip adress. So I can go to my DNS host and let the domain name I own point to the outside IP adress of my router with a port, which I then redirect to the pi. I.E. host my own little website for fun.
I looked for the answer on the internet but couldn't really find an answer that explained this. The whole server thing, and hosting your own websites is still a bit vaque to me. As I said, never worked with it before. Any help will be appriciated.
There's a small mistake in the tutorial you followed.
To get things to work so hitting http://203.0.113.114/ where 203.0.113.114 is your machine's local IP address, you must install WordPress in your web server's root directory. The tutorial suggests you install it so you can hit http://203.0.113.114/wordpress to get it. That's not what you want.
The tutorial says to do this.
cp -R wordpress /var/www/html/
Instead you want to do this.
cp -R wordpress/* /var/www/html
That puts WordPress's files in /var/www/html/, not /var/www/html/wordpress/. After you do this, you should be able to say ls -al /var/www/html and see a bunch of files, including among others index.php.
Once you've done that, do the permission-changing stuff in your tutorial again. Then use your web browser to hit
https://10.11.12.13/
and you should get WordPress's setup wizard on your browser. Here are WordPress's own instructions.
Here's the thing to keep in mind: apache exposes a subset of your machine's file system to web browsers. That subset is rooted at the directory /var/www/html/. And also, when you have php installed, apache interprets files like foobar.php not as text, but as php programs. It runs them instead of just sending them to the browser. It's worth your trouble to wrap your brain around these concepts; they're the heart of web server technology.
Again, use your own IP address in place of 203.0.113.114.
You can create virtual host and access site from subdomain for example.
create host file
/etc/apache2/sites-available/wordpress.com.conf
enter
<VirtualHost *:80>
DocumentRoot "/var/www/html/wordpress/"
ServerName wp.localhost
</VirtualHost>
Then enable host with command sudo a2ensite wordpress.com
Then you should be able to access wordpress on subdomain wp.localhost / wp.{yourserveraddress}
Solved
I found the answer with both of the answers from O.jones and Koxo.
I created a new .conf file in /etc/apache2/sites-available called something.com.conf (just to test).
entered this bit of code in there:
<VirtualHost *:80>
DocumentRoot "/var/www/html/wordpress/"
ServerName something.com
</VirtualHost>
After that I did a2dissite 000-default.conf to turn the "old" config off. This is the config that directs you to index.html. Then I did a2ensite something.com which enables the website on the apache server. After that I did: sudo service apache2 restart to restart the service and everything worked.
Thank you O.Jones and Koxo for the help!

WAMP is not responding to external requests

Installed WAMPServer
Version : 3.0.4
OS type : 64 bit
Apache : 2.4.18
PHP : 5.6.19 / 7.0.4 (5.6.19 checked)
MySQL : 5.7.11
I've tried to look at the older overflow questions and answers and tried to do along as they said, however, I still do not have any connection to the wampserver.
What I've done to test
Use localhost on the host laptop to check if wampserver is operational
[SUCCESS]
Use my IP on host to check if wampserver is operational [SUCCESS]
Use my IP on other devices on the network in attempt to access a php file of the server in a directory. [FAILED]
Use other devices to on the network to ping my host [Request timed out x4]
Use tracert command as an alternative to 4 [Request timed out]
What I've done to the server
Modification to httpd.conf
Listen 12.34.56.78:80//commented
Listen 0.0.0.0:80
Listen [::0]:80
Dynamic Shared Object (DSO) Support//commented
miscellaneous for LOAD MODULE
ServerName localhost:80
Deny access to the entirety of your server's filesystem. You must
explicitly permit access to web content directories in other
blocks below.
Directory//This directory tag has no reference to server
AllowOverride All
Require all granted
Directory
DocumentRoot "E:/Server/wamp64/www"
Directory "E:/Server/wamp64/www/"
Options Indexes FollowSymLinks
AllowOverride All
# onlineoffline tag - don't remove
Require all granted
Directory
What I've done to the host laptop
Fresh installation of WAMP
Backup original httpd.conf
Edited httpd.conf (Refer above)
[FAILED]Added rule for port 80 to enable all - Deleted
Disable all rules for inbound for port 80
Look for rules in outbound for port 80 [NONE]
All of the steps I've described does not work at all. Has no experience in firewall configuration and WAMP configuration. And no virtual hosts except localhost
P/S: The example link I tried testing was 1.1.1.1/testPHP/testPHP.php. The host is Win10 while the device on the similar network tested was XP. Any advice is greatly appreciated.
The apache configuration seems correct.
Check this if you're using Wifi on server or client
Check if the router/AP has enabled something called Wifi Isolation, or Client Isolation.
I looked on a similar router like yours and there it's one option called Client Isolation on the Wireless Basic setup of your router. Uncheck it, save and retry.
Check this on the Windows firewall
Press on your keyboard WindowsKey+R, write control.exe. Press enter
Double click on Windows Firewall
On the left vertical bar select Advanced Settings
Click Inbound Rules
On the right pane click New Rule...
Select Port and click Next button
On the top leave TCP option selected. And below select Specific local ports and write there 80 or the port your apache uses. Looking to your Listen line on the apache config you should write here 80. Press Next
Leave selected Allow the connection and press Next.
Select the profiles of the Firewall you want to use for this rule. If you doubt select all. Press Next
Set a name for the rule, and press Finish
Try it another time ;-)
Found the problem. Win 10 apparently had this setting I have had forgotten about - Make this PC discoverable (OFF)
I turned it off in the heydays of using Win 10 because of privacy concerns. Now it can be accessed. The next step is to figure out the forbidden access.
Edit
The culprit for this post is the Windows 10 OS Settings. In order for all the settings to work (Assuming the person has done all the tinkering with httpd.conf and firewall and/or router), the PC hosting the server must be checked whether is the PC discoverable in the network settings.
How to make sure it is discovered
Open Network Settings by left clicking the network icon on your taskbar (either lan or WiFi) then click Network Settings right above the bottom most icons.
Select Advanced Settings
Under the item Make this PC discoverable, there will be a switch button. Make sure the button is turned ON otherwise, left click on that particular button.

WAMP Server 3 - Lan Web Server

Good day, I have Windows Server 2012 R2, I installed WAMP Server 3, on wamp settings I enabled the following
- Virtual host sub-menu
- Menu item: Online/Offline
when installing wamp a "my-site" folder was created, i created a index.html file in there with a
then i created a vhost using the GUI (localhost)
and the httpd-vhosts.conf looks like this
ServerName my-site.dev
DocumentRoot c:/wamp64/www/my-site
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require local
after this, i clicked on Put Online and disabled my windows firewall
from a different computer on the network i am trying to access to (http://29.8.14.2/my-site.dev) (IP of the windows server / folder) but i get the message
"Forbidden
You don't have permission to access /my-site.dev on this server.
Apache/2.4.17 (Win64) PHP/5.6.16 Server at 29.8.14.2 Port 80"
could you please let me know what I am doing incorrectly?
thank you.
I know I answered this over on the WAMPServer forum but I thought it may be relevant to have an answer here as well.
First you cannot use publically addressable IP Addresses for a local network. So your 29.8.14.xx address range is probably causing some or all or these problems.
There are 3 address ranges provided for Private ip address ranges for Small, Medium and Large Internal networks and they are
RFC1918 name IP address range number of addresses
24-bit block 10.0.0.0 - 10.255.255.255 16,777,216
20-bit block 172.16.0.0 - 172.31.255.255 1,048,576
16-bit block 192.168.0.0 - 192.168.255.255 65,536
Pick one that suites your clients network size, current and potential.
Your next problem will be how to get all the PC's in this network to know where mysite.dev is in the network. If its only a few PC's then you can edit the HOSTS file on each PC and add an entry like this to each, I am assuming you go for the 16-bit block address range.
192.168.1.2 mysite.dev
just like you did to the PC running WAMPServer, but pointing the domain name to the IP Address of the PC running WAMPServer and your site.
Alternatively, if your client has a local DNS Server and MANY PC's, then it would be much easier to add your site to his DNS Server and then every PC should know where to find mysite.dev

View a wordpress site installed on localhost from LAN [duplicate]

This question already has answers here:
How do I connect to this localhost from another computer on the same network?
(8 answers)
Accessing localhost (xampp) from another computer over LAN network - how to?
(25 answers)
Closed 4 years ago.
I have installed xampp on localhost,and have installed wordpress on it(using port 8080),and have created a website on it.
I need to see that localhost wordpress site from another computer before loading it to a domain.I tried ngrok,but using that i could only get to the XAMPP welcome page.
How can I reach the wordpress site.
P.S. I access the wordpress site on my pc as localhost:8080/wordpress-trunk
Please help
You can access your local site from local network. To do that you need to assign ip to your local server. You can check these links link1 link2
To actually visit you site from internet you'll need to buy services(ip and domain name ) from your isp. Your isp will have to assign the in the dns server they are using. That is you'll have to make your own web server.
If its just for testing purpose best option is to use free hosts
Take a look on your apache configuration, looks like it allows requests only from localhost. Your config should looks like
<Directory /APP>
Allow from all
</Directory>
while now you have something like
<Directory /APP>
Allow from 127.0.0.0/8
</Directory>
* EDITED *
Accordin description, your task is to access your web site from another local computer, rather then from internet. As I can see, you can access this computer (and you can see XAMPP welcome page), so you don't need to follow Tousif Osman's answer, the problem is in your settings.
You can achieve what you want using your public IP adress, even if it's dynamic. First, you need to config a port forwarding in your router. To do this, enter in your router settings, go to port forwarding and there add the LOCAL IP adress from your XAMPP computer. Make sure to select type TCP and RANGE 80-80, because port 80 it's the default port for apache. Make sure you don't use Skype, which also use port 80.
After you did that, reset your router so the changes apply. Now, go to https-vhost.conf file and add something like this
<VirtualHost *:80>
#ServerAdmin webmaster#dummy-host.example.com
DocumentRoot "path to your wordpress directory"
ServerName your public IP
ServerAlias your public IP
</VirtualHost>
After that, go to hosts windows file (System32/Drivers/etc/) and add your IP twice. So, it should look something like this:
localhost localhost
YOUR PUBLIC IP YOUR PUBLIC IP
Don't forget to replace YOUR PUBLIC IP and path to your wordpress directory. Now, restart your apache service. I recommend you to perform a clean wordpress instalation in your wordpress directory and use YOUR PUBLIC IP for the website URL.
Briefly, this is all about it. I'm here if you have questions or problems!

Replace localhost to domain name

I am working on localhost right now. Suppose I have a route now at http://localhost:8000/info. Now I have a domain named www.helloyou.com.
In my project routing the routing for this info.php class is like /info.
How can I change http://localhost:8000/info to http://admin.helloyou.com/info. I am working on a Symfony environment.
In your Windows HOSTS file you can set a mapping from your domain to your localhost (127.0.0.1):
127.0.0.1 example.com
Located in C:\WINDOWS\SYSTEM32\DRIVERS\ETC\HOSTS (On most other systems (Linux/OSX) it's under /etc/hosts)
Any requests for example.com will then go to your localhost - this is suitable for testing just on your local machine.
If you want to be able to test this from any machine on your LAN (including phones, tablets, etc.) then you can set an A record in the DNS Zone for that domain (perhaps for a localtest. subdomain) that points to the internal IP address of your server. eg. 192.168.1.20.
You need to go to your online management panel.
There you'll find something like DNS.
You add an A record from admin.helloyou.com to your public ip address.
Wait till all the caching servers are updated (can take 48 hours).
After this, your public device is visible trough admin.helloyou.com.
Now you need to go to your router (mostly 192.168.0.1).
Go to the page where you can set up NAT/PAT port forwarding (virtual server is a common name for this).
There you need to forward port 80 (public) to port 8000 (private) to your private address.
On your PC you need to allow public access to port 8000 in your firewall.
In the case that you don't have a NAT-router, but are directly connected, you cannot do this second step.
In that case you will always need to surf to port 8000, or let apache listen on port 80.

Categories