BSD How to Install Apache, MySQL, PHP, and phpMyAdmin on FreeBSD


(20170107 — The steps in this post were amended to address changes in recent versions of software. Minor editorial corrections were also made — iceflatline)

This post will describe how to install and configure Apache, MySQL, PHP and phpMyAdmin on FreeBSD for basic local web development. Once set up, you’ll be able to use your “FAMP” server to do web development, code testing, maintain local copies of your web sites, etc.

The software discussed in this post are available as free and open source under various licensing structures. The versions of software discussed in this post are as follows:

  • FreeBSD 11.0-RELEASE
  • apache24-2.4.25_1
  • mysql57-server-5.7.17
  • mod_php70-7.0.14
  • php70-7.0.14
  • php70-extensions-1.1
  • phpMyAdmin-
  • WordPress 4.7
  • The following steps discussed in this post assume you have the FreeBSD Ports Collection installed. If not, you can install it using the following commands:

    If the Ports Collection is already installed, make sure to update it:

    Okay, let’s get started. All commands are issued as the user root. While building the various ports you should accept all default configuration options unless otherwise instructed.

    Install Apache

    Navigate to the Apache server port and build it:

    Once Apache has been successfully installed, use the sysrc command to add the following line to /etc/rc.conf so that the Apache server will start automatically at system boot.

    Now let’s start Apache to make sure it works:

    Point your web browser to the host name or IP address of the FreeBSD host you’ve installed Apache on and you should see the venerable “It works!”

    Install MySQL

    Navigate to the MySQL server port and build it:

    Add the following line to /etc/rc.conf using sysrc:

    And start the mysql server:

    Then set a password for the MySQL root user:

    You’ll be requested to enter a password. Enter the random initial root password contained in /root/.mysql_secret. You’ll now be at the command prompt for the mysql server. Change your root password using the following command:

    Enter ‘quit’ to exit the server. You may now delete /root/.mysql_secret.

    Install PHP

    Next, we’ll build PHP:

    Then add the extensions to PHP to round out its capabilities. Before we build this port though we’ll want to add support for MySQLi (an improved interface to MySQL) in order to communicate with the MySQL server.

    In the corresponding menu you should select “MYSQLI”, then proceed with building the port:

    Now let’s add the module required to support PHP applications on Apache:

    Install phpMyAdmin

    phpMyAdmin is a free software tool written in PHP intended to handle the administration of MySQL from your web browser. phpMyAdmin supports a wide range of operations with MySQL, including managing databases, tables, fields, relations, indexes, users, permissions, etc., from an easy-to-use web page, while you still have the ability to directly execute any SQL statement from the command line if you prefer. Installing phpMyAdmin is optional but it’s a nice tool to have:


    Now that we have the requisite ports built and installed it’s time to configure them. First, let’s create the file /usr/local/etc/php.ini to hold our PHP options. The simpliest way to do this is to copy the file /usr/local/etc/php.ini-development which will add the default settings for new PHP installations. This configuration is suitable for development purposes, but NOT necessarily for production purposes. If your plans include a production server, then among other things, and before going online with your site, you should consider copying /usr/local/etc/php.ini-production instead and consult the recommendations at

    Now let’s configure Apache. Open the file /usr/local/etc/apache24/httpd.conf and look for the following line:

    And change it so it reads as follows:

    Then append the following lines to the end of the file in order to support PHP files as well as phpMyAdmin, which normally lives outside of the Apache document root. Note: if you elected not to install phpMyAdmin, then you need only add the FilesMatch directives.

    Now restart Apache:

    That’s it for our Apache configuration. Now let’s configure phpMyAdmin. We’ll do this by creating the file /usr/local/www/phpMyAdmin/, the basic configuration file for phpMyAdmin. Traditionally, users have manually created or modified /usr/local/www/phpMyAdmin/, but now phpMyAdmin includes a nice setup script, making it much easier to create this file with the settings you want. Start by creating the directory /usr/local/www/phpMyAdmin/config and make it writable by the phpMyAdmin setup script:

    Then make /usr/local/www/phpMyAdmin/ readable by the phpMyAdmin setup script:

    Now open your web browser and navigate to http://your-hostname-or-IP-address/phpmyadmin/setup where you will see the phpMyAdmin setup Overview page. Select “New server” and then select the “Authentication” tab. Under the “Authentication type” choose “http” from the drop-down list (using HTTP-Auth to sign-in into phpMyAdmin will avoid storing login/password credentials directly in and remove “root” from the “User for config auth”(See Figure 1).

    Screenshot of the phpMyAdmin setup page

    Figure 1

    Now select “Apply” and you will be returned you to the Overview page where you should see a new server listed. Select “Save” in the Overview page to save your configuration as /usr/local/www/phpMyAdmin/config/ Now let’s move that file up one directory to /usr/local/www/phpMyAdmin where phpMyAdmin can make use of it.

    Now let’s try out phpMyAdmin to make sure it works. Point your web browser to http://your-hostname-or-IP-address/phpmyadmin where you will be presented with a pop-up box requesting you to log in. Use “root” and the MySQL password you set up previously, then you should be directed to the phpMyAdmin administration page. We no longer need the /usr/local/www/phpMyAdmin/config directory so let’s remove it, as well as the read permission we added previously to /usr/local/www/phpMyAdmin/

    And wrap up by restarting the Apache and MySQL servers:

    Testing our installation using WordPress

    WordPress is a full-featured website/blog platform that makes heavy use of Apache, MySQL and PHP. We’ll install it on our newly created implementation to ensure we have these packages installed and working correctly. Once again, all commands are issued as the root user or by simulating the root user using the command su. Let’s start by downloading the latest WordPress directly from the developers site to your home directory and untarring the package:

    You should now see the new directory wordpress in your home directory. Next we need to create the file ~/wordpress/wp-config.php and make some changes to it so WordPress can access the MySQL server. First, let’s copy the file ~/wordpress/wp-config-sample.php to use as a template:

    Open ~/wordpress/wp-config.php in your favorite editor and enter the database name as well as your MySQL login and password in the appropriate lines. When complete, it should look like the following:

    Now move the wordpress directory to Apache’s document root:

    Next, let’s create an MySQL database for our WordPress installation. Open phpMyAdmin in your browser and create a database by selecting the “Databases” tab at the top. Enter a name for it in the “Create database” field. For purposes of our example, I’ll use “wordpress” as the database name. You’re free to use a different database name, just make sure to use the same name in the define(‘DB_NAME’, ‘your-DB-name’); line in ~/wordpress/wp-config.php as described above. Then select “Create.”

    Now let’s run the WordPress script that will populate its database with the requisite tables. Open your web browser and navigate to http://your-hostname-or-IP-address/wordpress/wp-admin/install.php. If everything is configured correctly you should see the WordPress installation wizard page (See Figure 2). Enter a title for your site, username, password, and an e-mail, then select “Install WordPress.” Then login with your newly created WordPress credentials and you should be presented with the default WordPress administration page.

    Screenshot of WordPress installation page

    Figure 2

    Common problems

    An error that occasionally pops up when attempting to start the Apache server is the following:

    This can be fixed by adding the following line to /usr/local/etc/apache24/httpd.conf:

    HTTP 403 permission problems when trying to access phpMyAdmin is another area that seems to sometimes trip people up. This is usually caused by errors in the way either the Alias or Directory Apache directives for phpMyAdmin have been written in /usr/local/etc/apache24/httpd.conf. As an example, a missing “/” in the Alias statement cost me two hours of troubleshooting time!


    Well, that’s it. A few hours of your time with the FreeBSD Ports Collection and you can a get a fully configured “FAMP” web development server up and running on your FreeBSD box.


    Tags: , ,

    136 Responses to “How to Install Apache, MySQL, PHP, and phpMyAdmin on FreeBSD”

    1. junkiest Says:

      Nice tutorial…. thanks !!!

    2. airjure Says:

      Thanks a lot for this tutorial! It helped me a lot. :)

    3. iceflatline Says:

      airjure, you’re welcome. Thanks for the comment.

    4. Jayson Says:

      This is just what I am looking for. It is so much easier with layouts and color code. Thank you.

    5. iceflatline Says:

      Jayson: Thanks for your kind comments.

    6. Johannes Says:

      Great stuff!

      Perfect, best current guide out there, really. thanks a lot!

    7. iceflatline Says:

      Johannes, glad it was helpful. Thanks for the kind words.

    8. DrTebi Says:

      Thank you for the hint on the
      “local file (7229347 bytes) is longer than remote file (5324905 bytes)”

      That fixed my problem when trying to upgrade Apache.

    9. iceflatline Says:

      DrTebi: Great! Glad it worked.

    10. Jayr Says:

      Excellent tutorial. Worked perfect!

    11. iceflatline Says:

      Jayr, awesome! Thanks for posting your comment.

    12. matt Says:


      Followed your directions but php info document does not work

      My browser just tries to download it. This is FreeBSD9-STABLE with same apache and php you had. Any ideas? Seems like getting php to work on FreeBSd is turned into a huge mess since the 4.x fbsd days!

    13. iceflatline Says:

      matt, hmmm… not sure. I used 9.0-RELEASE for the post. Perhaps there is something in STABLE that has broken compatibility? If I get some time I’ll try to recreate using STABLE.

    14. deine mudder Says:

      thank U sir!

    15. colour Says:

      Everything work perfect accept for the last one WordPress… received below message when I try to open the wp-config.php from web browser
      “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

    16. iceflatline Says:

      colour, I’m unclear on why you are attempting to open wp-config in your browser. Did you try to open http://your-hostname-or-IP-address/wordpress/wp-admin/install.php?

    17. Charles Says:

      This tutorial is excellent. However, I continue to have an issue when attempting to run ‘~/wordpress/wp-admin/install.php’. The error is “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

      The environment is FreeBSD 9.0, Apache 2.2.22, MySQL 5.5.25, PHP 5.4.3, phpMyAdmin 3.5.1, PHP extension: mysqli, and WordPress 3.4.

      I have gone over the php.ini file and uncommented all the necessary lines but the error continues. Everything seems to be functioning properly.


      Thank you in advance.

    18. reaper Says:

      I’ve got the same error as Charles above. I’ve gone through the steps above to the letter but I also get a
      “Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”

    19. iceflatline Says:

      Charles, I’m running the same packages but have not encountered that error. You might try restarting the apache and mysql servers, and then create a phpinfo.php page to see if mysql and mysqli support are indeed present. Finally, you may want to try reinstalling the php5-extensions package without the mysqli support to see if that might be gumming things up for you.

      There should be no further configuration needed to /usr/local/etc/php.ini after successfully copying it from /usr/local/etc/php.ini-development, however, I’ve posted mine to in case it might be helpful to you.

      Good luck and let me know what you find out.

    20. Darren Says:


      I’m not sure why my name came out as reaper above, stupid auto-fill.

      I recompiled php5-extensions with both MySQLi and MySQL support. This time I got no error. The only problem now is that I just get a blank page when I browse to my site :(

      No errors in the access log:
      – – [15/Jun/2012:09:57:29 +0100] “GET /ccie/ HTTP/1.1” 200 –

      So the get is working. No error here. NO 403 or 404 error in my browser either. Just a blank page.

      Any ideas?

    21. iceflatline Says:

      Charles, Darren, I’ve attempted to reinstall everything using the lastest packages and, among other issues, am encountering the same mysql error. I’ll figure out what the issues are and repost when I find a work around. Apologies for the hassles…

    22. Darren Says:

      No worries. I’ve got my site running on my Linux box. I might actually go for an older version of FreeBSD if I find some time

    23. iceflatline Says:

      Okay, reinstalled from scratch this weekend using the most recent packages. This time adding both the mysql and the mysqli options when compiling php5-extensions. WordPress installed without error. It appears there is now a dependency on the older PHP MySQL driver where one did not exist before. Or, more likely, it was selected by default in an earlier port and I failed to notice it and compiled it in, which would explain why subsequent port updates failed to catch anything wrong in my implementation. Anyway, the package list and installation steps in the post have been updated. My thanks to Charles and Daren for bringing the problem to light.

    24. Charles Says:

      I haven’t been able to address the issue since last week. I’ll reinstall as well and add both mysql/msqli.

      Sounds like that may be the issue.


    25. Charles Says:

      Just finished re-installing from scratch. Once I added the mysql and mysqli options the install went flawlessly.

      Thanks for the great tutorial and the assistance with the dependency issue.

    26. iceflatline Says:

      Charles, thanks for taking the time to verify, and apologies again for the hassle.

    27. ronjns Says:

      Thank you very much!

    28. iceflatline Says:

      ronjns, you’re welcome. Thanks for the comment.

    29. Abay Says:

      Excelente tutorial, muy completo, enhorabuena.


    30. Gerald Says:

      I’ve been trying to get this to work and I get stuck on the phpmyadmin stuff – I point a browser at it and I get an unprocessed php file sent from the server. There were also a couple dependencies that wouldn’t compile right, but I was able to pkg_add them.

      Thanks for the guide though. :) Any chance of a less compiling “pkg_add -r” solution?

    31. iceflatline Says:

      Gerald, sorry to hear about your difficulties compiling the requisite ports. Glad you got it working though. I typically don’t use pre-compiled binary packages on *bsd so unlikely I’ll write an article explaining their use in this application. You never know though…

    32. Gerald Says:

      And no… pkg_add isn’t doable due to default compile time options not building the right bits. Furthermore mixing pkg_add and compiled ports stuff confuses dependencies in both systems – eventually making stuff refuse to work. :p

      What broke me is that I had already installed some other utils using pkg_add, and it broke the compile time dependency checks in the ports builds. I’ve regressed my pkg_add chain and am now doing ports builds for those utils as well.

    33. iceflatline Says:

      Gerald, good advice. Thanks for sharing it.

    34. Gerald Says:

      You’re welcome. Thank you for the starting point.

      For the details of the problems I encountered (and my mistakes) – one of the php5 dependencies didn’t want to build because it conflicted with a conf package that pkg_add had installed to support mc (midnight commander). So I simply did “pkg_add -r php5”, everything looked okay… except the precompiled package doesn’t include the apache module. D’oh.

      So, to clean up the mess – pkg_deleted the conflicting package, and everything stacked on top of it (mc, php5), including the stuff that stacked on when it was compiled (php5-extensions, phpmyadmin.) Now compiling everything over again. I’ll rebuild mc after I have AMP running.

      Something I did different – the 11 lines of support for php became /usr/local/etc/apache22/Includes/php5.conf on my setup because apache autoloads all .conf files in that directory. Keeps httpd.conf just a little cleaner.

      Anyway, experience shared, lessons learned. Thank you again for the basic guide. :)

    35. Graeme Geldenhuys Says:

      Thank you VERY MUCH for this great article. It was exactly what I was looking for, and your instructions were clear and spot on! I had to laugh today, when I read your “Common Problems” section this morning – after I spend an hour last night trying to get the phpMyAdmin to work. I too had the missing “/” in my Apache config files. :-) That will teach me for not reading the setup instructions completely, before I start the setup.

    36. iceflatline Says:

      Graeme, You’re quite welcome. Don’t feel too bad, I’ve actually tripped over this problem twice! That will teach me for not reading my own setup instructions.

    37. blueigloo Says:

      I can’t tell you how much this helped me. Even though I ran into extra snags since I’m trying to install these programs in a FreeNAS Jail, I still don’t think I would have come close to being successful without this guide. Thank you, thank you, and thank you.

    38. iceflatline Says:

      Blueigloo, You’re very welcome. I’m glad it helped. I’ve not tried to stand this up in FreeNAS before; however, I have used FreeNAS for simply storing the Apache doc root. I also recently switched from FreeNAS to NAS4Free and like it much better.


    39. Somsak Says:

      Hi, Anybody can help Pls.
      After Follow >> mv /usr/local/www/phpMyAdmin/config/ /usr/local/www/phpMyAdmin and will try again then not show anything

      Help me ple.

    40. iceflatline Says:

      Somsak, thanks for posting and apologies for the delay in responding. I just ran through the steps on a new FreeBSD 9 RELEASE system and was able to install everything with no issues. About the only thing I can suggest at this point is to carefully run back through the steps and post again if you need clarification on any of them.

    41. ahmadsarang Says:

      i have problem regarding this
      can someone help me??

      stop in /usr/ports/archivers/php5-zip

      this happen i try to built phpmadmin ports

    42. iceflatline Says:

      ahmadsarang, I assume your trying to install PHP5? I just installed AMP per the instructions above on a fresh install of FreeBSD 9-RELEASE and encountered no such error. Does the stop message give any other indication of what the problem might be?

      You might also try installing portmaster (/usr/ports/ports-mgmt/portmaster) and try installing PHP5 using it:

      [shell light=”true”]
      portmaster -dwv lang/php5

    43. chaoman Says:

      Thanks a lot for this nice tutorial. It helps me to integrate newly created jail on nas4free with a webserver.

    44. iceflatline Says:

      chaoman, you’re very welcome. Thanks for the kind words.

    45. 在 NAS4Free 的 jail 上安裝 Apache, PHP 和 MySQL | 炒麵的嘀咕自語 Says:

      […] […]

    46. XenitXTD Says:

      Hey, I run the process and everything goes perfectly until i get to the part where i create the config folder in the phpMyAdmin and am supposed to run the setup from hostname/phpMyAdmin/Setup and i get a 404 not found… could you advise as to why this is

    47. XenitXTD Says:

      Just and Update, My Apache page shows IT works and all and everything works like perfectly but the part where i am supposed to Setup the PHP MY ADMIN is not working… I did the install twice to the exact specifications listed and found that its the same for me… what am i doing wrong, other than the My Admin excellent Article and Thanks for the help…

    48. XenitXTD Says:

      Hi I found that i am logged in with the Root account and when i try to access the PhpMyAdmin/Config folder which i created with the mkdir like explained and adding the CHMOD o+w it i am unable to access it as it says that my root account his permission denied

      When i open the url to the setup its a 404 url not found on server…what else can i do to grant access to the folder

    49. iceflatline Says:

      XenitXTD, in my experience that problem is usually caused by errors in the way either the Alias or Directory Apache directives for phpMyAdmin have been written in /usr/local/etc/apache22/httpd.conf. Make sure they are entered as follows, including character case:

      [text light=”true”]
      Alias /phpmyadmin "/usr/local/www/phpMyAdmin"

      <Directory "/usr/local/www/phpMyAdmin">
      Options None
      AllowOverride None
      Order allow,deny
      Allow from all

    50. Romnick Says:

      nice how to, ur da best :)

    51. novice Says:

      Excellent tutorial, easy to follow and brief where it should be.

      I’ve only just completed my first ever freebsd install (release 9.1 in a vm) and almost everything has worked as per your tutorial.

      One problem I have had though, came right at the end, where wordpress was expecting the wp-login.php script to reside within a “wp-admin” folder within wordpress [http:///wordpress//wp-login.php] whereas, my install of wordpress seems to have it in the root directory (wordpress/).

      I manually altered the url, the script worked and logged me into the site, but I wonder whether I should create the “wp-admin” folder within wordpress or maybe look to find the line inside wordpress/index.php and change that to wordpress/wp-login.php rather than wordpress/wp-admin/wp-login.php.

      I’m not sure why this is different, I don’t think I’ve deviated in any meaningful way from the tutorial…

      The one significant difference might be that I originally installed release 9.0 of freebsd, then let the system upgrade overnight to 9.1.

      Anyway, some advice and maybe pointers to a solution would be much appreciated.

      Thanks, and thanks again for a great tutorial.

    52. novice Says:

      re: my previous post. The wordpress url should read http://my.ip.address/wordpress/wp-admin/wp-login.php*

    53. iceflatline Says:

      novice, thanks for your comment. In a default installation of WordPress the file wp-login.php should reside in the root directory. This is where WordPress expects it to be. This configuration then allows you to log in using the following URL syntax: [site]/wp-admin or [site]/wp-login.php .

    54. Ranzabar Says:

      Sa-weeet. Did the job. Now I can sleep at night again.

    55. iceflatline Says:

      Ranzabar, awesome! Glad I was able to help you (hopefully) get a good night of sleep.

    56. renic Says:

      You should really suggest “make config-recursive” instead of “make config” … this usually prevents coming back to find a config screen when you are expecting to find a command prompt :)

    57. Tykog Says:

      been trying to setup this exact configuration for a few days with errors, in the latest FreeBSD available as of 3/23/13 there are issues with “libgpg-error-1.11.tar.bz2” and “libgcrypt-1.5.0.tar.bz2” you can manually fetch them from
      and here
      and put them into /usr/ports/distfiles

      also some issues when installing phpMyAdmin, problems with openjdk6, just find it in
      make install clean
      then return to phpMyAdmin and follow instructions as provided here.

    58. iceflatline Says:

      Tykog, you are referring to the first beta build of FreeBSD 8.4, in the project’s “legacy” branch, announced 20130323. My post was based on the latest production release of FreeBSD – 9.1-RELEASE. In short, I’m not surprised you ran into some dependency issues. Regarding phpmyadmin, your comment suggests it has a dependency on java, however there is no such dependency. Perhaps though, something else you’re doing requires you to install it…

    59. recycled Says:

      Like Tykog I had issues installing phpMyAdmin.

      I’m running FreeBSD 9.1-RELEASE 64-bit as a virtual machine on XenServer 6.1 with the kernel custom configured with:
      options IPFILTER
      options IPFILTER_LOG
      Following your tutorial step-by-step resulted in errors with openjdk6 which were rectified by entering /usr/ports/java/openjdk6/ and running a make install clean
      After that, I returned to /usr/ports/databases/phpmyadmin/ and finished the process.

    60. iceflatline Says:

      recycled, hmmm, strange. I just performed the steps outlined in the post on a fresh install of 9.1-RELEASE (on bare metal) after updating it using freebsd-update. I encountered no such dependency for openjdk6. Running make build-depends-list && make run-depends-list also confirms that it is not a dependency.

    61. ysq Says:

      nice tutorial, tks.

    62. Chris Says:

      AllowOveride should be All or at least AuthConfig
      if we want to secure the phpMyAdmin installation with password.
      (In case the box is public or has static IP)

      By the way, I used suPHP from www/suphp port.
      Only one extra step to secure it and make it run under suphp
      suPHP_Engine on
      in httpd.conf.

      Just writing it here in case someone lands from google. Both useful.

    63. RandomYggdrasil Says:

      Had a lot of issues trying to get this to work but then I deinstalled apache 2.2 and used apache 2.4 replacing the appropriate lines with apache24.

      Not sure if anyone will read the comments this far down but hope it helps.

    64. Yu Says:

      Just want to thank you for your detail tutorial which helps me a lot

    65. SteveS Says:

      Great article… but I hit a snap with myphpadmin:

      I got the 403 permission error until I changed my httpd.conf setting (Apache24) to read:

      Options None
      AllowOverride None
      Order allow,deny
      Allow from all
      Require all granted

      Apparently, “Required all granted” for this section enables access.

    66. iceflatline Says:

      SteveS, thanks very much for bringing this problem to my attention. Yes, it appears that as of Apache 2.4, the old access control directives no longer work, and must be replaced by the new Require directive, implemented under the new Apache module mod_authz_host. I’ve revised the post to correct this issue.

    67. Instalar Apache, MySQL, PHP, phpMyAdmin y Wordpress en FreeBSD | Cyberia Lab Says:

      […] […]

    68. Clay Garland Says:

      You should add, that if people are getting gmake not found errors when they’re trying to make install, that they need to create a symlink to gmake in their usr/bin directory. I always have this problem when I’m setting up BSD on a virtual machine.

    69. iceflatline Says:

      Clay, I think you just did. Thanks for adding your knowledge to the discussion.

    70. Icarus Says:

      This is a great help took me a few hours of keeping the shell open installing the packages and watching a movie at same time,but worked perfectly there is mysql 5.6 out now but i kept with 5.5 this guide works perfectly this is a big help for a raw freebsd install like i had,now i also have a fully functional web and datbase server FAMP
      il keep up with your blog

      Thank You !!!

    71. iceflatline Says:

      Icarus, awesome. Glad it worked well for you. Thanks for the kind words.

    72. Harry Says:

      Nice with this tutorial to get WordPress up and running locally… just working “out of the box” on my FreeBSD 10.0-BETA3.


    73. iceflatline Says:

      Harry, thanks for the kind words. Glad to hear it worked on FreeBSD 10. I have not had a chance to test it yet.

    74. JakDaRippa Says:

      Thanks. Very accurate. The best AMP tutorial I’ve seen so far.

    75. iceflatline Says:

      JakDaRippa, thanks very much for the kind words.

    76. amen Says:

      Hi this work on freenas 9.2 do i need to create a jail? or just ssh to freenas and start copy paste this steps?

    77. iceflatline Says:

      amen, assuming you have access to ports (and can build them) on FreeNAS I see no reason why it should not work. As an alternative, you might look to see if there is a FreeNAS “plugin” that supports this fucntionality. If you just want to use FreeNAS as the Apache doc root, I wrote a post on how to do this.

    78. FreeNAS User Says:

      Thanks for taking the time to write this up iceflatline. I’ve used it twice to setup two separate servers.

      Very well written.


    79. iceflatline Says:

      FreeNAS User, thanks for the kind words.

    80. techknight Says:

      Is there anyway to separate the configuration into a couple of Jails. I am relatively new to FreeBSD, but am learning as much as i can when i can. I am planning to have multiple Jails with Apache and PHP and would like to have one Jail with MySQL in it versus having MySQL in every Jail. Is it even possible to begin with? And if it is are there any special steps that need to be taken?

      Your tutorial here is very good and i have learned a lot from it.

      Thank You

    81. iceflatline Says:

      techknight, thanks for the kind words. I have not implemented this in jails the way you’ve suggested but I see no reason why it wouldn’t work. PHP would likely have to live within each jail along with Apache, but then it seems like you could simply point each web server to the jail where the database lives.

      Give it try and let me know how you make out.

    82. Chris Says:

      FYI, lang/php5 doesn’t have an option to build the apache module anymore. You have go to www/mod_php5 and “make clean install” after doing the same for lang/php5

      Restart apache afterwards and you should be good to go.

    83. iceflatline Says:

      Chris, thanks for the update. I’ll revise the post as soon as I can.

    84. Goose Says:

      I appreciate this is a very old post but the steps

      cd /usr/ports/databases/phpmyadmin/
      make config clean

      don’t appear to do anything, certainly not create the /usr/local/www/phpMyAdmin directory and files as looks to be expected. Should it be ‘make install clean’?

      Trying this with php55 instead of php5 shouldn’t have any effect but that is the only difference.

      Any ideas?

    85. Goose Says:

      In answer to my own question and to help others, it is php55 causing the problem and make install clean does work. php55-extensions needs the GD library enabled…

    86. iceflatline Says:

      Goose, yes indeed, it should be ‘make install clean’. Thanks for alerting me to the error. The post has been updated.

    87. thingle Says:

      I installed all the PHP5 packages but still can’t get the setup to work in phpmyadmin. I can only see the php code when trying to open it.

    88. iceflatline Says:

      thingle, okay I’ll have a look as soon as I get a moment.

    89. Jay Says:

      Thank you for an excellent write-up on this. Although tripping a couple of times, I was able to get our family’s website upgraded, with a general wordpress account for our main page and individual wordpress accounts and pages for each of us.
      Of course, I had to break it. I was trying to upgrade and fix some unrelated issues in gnome, which appears to have wiped out php. Although I went back through the install and configuration steps above, like thingle, we only see the php code when we open the page in our browser.
      I’m going to keep working on it, and most likely will remove gnome and all associated parts to get back to a bare-bones FreeBSD system. I’ll let you know what I find.

    90. iceflatline Says:

      jay, thanks for your comment. I’ll try to look at this issue as soon as possible. All my equipment is tied up on other projects right now. Please comment again if you find a solution.

    91. iceflatline Says:

      Okay, using the ports and steps described in the post I encountered no issues. I’ll try again using PHP 5.6.

    92. Jay Says:

      Thanks, I’ve also had some success as well. I’ve cleaned out all of gnome and associated libraries, drivers, utilities and the like. I did note that for some reason, db48 and db5 were both present, and for some reason, the old gnome required apache22 (which is why I tripped last time, due to differences between 22 and 24 directory security access definitions. After cleaning out everything and reinstalling as above, and moving my sites over to the apache24 directory, most everything is working. I’m currently working on two issues:
      1) Attempting to log into wordpress generates the error message: “Fatal error: Call to undefined function hash() in /usr/local/www/apache24/data/wordpress/wp-includes/session.php on line 64”. I suspect there was an option (sha256) somewhere I forgot to check, or otherwise missing something.
      2) I need to re-figure out how to restrict access to the phpmyadmin directory to only the local network. I was able to implement this under apache22, now I need to do this again for apache24.

    93. Jay Says:

      Finally got the last two worked out.

      1) Turns out that the php5-hash module was never installed by any of the other modules. It does not seem to be a requirement or option in any of the apache or php configuration sections. Installing this cleared up the wordpress login error. (thanks to “Ebbmar” at

      2) Under the <Directory block, previously the statement was "Allow from 192.168", now it has to be "Require ip 192.168" to restrict phpmyadmin access to only the local network.

      Thanks again for all the help, I never would have been able to get these sites working for my family without it.

    94. therooster Says:

      I followed your instructions very carefully. Everything worked perfectly on my first try. I am a beginner approaching novice.

      Thank you for a great tutorial. Now will you please make on on BIND. lol Just kidding…unless of course you have the time!

    95. iceflatline Says:

      therooster, Great! glad it worked for you. Thanks for commenting.

    96. iceflatline Says:

      Jay, I’m glad you got all working.

      By the way, I reinstalled using the following ports:


      Everything worked as expected, so I have updated the post to reflect these new ports.

    97. Upgrades and Downgrades | Jay's Corner Says:

      […] thanks to ‘iceflatline’ ( for his write-up on putting this all […]

    98. naugehyde Says:

      Thank you!!!

      The instructions work for FREENAS 9.2 as well (note: did NOT install and test WordPress) . Just one note: You have to create your webserver jail from the “portjail” template in the Freenas console to get all the port goodness.

    99. iceflatline Says:

      naugehyde, good to know! Thanks for sharing this.

    100. mat Says:

      noob question here:

      how do i change an option from the install options?

    101. iceflatline Says:

      mat, I’m not sure I understand the question. Which install options are you referring to?

    102. mat Says:

      I got it figured out. I was trying to follow this with an install of FreeNAS through the web GUI’s shell. I couldn’t select the options for mysql support for mod_php56. I ended up enabling ssh and accessed it via PuTTy.

    103. iceflatline Says:

      Gotcha. Thanks for letting me know.

    104. Ankur Says:

      Great tutorial. Thank you so much! I performed this in a FreeNAS portjail and works brilliantly!

    105. iceflatline Says:

      Ankur, good to hear! Thanks for letting me know.

    106. kaspernordmark Says:

      Delete the firs commet. I made a major typo

      I finaly managed to install this in a freenas 9.3 jail after 5 atempts (no idea what i did wrong) and the things i needed to change was that i hat to do a “pkg upgrade” after i had extracted the portsnap and then when i come to “cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php” it has to be “cp /wordpress/wp-config-sample.php /wordpress/wp-config.php” and “mv ~/wordpress/ /usr/local/www/apache24/data/” hast to be “mv /wordpress/ /usr/local/www/apache24/data/”.

      Thank you for the great turtorial.

    107. iceflatline Says:

      kaspernordmark, thanks for your comment. It looks like you downloaded the wordpress tarball to root of your file system, which is why the cp syntax in the examples did not work for you. I’ve added the command cd ~ before the fetch command to help make this clearer.

    108. bish Says:

      iceflatline, thanks so much for this brilliantly put together post. This is probably the tenth time I’ve tried to setup a webserver on my freenas to run wordpress alongside some static pages – previous efforts to figure it out by myself (with the aid of much less helpful guides) have always fallen short, usually after days of tinkering and frustration (except one glorious time when I actually got everything working by myself, albeit using a variety of cludges to get there… and then the disk holding the jails failed a few months later!)

      This time, I simply followed your steps and had a fully functional server in less than two hours. And phpMyAdmin is a fantastic addition: makes handling mysql utterly painless! Really can’t thank you enough – easily the best writeup I’ve seen for this topic!

    109. iceflatline Says:

      bish, you’re very welcome. And thanks for the kind words.

    110. Gary Says:

      I have had problems with a missing mbstring in extensions
      as well, as being warned to check ZTE threading in both the php5x and php5x itself.
      and one more, do not check APC if using php55. pecl ( part of the mod) doesnt like php 55 at all.
      what this means is that php5x-extensions, php5x_mods, possibly php5x itself must be compiled as the parts mention here are not a part of the precompiled packages.

      php5x meaning php55 or 56


    111. Ricardo Says:

      Thanks heaps for this tutorial, you’ve been a lifesaver. Now I can play with wordpress to my heart’s content.

    112. iceflatline Says:

      Ricardo, you’re welcome. Thanks for the kind words. Having the ability to play with WordPress locally is what motivated me to create the post.

    113. Garyjg269 Says:

      Thanks for the excellent tutorial… I’m not a Linux person nor a programmer but following your instruction everything seems to be working…

      question: is it possible to have owncloud running with the about installation?

    114. iceflatline Says:

      Garyjg269. No. ownCloud is a self-hosted file sync and share server based on Linux. It’s not really a web server.

    115. garyjg269 Says:

      Hi and thanks for the reply… what I was meaning is what others have done, install owncloud into a jail.

      ref link

      but I’ve love to use your install…


    116. iceflatline Says:

      garyjg269, apologies, I’m still don’t think I’m understanding you. Are you trying to get Apache, Mysql, etc or ownCloud installed in a FreeBSD jail?

    117. Scott Says:

      Fantastic! Everything worked flawlessly. Thank you for the wonderful tutorial.

    118. iceflatline Says:

      Scott, great! Glad it worked well for you.

    119. Jail/nas4Free 에 FAMP 설치하기 – Nite Lite Says:

      […] 1. how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd […]

    120. Julien Says:

      it’s great!
      But it’s out-of-date.
      Now, there is PHP 7.0.x.

    121. praxidice Says:

      I’ve followed every single step to the letter, checked and re-checked til my eyes are popping out of my head, rebooted & restarted apache umpty zillion times, still get a totally blank page at http://IPaddress/wordpress/wp-admin/install.php

      I’ve quite obviously stuffed up someplace but I haven’t the foggiest idea where. That said, every experience I’ve ever had with PHP has been demonic, in fact I swore never to touch it with a bargepole after the last attempt many years ago.

      I’ve followed numerous tutorials in vain attempts to get WordPress working. If there was a non_PHP equivalent I would most definitely be using it. Surely it can’t be as difficult as I’ve found. What FFS am I missing here ??

    122. praxidice Says:

      FWIW, apache24 is working fine, MySQL appears to be working fine, PHP appears to be working fine as far as a file is concerned. phpMyAdmin doesn’t even give a hint that its working & WordPress hasn’t even realized its installed, let alone is supposed to be configurable. My 2c worth is that the very thought of ‘php’ is possessed.

    123. iceflatline Says:

      praxidice, that sounds frustrating. I went through the instructions today on fresh install of FreeBSD 10.3-RELEASE installed as a VM just to make sure nothing had changed and it worked fine for me. Were you able to create the database using phpMyAdmin?

    124. Pim Says:

      installing mysql-server. port builds and installs without errors.
      can never enter mysql. there is no /root/.mysql_secret and no matters which password i enter after “mysql -u root -p” i get the following error:

      “ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)”

      i tried all the possible solutions i found on freebsd forums… nothing helped.

    125. iceflatline Says:

      Pim, thanks. Are you installing databases/mysql57-server or an older version?

    126. Peter Says:

      I have been trying to get more use out of my freenas file server. This is the first tutorial I have found that has worked for building a working Apache server for an internal website.

      Thank you for maintaining this page. If possible can you point me in the direction of a tutorial for setting up the ftp connections for installing themes. Using my router and DNS, I believe I can make my jail (the one with Apache and WordPress) available to the web. however, I do not understand how to set up ftp on the server. I hope that make sense. Thanks!

    127. iceflatline Says:

      Peter, thanks for your comment. It’s quite easy to setup an FTP server in FreeBSD as one is included in the base system. Instructions for doing so can be found in the FreeBSD Handbook located at

    128. Charles Says:

      Thanks for the great tutorial, worked great.

    129. Alex Says:

      Doesn’t seem to work for me, I am trying to setup phpmyadmin, I’ve never used freebsd, I’ve been using CentOS for years now, but I am somewhat forced to use FreeBSD. Anyway.

      I am getting the following error when I try to import files, or import data via the SQL tab:

      ” Error: Token mismatch” I’ve been Googling for hours, and my tmp folder is enabled, my tmp folder is not full although files do go in there when I access the phpmyadmin client.

      I don’t know what I am doing wrong.

      Thanks for your time, and help.

    130. Blake Says:

      Could you help me with installing PHP Nuke. I’ve gone through this and have everything up and running. Would like to add PHP nuke website instead of wordpress.

      I have tried messing around with it myself a little bit but im not sure if its permissions holding me up, database issues or what. Not able to complete the php install.

      I would be willing to put the guide together if we can figure it out.

    131. iceflatline Says:

      Blake, thanks for you comment. Boy I sure wish I could help but I have no experience with PHP Nuke. If I get any free time at all I’ll try to install it. As a suggestion you might consider posting your question to the FreeBSD mailing list or its IRC channel on freenode.

    132. africall Says:

      thanks, i used this guide to install apache, mysql and php to my freebsd.

    133. Ismael Duarte Says:

      I’ve followed all and it works fine. But I’ve a small issue.
      Everytime I do “pkg upgrade” it try to remove all php70 extensions and install php56

      root@PHPui:~ # pkg upgrade
      Updating FreeBSD repository catalogue…
      FreeBSD repository is up to date.
      All repositories are up to date.
      Checking for upgrades (111 candidates): 100%
      Processing candidates (111 candidates): 100%
      Checking integrity… done (2 conflicting)
      – php56-5.6.32 conflicts with php70-7.0.26_2 on /usr/local/bin/php
      – php56-gd-5.6.32 conflicts with php70-gd-7.0.26_2 on /usr/local/include/php/ext/gd/gdcache.h
      Checking integrity… done (0 conflicting)
      The following 38 package(s) will be affected (of 0 checked):

      Installed packages to be REMOVED:

      New packages to be INSTALLED:
      php56: 5.6.32
      php56-gd: 5.6.32

      Installed packages to be REINSTALLED:
      pecl-pdflib-4.1.2 (direct dependency changed: php56)

      Number of packages to be removed: 35
      Number of packages to be installed: 2
      Number of packages to be reinstalled: 1

      The operation will free 14 MiB.

      Proceed with this action? [y/N]: n
      what can I do?

    134. iceflatline Says:

      Ismael, I’m not sure why pkg is removing php70. However, if you installed it from ports then I recommend using a ports tool, like portmaster, to keep it and any other applications installed from ports updated. You can then “lock” those ports using pkg lock to prevent pkg from trying to update them when updating your packages. See the man page. Alternatively you could simply install php70 from packages instead of ports.

    135. Rusty Weaver Says:

      Great tutorial.

      I ran into a snag at “Figure 1”, starting phpmyadmin. Call to undefined function Symfony\Polyfill\Mbstring\iconfv_strpos() in /usr/local/www/phpMyAdmin/vendor/symfony/polyfill-mbstring/Mbstring.php:363 Stack trace. . .
      I’m running FreeBSD 11.1, apache24-2.4.29, mysql57, php72,phpMyAdmin-4.7.6.

      It would seem that there is some kind of problem with symfony. When I run pkg inf|grep symfony, I get pear-channel-symfony-20110701. I can’t help but think I’m missing a php library required for phpMyAdmin.

      Does this ring any bells?

      Thank you,


    136. iceflatline Says:

      Rusty, no, sorry, I’ve not encountered that error before. I assume you also installed the appropriate mod_php* and php*-extensions?

    Leave a Reply