This is a quick and easy way to find out latitude and longitude information of a specific city in PHP, using the Google Maps API.
We should always try sticking to the three-layer model of web development:
- The structure and content layer: HTML
- The presentation and design: CSS
This makes for easily maintainable web pages, better performance thanks to caching and increased re-usability since you have everything in a specific file and this makes it easy to move it somewhere else.
A few days ago I discovered a nifty little web app called phpIPAM (short for PHP IP Address Management). The name pretty much gives it away, but from the developers’ own words:
Its goal is to provide light, modern and useful IP address management.
And honestly, it manages to do that extremely well. It has a bunch of different features, but one of my favourite ones is the visual representation of a subnet:
I was about to create the typical Excel spreadsheet with all the IP information since the number of servers in my home network has now reached a point where I tend to forget some of the IP addresses I am using, but then I found this web app and I decided to give it a try, but I think I will keep using it for a while.
Also, installing it is super quick and easy. I will go ahead and assume that you already have the following:
- Apache (2.2 or 2.4)
Basically, a full LAMP stack on your machine.
- Install the necessary PHP extensions:
sudo apt-get install php5-gmp php-pear
- Enable mod_rewrite in Apache:
sudo a2enmod rewrite
- Restart Apache to enable this change:
sudo service apache2 restart
- Change to your web server’s root directory (by default,
- Create a directory for phpIPAM:
sudo mkdir phpipam
- Download phpIPAM to this directory:
sudo wget http://sourceforge.net/projects/phpipam/files/phpipam-1.1.tar
- Unpack it:
tar -xvf phpipam-1.1.tar
- Enter your DB details
$db['host'] = "localhost"; $db['user'] = "your_db_user"; $db['pass'] = "your_db_user_password"; $db['name'] = "phpipam";
- Set the base folder to phpipam:
- Enter your DB details
.htaccessto set the base folder here as well:
- Remove the tar file:
webserver_ip/phpipamand complete the installation procedure (essentially just creating the database). You can let the installer itself take care of the creation of the database though, if you just enter the DB username and password.
I don’t know about you, but sometimes all I need is a quick refresh to my memory on how to do something, and I don’t need complete, in-depth instructions. Those times, I don’t want to scroll through long instructions, I just need some precise information, and I need it quick. This is why I wrote this quick post to be used as a reference for myself, and I thought that other people might find it useful too.
Note: if you would prefer in-depth instructions on this, I will refer you to the articles linked at the end of this post. They really cover everything there is to know about the topic and I wouldn’t be able to add any other useful information.
If you want to do some local web development on a Mac, you have two options: you either use a full stack like MAMP, or you enable Apache and PHP and install MySQL only. On Mac OS X, Apache and PHP are already installed, and it’s only a matter of enabling them.
Technically, Apache doesn’t even need to be enabled, it just needs to be started:
sudo apachectl start
To enable PHP you need to edit the
httpd.conf file (
/etc/apache2/). Specifically, you need to uncomment the following line:
LoadModule php5_module libexec/apache2/libphp5.so
And then run:
sudo apachectl restart
Now, this is all you need to do to be up and running: if you visit http://localhost you will see the Apache default page.
[Optional] Bring back the Sites folder
If you stopped at the previous step, you would use the default system-wide Apache folder:
/Library/WebServer/Documents/. If you prefer to have a user-level folder instead, there are a few extra steps to follow.
#LoadModule userdir_module libexec/apache2/mod_userdir.sofrom
http-userdir.conf(which you can find under
- Create a Sites folder inside your home folder
- Create a
- Copy and paste the following code inside the conf file
<Directory "/Users/<your_username>/Sites/"> Options FollowSymLinks Indexes MultiViews AllowOverride None Order allow,deny Allow from all Require local </Directory>
Restart Apache and you are good to go.
For more in-depth instructions on how to do this, have a look at the following two excellent articles: