Running a Local Web Server on Your Mac

Use this forum to talk about Nova and ask any questions you may have about it. Please use the Help & Support forum if you have found a bug or need help getting something working.

AgentPhoenix Sun Jun 09, 2013 5:10 pm

Running a Local Web Server on Your Mac

It can be a pain to do any type of web development when you're having to constantly upload to a server and check your progress. When it comes to developing skins or custom MODs or testing Nova 3, it can be even more of a pain. It may have even made you wonder how I do all this work. The answer is simple: running a local web server.

Because PHP is a server side language, it has to have a server to interpret commands and send the output back to the browser. Traditionally, that's done on a brick-and-mortar server somewhere, but the same technology on those servers can be run on your desktop or laptop with only a handful of steps. Let's walk through what you need to do to get a local server up and running on your Mac.

The web server

The first (and most important) piece is the server. Years ago, you'd have to download source, compile, create symlinks and all other such nonsense. Today, it's much easier. On the Mac, we're going to use MAMP (Mac Apache MySQL PHP). You can download MAMP from the link below:

http://www.mamp.info/en/downloads/index.html

We're going to use the free version, but if you have the money and want to get the Pro version, you'll get a more robust control panel where you can do a lot more in terms of setting up virtual domains and such. None of that is necessary for what we're doing.

First things first. Download MAMP and install it into your Applications folder. Once you've finished the install, you can double-click on the MAMP icon in the MAMP folder in your Applications directory to launch the control panel. Once the control panel is on your screen, you'll see a very simple set of controls: Start Servers, Open Start Page, Preferences and Quit. There are also indicators on the left of the status of the Apache and MySQL servers (they'll turn green when the servers are running).

Click on the Preferences button and we'll make sure we're set to go. Let's go through the 4 tabs to make sure everything is right.

Start/Stop: This is a personal preference, but I uncheck opening the start page and stopping servers when quitting MAMP (this lets me close MAMP complete and still have the servers up and running).

Ports: Click the button to set to the default Apache and MySQL ports. This will make life in the browser a little easier.

PHP: Change the version to PHP 5.4. (MAMP Pro comes with a version of PHP 5.3, but you can also download a standalone installer from the link above if you need a copy of PHP 5.3.) You can also change the cache extension, but it isn't necessary.

Apache: By default, you'll store all of your documents you want to be on the "server" in Applications/MAMP/htdocs. The easier option is to change that to the Sites folder that comes with OS X by default. You can also choose to use a folder wherever you want.

When you're all set, click Ok and then click Start Servers. After a few moments, both the indicators should turn green. (If they didn't, you'll probably have to open up the Console app and see what errors were thrown.) If both indicators are green, you're successfully running a web server on your Mac!

To test that you're running the server successfully, click the Open Start page button. Your default browser should open and you should see the MAMP start page.

The database piece

So you have the web server up and running, but the database piece is just as important as the server for working with Nova. From the MAMP start page, you have access to phpMyAdmin, but that can be kinda clunky when dealing with managing your MySQL database. Instead, we're going to rely on an awesome third-party app called Sequel Pro.

http://www.sequelpro.com/

Download and install Sequel Pro then start it up. You'll be prompted to enter some credentials to connect to the server. Fortunately, we've got MAMP up and running, so we can simply connect to that server. For quick access to this connection in the future, create a new favorite by clicking on the plus button at the bottom of the window.

Click the Socket tab and create a name for the connection. I've set the name to root - localhost. The default username for MAMP is root and the password is root. You can change these, but since this is a local server, that's not really necessary. Leave the database field empty, but make sure you set the Socket to /Applications/MAMP/tmp/mysql/mysql.sock. Save the favorite and then connect.

It'll take a few seconds to connect, but once you do, you'll see a pretty blank screen. In the upper left, there will be a dropdown that says Choose Database. Click on that then click on Add Database. Set the name to nova (or whatever you want) and I generally choose the encoding as UTF-8, but you can leave it the default as well. Click Ok and now you have a new database on your server.

When you install Nova or anything else, it'll ask you for the database and you'll just type nova along with the root/root username/password combination. There's nothing in the database, but that's okay, because we have something to install Nova into now.

How the hell do I use this now?

Anything you want to display on the server, you'll put into the directory you set in the Apache tab of the MAMP control panel. Assuming you're using the Sites directory, just grab a new Finder window, open the Sites folder and create a new directory called nova. Download your copy of Nova from the Anodyne site and unzip the files into ~/Sites/nova. Once that's finished, fire up your browser and navigate to http://localhost/nova.

If all goes as planned, you should be redirected to the setup page and will go through the install process as normal. Once the install process is finished, you'll be able to use Nova as you normally would, but instead of needing a server, you're now doing everything on your Mac instead.

The thing to remember with a local web server is that you can't show someone else your Nova installation (or anything else on your server) by just sending a link. You'd have to change a bunch of settings on your Mac to allow that and would have to send a different URL to someone. This is meant solely as something to use for your own benefit.

An easier way to play around with Nova 3

There may be some people out there that want to keep up with Nova 3's development, even in its earliest stages. Since all of Nova 3's development is stored on Github, you can actually pull down a copy of Nova 3 and test it as work happens. This is both a good and bad thing. The good part is that you have easy, constant access to the work that's being done. The bad part is that things tend to break quite often, or even worse, change entirely without any documentation. If you're fine with that, you can actually get up and running with Nova 3 in a few short steps.

First, go to github.com and sign up for a free account.

Second, go to mac.github.com and download Github for Mac. Install Github and make sure you open it to go through the configuration process.

Third, go to github.com/anodyne/nova3. You'll see a button near the top that says Clone in Mac. This will kick off a process in the Github for Mac app that lets you clone the repository to your computer. Make sure you select the folder you setup for Apache to use (or wherever you want to put it). A few minutes later, you'll have a copy of Nova 3 on your computer. Brilliant!

Fourth, you'll need to get up and running with Composer so you can install Nova's dependencies. In order to do that, go to getcomposer.org and follow the installation instructions. Once Composer is installed, you'll go to the command line (Terminal) and navigate to ~Sites/nova3. Type in composer install and it will download a bunch of files and directories.

You can now navigate to http://localhost/nova3 (or wherever you put it) and go through the install process.

On a regular basis, make sure you go back into Github for Mac and sync the branch. Doing that will pull down the latest changes from Github and you'll be able to see and play around with bug fixes and any other changes that have been made since the last time you synced. You'll also need to go to the command line and run composer update as well to make sure the dependencies are up-to-date.

While this may seem complicated and like a lot of work, once you've done it a few times, it'll be a lot easier. This also won't be the process for stable Nova 3 releases either. Those will still come in a zip archive, but for staying up with Nova 3 development, this is how you'll keep tabs on everything! If you have questions, please post them below.
User avatar

Posts: 7577


Return to General

Who is online

Users browsing this forum: No registered users and 2 guests

cron