I’ve been throwing together a few useful mac terminal os x shell scripts lately and this was another one of those cases today. It’s not completely finished just yet but it will do a job the first time round. I’m not sure just yet how best to have lots of different symlinks to different Library bases and how to code that so that it happens.
The below code and it’s paths are relevant to me and my setup with MAMP. You can easily edit this function to include different paths as you require.
Open up your ~/.bash_profile
sym-install-laravel () {
echo "Installing Laravel as symlink to $1"
mkdir -p ~/Develop && cd ~/Develop
DIR="/Users/davidheward/Develop/Laravel"
if [ ! -d "$DIR" ]
then
git clone https://github.com/laravel/laravel.git Laravel
else
echo "Directory already exists"
fi
cd /Applications/MAMP/htdocs
ln -s ~/Develop/Laravel/public/ /Applications/MAMP/htdocs/$1
cd /Applications/MAMP/htdocs/$1
echo "Install complete"
}
Save it close and open a new terminal session or reload profile ./profile
Then you can simply cd into your desired directory for me it's /Applications/MAMP/htdocs/ because i'm running MAMP on my Mac OS X machine and run the following at the terminal.
$ sym-install-laravel symlara
Visit this by just hitting http://localhost/symlara/ in your browser (if you have localhost configured in this way of course).
Again, as is often quite a common occurence on my blog, i’m again blogging something that I think me and my team will find useful in the future. This time it’s setting up a WordPress MU installation on OS X using MAMP.
We needed a WordPress Multisite install locally so that we could test flexibly, privately, and securely throughout the development process for a new project. It’s definitely worth the effort especially if you – like us love developing locally.
Things you’ll need
- Terminal
- Editor – vim, nano, mate
- MAMP installed
Getting started
First lets create a site in /Applications/MAMP/htdocs/ – call it mutest
mkdir mutest
cd mutest
Now checkout wordpress with your favourite version control (we use subversion).
svn co http://core.svn.wordpress.org/tags/3.3.2 .
You’ll see it checking out wordpress now – when it’s done navigate to localhost:8888/mutest/ and complete the WordPress installation, i’m going to assume your competent with installing it normally.
Now open up the MAMP portal and perform the following.
Now go to Ports and change the default port from 8888 to 80 – once you do this mamp will restart and probably prompt you for your admin password.
We’re going to use the subdomain mapping for wordpress rather than the subfolder so next we need to edit the /etc/hosts file (which is on your mac).
I use textmate with the terminal hook, so I fire up terminal and run a command like so.
mate /etc/hosts
You could run vim or any other terminal editor if you like.
Add two new example domains to the hosts file (you will probably add more in the future but two will do for now).
example.site.com
example1.site.com
Save and exit.
Edit your Apache vhosts config file
Open /Applications/MAMP/conf/apache/httpd.conf in a text editor and scroll down to the line that says “#NameVirtualHost *”. Replace that line with the following code:
NameVirtualHost *
<virtualHost *>
ServerName example.site.com
ServerAlias example.site.com *.example.site.com
DocumentRoot "/Applications/MAMP/htdocs/mutest"
<directory "/Applications/MAMP/htdocs/mutest">
Options Indexes FollowSymLinks Includes
AllowOverride All
Order allow,deny
Allow from all
</directory>
</virtualHost>
Save and restart mamp server.
Configuring WordPress MU
WordPress Multisite is really easy to configure just start by adding the following to your wp-config.php file.
define('WP_ALLOW_MULTISITE', true);
Once you’ve done this head to wp-admin backpanel and then look for the submenu ‘Tools’ and click Network.
On this page you will now see an option to use sub-domains for your site addresses. Make sure that’s selected, check the other details, and then click the “Install” button to make it happen. Note that you’ll see a warning message that says, “Wildcard DNS may not be configured correctly!” – we can ignore this warning because we know our DNS is correct.
Finally, complete the steps outlined there on the “Enabling the Network” page (i.e., create a blogs.dir folder and add the required code snippets to your .htaccess etc). After that, re-login to the Admin area and go to Network Admin > Sites > Add New to begin adding your sub-domain network sites.
Your done! It’s all over. Your now rocking a nice little wordpress multisite setup locally. Good job. Grab a coffee and get coding!
A colleague of mine was having some trouble setting up virtual host’s with his new installation of MAMP recently. So I decided to sit down and have a little look into it, and here follows a small guide to getting vhosts working locally on your mac using MAMP v2.0 and it’s bundled apache.
I’ve chosen to use “mate” which is the terminal shorthand for textmate, which you can download here Macromates Textmate, but you can swap out my instance’s of this with a more familiar editor like “nano” or “vim”.
Firstly run the following command or open /Applications/MAMP/conf/apache/httpd.conf in your preferred editor.
dave$ mate /Applications/MAMP/conf/apache/httpd.conf
First thing I noticed was that MAMP now quietly includes a bunch of file’s rather than just having it all appended at the bottom of httpd.conf, however all the usual files
Somewhere in amongst all of these files you will find the following:
# Virtual hosts
# Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Simply uncomment it like so;
# Virtual hosts
Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
I used a command from terminal like so:
dave$ mate /Applications/MAMP/conf/apache/httpd.conf
Next we need to set up a record in our /etc/hosts/ file, you will need to call on the power of “sudo” for this. Use the following command:
dave$ sudo mate /private/etc/hosts
You will of course be prompted for your password, which is your system password. Once open you should see something like this:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
Now add this line to the bottom of this file, replacing “nameserver” with whatever you wish to call yours.
127.0.0.1 testrun
Save and Quit.
Now you need to, create your virtual host in the vhosts file. So remember that line we uncommented in the httpd.conf file? The file that points to is now where we’re heading so.
dave$ mate /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf
Once open you should see something like this:
#
# Virtual Hosts
#
# If you want to maintain multiple domains/hostnames on your
# machine you can setup VirtualHost containers for them. Most configurations
# use only name-based virtual hosts so the server doesn't need to worry about
# IP addresses. This is indicated by the asterisks in the directives below.
#
# Please see the documentation at
#
# for further details before you try to setup virtual hosts.
#
# You may use the command line option '-S' to verify your virtual host
# configuration
#
# Use name-based virtual hosting.
NameVirtualHost *:80
# VirtualHost example:
# Almost any Apache directive may go into a VirtualHost container.
# The first VirtualHost section is used for all requests that do not
# match a ServerName or ServerAlias in any block.
#
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot "/Applications/MAMP/htdocs/playme/http/"
ServerName dummy-host.example.com
ServerAlias www.dummy-host.example.com
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
#
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/Applications/MAMP/htdocs/playmedeux/http/"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
You’ll notice that there are two uncommented dummy servers set up, if you want to reference them at a later date just simply comment them out using the “#” infront of text on every line, or you can simply delete them. If your commenting it should end up like this:
#
# ServerAdmin webmaster@dummy-host.example.com
# DocumentRoot "/Applications/MAMP/htdocs/playme/http/"
# ServerName dummy-host.example.com
# ServerAlias www.dummy-host.example.com
# ErrorLog "logs/dummy-host.example.com-error_log"
# CustomLog "logs/dummy-host.example.com-access_log" common
#
Right, now to adding our new one, called testrun, let’s copy the format from above and insert this code into the bottom of our file. Note that at this point you now need to decide where your document route is going to be, in most cases I would just create a folder inside htdocs inside my mamp install something like below:
dave$ mkdir /Applications/MAMP/htdocs/testrun/
Our document root in our VirtualHost setup should now reflect that when you add the following.
<virtualHost *>
ServerName testrun
DocumentRoot /Applications/MAMP/htdocs/testrun/
</virtualHost>
Notice how i’ve decided to make this available on a specific port but have just opted for any port, normal port numbers for apache are :8888 or :80 so you could specify either one of those if you so wished like so:
VirtualHost *:8888
As opposed to:
VirtualHost *
Onto the final leg, now we just need to reboot apache, so, in terminal you can do:
/Applications/MAMP/bin/apache2/bin/apachectl restart
Or simply if you prefer the mamp interface a stop and start of server’s should suffice.
One last thing, let’s quickly add a index.html file to our Document Root for testing purposes.
mate /Applications/MAMP/htdocs/nameserver/index.html
And enter “Welcome to the testrun vhost – Served by MAMP” to the file. Save and quit.
Finally type http://testrun:8888 into your favourite browser (of course with MAMP started) and you should see your index.html file served up nicely.