Getting Apache, PHP, and MySQL installed and talking to each other is pretty simple — until something doesn’t come out right. This guide takes things one step at a time and checks each step along the way.
The good new is that because of the changes, you may not need this guide anymore, but I’ll update it when I get a chance to do a new install, just to keep my own head on straight.
Using MacPorts to build a LAMP server from scratch
About this tutorial:
There are other step-by-step guides out there, and some of them are pretty dang good. But I’ve never found one that I could go through and reach the promised land without a hitch. (Usually the hitches happen around MySQL.) Occasionally key points are glossed over, but I think mostly there are things that have changed, and the tutorials haven’t updated. Now however I’ve done this enough times that there are no hitches anymore for me. Since MacPorts occasionally changes things, I’ll put up at the top of this page the last time this recipe was last used exactly as written here.
This guide breaks things down into very small steps, but each step is simple. I include tests for each stage of the installation, so problems can be spotted while they're easy to trace. We get each piece working before moving on to the next. I spend a little time telling you what it is you accomplish with each step, because a little understanding can really help when it’s time to troubleshoot, and if things are slightly different you have a better chance of working through them.
Audience: This guide is designed to be useful to people with only a passing familiarity with the terminal. More sophisticated techno-geeks may just want to go through the sequence of commands, and read the surrounding material only when something doesn't make sense to them. The goal: follow these steps and it will work every damn time.
MacOS X versions: Tiger, Leopard, Snow Leopard, Lion. Maybe others, too. The beauty of this method is it doesn’t really matter which OS X version you have.
The advantages of this approach
There are multiple options for setting up a Mac running OS X to be a Web server. Many of the necessary tools are even built right in. Using the built-in stuff might be the way for you to go, but there are problems: It’s difficult to customize (Search on install apc Mac and you’ll see what I mean), you don’t control the versions of the software you install, and when you upgrade MacOS versions things could change out from under you.
Also simple to set up is MAMP, which is great for developing but not so much for deployment. For simple Web development on your local machine, it’s hard to beat.
But when it comes right down to it, for a production server you want control and you want predictability. For that, it’s best to install all the parts yourself in a known, well-documented configuration, that runs close to the metal. That’s where MacPorts comes in. Suddenly installing stuff gets a lot easier, and there’s plenty of documentation.
Holy schnikies! A new timing exploit on OpenSSL! It may be months before Apple's release fixes it. I want it sooner!
What you lose:
If you’re running OS X Server (suddenly an affordable option), you get some slick remote management tools. You’ll be saying goodbye to them if you take this route. In fact, you’ll be saying goodbye to all your friendly windows and checkboxes.
Also, I have never, ever, succeeded in setting up a mail server, MacPorts or otherwise, and I’ve tried a few different ways (all on the same box, so problems left over from one may have torpedoed the next), and no one I've ever met, even sophisticated IT guys, likes this chore. If serving mail is a requirement, then OS X Server is probably worth the loss of control. Just don’t ever upgrade your server to the next major version. (Where’s MySQL!?! Ahhhhhh! I hear frustrated sys admins shout.)
So, here we go!
Document conventions
There are commands you type, lines of code you put in files, and other code-like things. I've tried to make it all clear with text styles.
This is something you type into the terminal | Do not type the ; it's just to represent the prompt in your own terminal window. Once you've typed the text (or pasted it in from here), hit return. |
This is a line of code in a file. | Either you will be looking for a line like this, or adding a line like this. |
This is a reference to a file or a path. |
Prepare the Box
- Turn off unneeded services on the server box. Open System Preferences and select Sharing.
- turn on remote login
- (optional) turn on Screen Sharing
- Turn off everything else - especially Web Sharing and File Sharing
- Install XCode. This provides tools that MacPorts uses to build the programs for your machine. You can get XCode for free from the app store. It’s a huge download. Note that after you download it, you have to run the installer. It may launch XCode when the install is done, but you can just Quit out of it. Lion and Mountain Lion require an extra step to install the command-line tools that MacPorts accesses.
- Install MacPorts. You can download the installer from http://www.MacPorts.org/install.php (make sure you choose the .dmg that matches the version of MacOS you are running). Run the installer and get ready to start typing.
- Now it’s time to make sure MacPorts itself is up-to-date. Open terminal and type
sudo port selfupdate
password: <enter your admin password>
- If you're not familiar with
sudo
, you will be soon. It gives you temporary permission to act as the root user for this machine. Every once in a while during this process you will need to type your admin password again. - May as well get into the habit of updating the installed software while we’re at it. Type
sudo port upgrade outdated
- Make a habit of running these commands regularly. One of the reasons you're doing this whole thing is to make sure your server stays up-to-date. This is how you do it.
Install Apache
- Now it’s time to get down to business. All the stuff we’ve installed so far is just setting up the tools to make the rest of the job easier. Let’s start with Apache!
sudo port install apache2
- This may take a little while. It’s actually downloading code and compiling a version of the server tailored to your system. First it figures out all the other little pieces Apache needs and makes sure they’re all installed correctly. Hop up and grab a sandwich, or, if you're really motivated, do something else productive while you wait.
- When the install is done, you will see a prompt to execute a command that will make Apache start up automatically when the computer is rebooted. Usually you will want to do this. The command has changed in the past, so be sure to check for the message in your terminal window. As of this writing, the command is:
sudo port load apache2
- Create an alias to the correct apachectl. apachectl is a utility that allows you to do things like restart Apache after you make changes. The thing is, the built-in Apache has its own apachectl. To avoid confusion, you can either type the full path to the new apachectl every time, or you can set up an alias. Aliases are commands you define. In this case you will define a new command that executes the proper apachectl.
- In your home directory (~/) you will find a file called .profile - if you didn’t have one before, MacPorts made one for you. Note the dot at the start. That makes the file invisible; Finder will not show it. In terminal you can see it by typing
ls -a ~/
- Edit ~/.profile and add the following line:
alias apache2ctl='sudo /opt/local/apache2/bin/apachectl'
- Edit how? See below for a brief discussion about editing text files and dealing with file permissions.
- ~/.profile isn't the only place you can put the alias, but it works.
- You need to reload the profile info for it to take effect in this terminal session.
source ~/.profile
- Now anywhere in the docs it says to use apachectl, just type apache2ctl instead, and you will be sure to be working on the correct server.
- In your home directory (~/) you will find a file called .profile - if you didn’t have one before, MacPorts made one for you. Note the dot at the start. That makes the file invisible; Finder will not show it. In terminal you can see it by typing
- Start Apache:
apache2ctl start
- Test the Apache installation. At this point, you should be able to go to http://127.0.0.1/ and see a simple message: “It works!”
- MILESTONE - Apache is up and running!
Install PHP
- Use MacPorts to build PHP 5:
sudo port install php56-apache2handler
- Time passes and I don't always update the php version number. At this moment the latest php version is 5.6, so you use php56 everywhere. If you want to install php 7.0, you would use php70. You get the idea.
- MacPorts will know it needs to install php56 before it can install the apache2 stuff.
- You could install the MySQL extensions to PHP now (
sudo port install php56-mysql
), but that will cause MySQL to be installed as well. It’s no biggie, but I like to make sure each piece is working before moving on to the next. It makes problem-solving a lot easier. So, let’s hold off on that.
- Choose your php.ini file. There are a couple of different options that trade off security for convenience (error reporting and whatnot). As of this writing there is php.ini-development (more debugging information, less secure) and php.ini-production. Copy the one you want to use and name it php.ini:
sudo cp /opt/local/etc/php56/php.ini-development /opt/local/etc/php56/php.ini
- Test the PHP install
- On the command line, type
php56 -i
- A bunch of information will dump out. Hooray!
- On the command line, type
- Make your new php the default. This will allow you to run scripts from the command line just by typing 'php', rather than having to specify 'php56'.
- On the command line, type
sudo port select --set php php56
- Test this by typing
which php
You will see /opt/local/bin/php, which is where MacPorts keeps a pointer to the version you specified.
- On the command line, type
- Now it’s time to get Apache and PHP talking to each other. Apache needs to know that PHP is there, and when to use it. There’s a lot of less-than-ideal advice out there about how to do this.
- httpd.conf is the heart of the Apache configuration. Mess this up, Apache won’t run. It’s important, therefore, that you MAKE A BACKUP (there’s actually a spare copy in the install, but you never rely on that, do you?)
cd /opt/local/apache2/conf
sudo cp httpd.conf httpd.conf.backup
- First run a little utility installed with Apache that supposedly sets things up for you, but actually doesn’t do the whole job:
cd /opt/local/apache2/modules
sudo /opt/local/apache2/bin/apxs -a -e -n php5 mod_php56.so
- The utility added the line in the Apache config file that tells it that the PHP module is available. It does not tell Apache when to use it. There is an extra little config file for that job, but it’s not loaded (as far as I can tell), and it’s not really right anyway. Let's take matters into our own hands.
- It won't let me save! See below for a brief discussion about editing text files and dealing with permissions.
- Time to edit! Open /opt/local/apache2/conf/httpd.conf with permission to edit it. We need to add three lines; one to tell it that PHP files are text files (not strictly necessary but let’s be rigorous here), and two lines to tell it what to do when it encounters a PHP file.
- Search for the phrase AddType in the file. After the comments (lines that start with #) add:
AddType text/html .php
- Search for AddHandler (it’s just a few lines down) and add:
AddHandler application/x-httpd-php .php
AddHandler application/x-httpd-php-source .phps
- Finally, we need to tell Apache that index.php is every bit as good as index.html. Search in the config file for index.html and you should find a line that says
DirectoryIndex index.html
. Right after the html file put index.php:- Before:
DirectoryIndex index.html
- After:
DirectoryIndex index.html index.php
- Before:
- (Optional) As long as we’re in here, let’s make one more change for improved security. Search for the line that specifies the default options for Apache and remove Indexes:
- Before:
Options Indexes FollowSymLinks
- After:
Options FollowSymLinks
- Before:
- Save the file.
- Search for the phrase AddType in the file. After the comments (lines that start with #) add:
- Check the init file syntax by typing
/opt/local/apache2/bin/httpd -t
Syntax OK
message. If there is an error, the file and line number should be listed. - Restart Apache:
apache2ctl restart
- httpd.conf is the heart of the Apache configuration. Mess this up, Apache won’t run. It’s important, therefore, that you MAKE A BACKUP (there’s actually a spare copy in the install, but you never rely on that, do you?)
- Test whether PHP and Apache can be friends. We will modify the “It Works!” file to dump out a bunch of info about your PHP installation.
- Currently the default Apache directory is /opt/local/apache2/htdocs
- Start by renaming index.html to index.php:
cd /opt/local/apache2/htdocs
sudo mv index.html index.php
- Edit the file, and after the It Works! bit add a PHP call so the result looks like this:
<html>
<body>
<h1>It works!</h1>
<?php echo phpinfo(); ?>
</body>
</html>
- Save the file
- Go to http://127.0.0.1 - you should see a huge dump of everything you wanted to know about your PHP but were afraid to ask.
- MILESTONE - Apache and PHP are installed and talking nice to each other.
Install and configure MySQL
- Use MacPorts to install MySQL database and server and start it automatically when the machine boots:
sudo port install mysql55-server
sudo port load mysql55-server
- Now we get to the trickiest part of the whole operation. There's nothing here that's difficult, but I've spent hours going in circles before, and I'm here so you won't find yourself in that boat as well. MySQL requires some configuration before it can run at all, and it can be a huge bother figuring out what’s going on if it doesn’t work the first time. We start by running a little init script:
sudo -u _mysql /opt/local/lib/mysql55/bin/mysql_install_db
- As with Apache, you can create a set of aliases to simplify working with MySQL. There are some commands you will run frequently; things get easier if you don’t have to type the full path to the command every time. Open up ~/.profile again and add the following three lines:
alias mysqlstart='sudo /opt/local/share/mysql55/support-files/mysql.server start'
alias mysql='/opt/local/lib/mysql55/bin/mysql'
alias mysqladmin='/opt/local/lib/mysql55/bin/mysqladmin'
- #TEMPORARY addition to the path so the next step will work
- export PATH=/opt/local/lib/mysql55/bin:$PATH
source ~/.profile
- Next we need to deal with making the database secure and setting the first all-important password. The most complete way to do this is running another utility that takes you through the decisions.
sudo /opt/local/lib/mysql55/bin/mysql_secure_installation
Remember the password you set for the root user!- You now have a MySQL account named root which is not the same as the root user for the machine itself. When using sudo you will use the machine root password (as you have been all along), but when invoking mysql or mysqladmin you will enter the password for the database root account.
- As with PHP above, MySQL has example config files for you to choose from. The config file can be placed in a bunch of different places, and depending on where you put it, it will override settings in other config files. If you follow this install procedure, you don’t actually need to do anything with the config files; we’ll just be using the factory defaults. But things will work better down the road if you choose a config that roughly matches the way the database will be used.
- Find where the basedir is. As of this writing it’s /opt/local, and that’s not likely to change anytime soon, but why take that for granted when we can find out for sure? Let's make a habit of finding facts when they're available instead of relying on recipes like this one.
mysqladmin -u root -p variables
password: <enter MySQL root user's password>
- Now it’s time to choose which example config file you want to start with. The examples are in /opt/local/share/mysql55/support-files/, and each has a brief explanation at the top that says what circumstances it’s optimized for. You can read those, or just choose one based on the name. If you have no idea how big your database is going to be, medium sounds nice. You can always swap it out later.
sudo cp /opt/local/share/mysql55/support-files/my-medium.cnf <basedir>/my.cnf
- Find where the basedir is. As of this writing it’s /opt/local, and that’s not likely to change anytime soon, but why take that for granted when we can find out for sure? Let's make a habit of finding facts when they're available instead of relying on recipes like this one.
- On the command line, type
mysql -u root -p
password: <enter MySQL root user's password>
exit
Teach PHP where to find MySQL
The database is up and running; now we need to give PHP the info it needs to access it. There's a thing called a socket that the two use to talk to each other. Like a lot of things in UNIX the socket looks like a file.
The default MySQL location for the socket is in /tmp, but MacPorts doesn’t play that way. There are a couple of reasons that /tmp is not an ideal place for the socket anyway, so we’ll do things the MacPorts way and tell PHP that the socket is not at the default location. To do this we edit /opt/local/etc/php56/php.ini.
There are three places where sockets are specified, and they all need to point to the correct place. Remember when you saved the socket variable from MySQL before? Copy that line and then search in your php.ini file for three places where is says
default_socket
:pdo_mysql.default_socket = <paste here>
. . .
mysql.default_socket = <paste here>
. . .
mysqli.default_socket = <paste here>
In each case the
whatever =
part will already be in the ini file; you just need to find each line and paste in the correct path.- While we’re editing the file, you may want to set a default time zone. This will alleviate hassles with date functions later.
- Finally, we need to install the PHP module that provides PHP with the code to operate on MySQL databases.
sudo port install php56-mysql
- Restart Apache:
apache2ctl restart
- Test the connection.
- Typing
php56 -i | grep -i 'mysql'
- Second test: The whole bag of marbles. You ready for this?
- In the Apache’s document root (where the index.php file you made before lives), create a new file named testmysql.php
- In the file, paste the following:
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'MYSQL_ROOT_PASSWRD';
$conn = mysqli_connect($dbhost, $dbuser, $dbpass);
if ($conn) {
echo 'CONNECT OK';
} else {
die ('Error connecting to mysql');
}
$dbname = 'mysql';
mysqli_select_db($conn, $dbname);
- Edit the file to replace MYSQL_ROOT_PASSWRD with the password you set for the root database user.
- Save the file.
- In your browser, go to http://127.0.0.1/testmysql.php
- You should see a message saying “Connection OK”
- DELETE THE FILE. It's got your root password in it!
sudo rm /opt/local/apache2/htdocs/testmysql.php
- Typing
- MILESTONE - Apache, PHP, and MySQL are all working together. High-five yourself, bud! You are an IT God!
Set up virtual hosts.
Finally, we will set up virtual hosts. This allows your server to handle more than one domain name. Even if you don't think you need more than one domain, it's a safe bet that before long you'll be glad you took care of this ahead of time.
We will create a file that tells Apache how to decide which directory to use for what request. There is an example file already waiting for us, so it gets pretty easy.
- Tell Apache to use the vhosts file. To do this we make one last edit to httpd.conf. After this, all our tweaks will be in a separate file so we don’t have to risk accidentally messing something up in the master file.
- In /opt/local/apache2/conf/httpd.conf, find the line that says
#Include conf/extra/httpd-vhosts.conf
- The # told Apache to ignore the include command. Take a look at all those other files it doesn’t include by default. Some of them might come in handy someday...
- Save the file and restart Apache - the warnings you see will make sense soon.
- Test by going to your old friend http://127.0.0.1
- Forbidden! What the heck!?! Right now, that's actually OK. The vhosts file is pointing to a folder that doesn't exist and even if it did it would be off-limits. All we have to do is modify the vhosts file to point to a directory that actually does exist, and tell Apache it's OK to load files from there.
- In /opt/local/apache2/conf/httpd.conf, find the line that says
- Before going further, it's probably a good idea to figure out where you plan to put the files for your Web sites. I've taken to putting them in /www/<sitename>/public/ - not through any particular plan, but this gives me full control over permissions if I should ever need to chroot any of the sites. The Apple policy of putting sites in User can be useful, but really only if you plan to have one site per user. Otherwise permissions get tricky. The public part is so you can have other files associated with the site that are not reachable from the outside.
- Set up the default host directory
- Open /opt/local/apache2/conf/extra/httpd-vhosts.conf for editing.
You will see two example blocks for two different domains. Important to note that if Apache can’t match any of the domains listed, it will default to the first in the list. This may be an important consideration for thwarting mischief.
The examples provided in the file accomplish one of the two things we need to get done — they tell Apache what directory to use for each domain, but they do nothing to address what permissions Apache has in those directories. A lot of people put the permissions stuff in the main httpd.conf, but why not keep it all in one place and simplify maintenance while we reduce risk?
Here's an example:
<VirtualHost *:80>
ServerAdmin you@your.email.com
DocumentRoot "/www/sitename/public"
ServerName sitename.com
ServerAlias www.sitename.com
ErrorLog "logs/sitename-error_log"
CustomLog "logs/sitename-access_log" common
<Directory "/www/sitename/public">
Options FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
You can see where it sets what directory to go to, where it says to treat www.mydomain.com the same as mydomain.com, and then in the Directory block it sets permissions. The actual permissions instructions are pretty arcane. The most important thing to note is the line
AllowOverride none
Here's the skinny: A lot of web apps like WordPress and Drupal need to set special rules about how certain requests are handled. They use a file called .htaccess to set those rules. By setting
AllowOverride none
you're telling Apache to ignore those files. Instead, you can put those rules right in the <Directory> blocks in your vhosts file. It saves Apache the trouble of searching for .htaccess files on every request, and it's a more difficult target for hackers. .htaccess is for people who don't control the server. You do control the server, so you can do better.- If others will be putting sites on the server and you don't want them fiddling with the config files, you can allow .htaccess to override specific parameters. Read up in the Apache docs to learn more.
- If you are using SSL, you also need to set up a VirtualHost entry for port 443. That entry will also include the locations of the SSL certificates.
- Add further blocks that match the domains you will be hosting.
- Restart Apache and test your setup. http://127.0.0.1 should go to your default directory. Testing the domains is trickier if you don’t have any DNS entries set up for that server. I’ll write up a separate document about using /etc/hosts to create local domains for this sort of test.
- MILESTONE - You have done it. A fully operational LAMP environment on your Mac, suitable for professional Web hosting.
(Optional) Install phpMyAdmin
phpMyAdmin makes some database operations much easier. There have been security issues in the past, so you might reconsider on a production machine, but on a development server it can be a real time saver.
sudo port install phpMyAdmin
- Update your Virtual Hosts with the domain you want to use to access phpMyAdmin, which is by default at /opt/local/www/phpmyadmin/
- test - log in as root.
- Configure - configuring phpMyAdmin fills me with a rage hotter than a thousand suns. It just never goes smoothly for me, whether I use their helper scripts or hand-roll it while poring over the docs. Maybe if I do it a few more times I’ll be ready to write a cookie-cutter guide for that, too. In the meantime, you’re better off getting advice on that one elsewhere.
Wrapping Up
I hope this guide was useful to you. I'm he kind of guy who learns by doing, and I've made plenty of mistakes in the past getting this stuff working. Funny thing is, when it goes smoothly, you wonder what the big deal was. Hopefully you're wondering that now.
If you find errors in this guide, please let me know. Things change and move, and I'd like this page to change and move with them.
Keep up to date: One of the big advantages of this install method is that updates to key software packages get to your server faster. Use that power. Run the update commands listed in step one regularly.
- The script that tests the PHP-MySQL connection is based on one I found at http://www.pinoytux.com/linux/tip-testing-your-phpmysql-connection
Appendices
Appendix 1: A brief explanation of sudo
In the UNIX world, access to every little thing is carefully controlled. There's only one user who can change anything they want, and that user is named root.
When you log in on a Mac, you're not root, and good thing, too. But as an administrator, you can temporarily assume the root role. You do this by preceding your command with sudo
. (That's an oversimplification, and you will have earned another Geek Point when you understand why. In the meantime, just go with it. sudo
gives you power.)
When you use sudo, you type your password and if the system recognizes you as an administrator it will let you be root for that command.
For convenience, you only have to type your password every five minutes, but you do need to repeat 'sudo' for each command.
Just remember, as root you can really mess things up.
Appendix 2: On editing text files and permissions
Jerry told me to edit the file, you lament, but he didn't say how. Kind of strange, considering the minute detail of the rest of the guide. The thing is, there's not one easy answer.
Let's start with the two kinds of text editors. There are editors like vim and pico that run right in terminal. They are powerful, really useful for editing files on a remote box, and if you know how to use them you're not reading this footnote. The other option is a windowed plain-text editor. TextEdit is NOT a plain-text editor. There are a lot of plain-text editors out there, and they all have their claims to fame. You can use any of them to edit these files.
Whoops! That brings us to the gotcha: permissions. In UNIX, who can change what is tightly controlled. Many of the files we need to edit are owned by root, the God of the Machine, so we need to get special permission to save our changes. Many of the plain-text editors out there will let you open the file, but when it comes time to save... they can't. You don't have permission.
Some editors handle this gracefully, however, and let you type your admin password and carry on. BBEdit and its (free) little brother TextWrangler give you a chance to type your password and save the file. I'm sure there are plenty of others that do as well.
BBEdit and TextWrangler also allow you to launch the editor from the command line, so where I say above edit ~/.profile, you can actually type edit ~/.profile
and if you have TextWrangler installed, it will fire right up and you'll have taken care of the permissions issue. (If you decided to pay for BBEdit, the command is bbedit ~/.profile
.) I'm sure there are plenty of other editors that do that too.
I'm really not endorsing BBEdit and TextWragler here; they just happen to be the tools I picked up first. Over time I have become comfortable with their (let's call them) quirks. Alas, finding your text editing answer is up to you. If you're starting down this path, it's only a matter of time before you pick up rudimentary vim or pico skills; eventually you'll be using your phone to tweak files while you're on the road. It's pretty empowering. But is now the time to start learning that stuff? Maybe not. It's your call.
I don’t know if your intent was that this post realign all the posts and make your blog wider, but… yeah, it’s realigning all the posts and making your blog wider. Thought you might want to know.
Thanks. Yeah, while this is on the front page everything will be wider. This episode just needed a little more room.
Now I will be churning out episodes to push this monster off the front page. Suggestions and challenges welcome!
The Secret Life of Sporks!
Done and done!
Amazing post. I’ve bookmarked it for when I have some free time. Thanks.
Personally, I could not live without BBEdit, and I have had to edit locally (emacs, vim) and use various editing tools “encouraged” by various clients. It doesn’t suck. But I’m just not a command-line guy when it can be avoided. -b.
I’m with you. I think it comes down to remembering stuff. I’m not so good at that. I know about six vim commands, and I know there are easier ways to do almost everything I do.
Just today I remembered that I looked up once how to go to a particular line in a file, but that tidbit of knowledge is long gone, and I just held down the arrow key for a while. I’m pretty much the opposite of the power user.
BBEdit can edit over the wire with sftp, and that’s plenty fine most of the time. Still, I use vim on a pretty regular basis for quickie stuff, and I actually have used it from my phone for an emergency repair.
You are my hero!
thanx a lot!
Thank you so much for this guide – I don’t even want to think about how many hours you saved me! :)
Something crucial is omitted about setting up virtual hosts: you must not only edit httpd-vhosts.conf and uncomment “#Include conf/extra/httpd-vhosts.conf” in httpd.conf. You must also add an entry for each virtual host to /etc/hosts.
Yeah, I promised above to discuss /etc/hosts in a separate post, but never did. I’ll revise this to make that clearer. Thanks for the feedback!
Thanks for great post. I setted custom web directory to /Users/XXX/Documents/www and fell into issue with 403 forbidden access. I resolved it by changing permissions to 755 for every parent directory recursivly. Maybe, it can help someone.
Thank you for the helpful guide!
This is exactly what I needed, thank you so much for these instructions. Nothing else out there compared to how thorough and descriptive your step-by-step is.
Excellent post I had issues with phpmyadmin but this was primarily round to some php extensions not being present ie php54-mcrypt. By port installing an extension swarm this gives you a great dev environment..
port install php54-apc php54-curl php54-gd php54-http php54-iconv php54-imagick php54-mbstring php54-mcrypt php54-memcached php54-openssl php54-tidy
Great guide, thanks.
Even if it is optional, would it be not a good idea to set the server name? In other words where it says:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn’t have a registered DNS name, enter its IP address here.
#
#ServerName http://www.example.com:80
Change it to:
#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If your host doesn’t have a registered DNS name, enter its IP address here.
#
ServerName localhost:80
Thanks again,
Alberto
That’s a very good suggestion, much better than my advice to shrug off the warning. I’ll update when I have a moment.
A small problem in your check with the index.php file.
Where it says:
Should be:
The phpinfo() function output is boolean (see http://us1.php.net/manual/en/function.phpinfo.php), a secondary effect is that the output for the php installation configuration is printed, so echo tries to print TRUE (bool) instead of the HTML produced.
Alberto
Alberto, I owe you one. Thanks for the feedback.
oops. the commands in my previous comment were removed. They were
echo phpinfo();
and
phpinfo();
respectively.
-A
Pingback:
Nice article but my.cnf changes are not working.
I tried to change “max_allowed_packet” in my.cnf (/my.cnf) but after restart the mysql, it does not effect.
Please check and advice me.
Thank you
Asanka
In my install, I have my.cnf at
/opt/local/my.cnf
That’s because when I run
mysqladmin -u root -p variables
and look for basedir I see that it is
/opt/local/
Thank You. This is a time tested tutorial that I have used on many a different Macport installation. Very well put.
Just a note that “sudo port install php70-apache2handler” does not work and gives a fatal error that file checksums are not available. Just saying that in case someone here run into same issue.
Thanks for the heads-up. I haven’t ventured into php 7.0 yet. Might be worthwhile to submit a bug report over at MacPorts.
My programmer is trying to persuade me to move to .net from PHP. I have always disliked the idea because of the expenses. But he’s tryiong none the less. I’ve been using WordPress on several websites for about a year and am nervous about switching to another platform. I have heard fantastic things about blogengine.net. Is there a way I can transfer all my wordpress posts into it? Any kind of help would be greatly appreciated!
WordPress is so big that all other blogs have to be able to import and export data in a way WordPress can understand. I’m sure blogengine.net has a WordPress importer.
On the subject of php vs .net, I have mixed emotions. php is a bit of a dinosaur, and it was never built to do the super-fancy stuff Web sites do these days. Still, it’s tried and true. While I’ve never used .net I used its predecessor quite a bit, and these days .net is just about the last platform I would consider if moving from php, cost being the first obstacle and server options being the second. I would have to eliminate Ruby (rails), Python (django), node.js, and now Swift (several emerging options, blazing fast but immature) before considering a non-open-source option like .net.
But in the end, the server choice may not matter that much anymore. The “thin client” idea is dead, buried and good riddance, and now sophisticated apps are being made that run on the client machine (usually in the browser using javascript), making the servers straightforward data services that can be written with pretty much anything.
And that brings us back to WordPress. You’re using it. It works. There’s no more prevalent platform; plugins and expansions number in the tens of thousands. I use WordPress for this blog, because it just plain works. Unless there’s a specific feature you need that WordPress doesn’t do, I’d just roll with it and focus on making awesome stuff.
Apparently this was spam – three years later I got another comment like this, almost word for word. Huh.