(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-4.6.5.2
- 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:
1 2 |
portsnap fetch portsnap extract |
If the Ports Collection is already installed, make sure to update it:
1 |
portsnap fetch update |
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:
1 2 |
cd /usr/ports/www/apache24 make config-recursive install distclean |
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.
1 |
sysrc apache24_enable=YES |
Now let’s start Apache to make sure it works:
1 |
service apache24 start |
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:
1 2 |
cd /usr/ports/databases/mysql57-server make config-recursive install distclean |
Add the following line to /etc/rc.conf using sysrc:
1 |
sysrc mysql_enable=YES |
And start the mysql server:
1 |
service mysql-server start |
Then set a password for the MySQL root user:
1 |
/usr/local/bin/mysql -u root -p |
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:
1 |
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your-new-password'; |
Enter ‘quit’ to exit the server. You may now delete /root/.mysql_secret.
Install PHP
Next, we’ll build PHP:
1 2 |
cd /usr/ports/lang/php70 make config-recursive install distclean |
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.
1 2 |
cd /usr/ports/lang/php70-extensions/ make config-recursive |
In the corresponding menu you should select “MYSQLI”, then proceed with building the port:
1 |
make install distclean |
Now let’s add the module required to support PHP applications on Apache:
1 2 |
cd /usr/ports/www/mod_php70 make config-recursive install distclean |
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:
1 2 |
cd /usr/ports/databases/phpmyadmin/ make config-recursive install distclean |
Configuration
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 http://php.net/manual/en/security.php.
1 |
cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini |
Now let’s configure Apache. Open the file /usr/local/etc/apache24/httpd.conf and look for the following line:
1 |
DirectoryIndex index.html |
And change it so it reads as follows:
1 |
DirectoryIndex index.html index.php |
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
<FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> Alias /phpmyadmin "/usr/local/www/phpMyAdmin" <Directory "/usr/local/www/phpMyAdmin"> Options None AllowOverride None Require all granted </Directory> |
Now restart Apache:
1 |
service apache24 restart |
That’s it for our Apache configuration. Now let’s configure phpMyAdmin. We’ll do this by creating the file /usr/local/www/phpMyAdmin/config.inc.php, the basic configuration file for phpMyAdmin. Traditionally, users have manually created or modified /usr/local/www/phpMyAdmin/config.inc.php, 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:
1 |
mkdir /usr/local/www/phpMyAdmin/config && chmod o+w /usr/local/www/phpMyAdmin/config |
Then make /usr/local/www/phpMyAdmin/config.inc.php readable by the phpMyAdmin setup script:
1 |
chmod o+r /usr/local/www/phpMyAdmin/config.inc.php |
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 config.inc.php) and remove “root” from the “User for config auth”(See 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/config.inc.php. Now let’s move that file up one directory to /usr/local/www/phpMyAdmin where phpMyAdmin can make use of it.
1 |
mv /usr/local/www/phpMyAdmin/config/config.inc.php /usr/local/www/phpMyAdmin |
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/config.inc.php:
1 2 |
rm -r /usr/local/www/phpMyAdmin/config chmod o-r /usr/local/www/phpMyAdmin/config.inc.php |
And wrap up by restarting the Apache and MySQL servers:
1 2 |
service apache24 restart service mysql-server restart |
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:
1 2 3 |
cd ~ fetch http://wordpress.org/latest.tar.gz tar -zxvf latest.tar.gz |
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:
1 |
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php |
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:
1 2 3 4 5 6 7 8 9 |
// ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'root'); /** MySQL database password */ define('DB_PASSWORD', 'your-mysql-password'); |
Now move the wordpress directory to Apache’s document root:
1 |
mv ~/wordpress/ /usr/local/www/apache24/data/ |
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.
Common problems
An error that occasionally pops up when attempting to start the Apache server is the following:
1 2 3 |
httpd: apr_sockaddr_info_get() failed for <some-host-name> httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName /usr/local/etc/rc.d/apache24: WARNING: failed to start apache24 |
This can be fixed by adding the following line to /usr/local/etc/apache24/httpd.conf:
1 |
ServerName localhost:80 |
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!
Conclusion
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.
References
http://caffetine.org/freebsd-amp.php
Nice tutorial…. thanks !!!
Thanks a lot for this tutorial! It helped me a lot. :)
airjure, you’re welcome. Thanks for the comment.
This is just what I am looking for. It is so much easier with layouts and color code. Thank you.
Jayson: Thanks for your kind comments.
Great stuff!
Perfect, best current guide out there, really. thanks a lot!
Johannes, glad it was helpful. Thanks for the kind words.
Thank you for the hint on the
“local file (7229347 bytes) is longer than remote file (5324905 bytes)”
error.
That fixed my problem when trying to upgrade Apache.
DrTebi: Great! Glad it worked.
Excellent tutorial. Worked perfect!
Jayr, awesome! Thanks for posting your comment.
Hello,
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!
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.
thank U sir!
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.”
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?
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.
Suggestions?
Thank you in advance.
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.”
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 http://pastebin.com/74X4k0MD in case it might be helpful to you.
Good luck and let me know what you find out.
Hiya.
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?
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…
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
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.
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.
Thanks.
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.
Charles, thanks for taking the time to verify, and apologies again for the hassle.
Thank you very much!
ronjns, you’re welcome. Thanks for the comment.
Excelente tutorial, muy completo, enhorabuena.
Saludos.
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?
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…
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.
Gerald, good advice. Thanks for sharing it.
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. :)
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.
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.
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.
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.
Cheers.
Hi, Anybody can help Pls.
After Follow >> mv /usr/local/www/phpMyAdmin/config/config.inc.php /usr/local/www/phpMyAdmin and will try again then not show anything
Help me ple.
Somsak
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.
i have problem regarding this
can someone help me??
stop in /usr/ports/archivers/php5-zip
this happen i try to built phpmadmin ports
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
[/shell]
Thanks a lot for this nice tutorial. It helps me to integrate newly created jail on nas4free with a webserver.
chaoman, you’re very welcome. Thanks for the kind words.
[…] http://www.iceflatline.com/2011/11/how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd/ […]
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
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…
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
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
</Directory>
[/text]
nice how to, ur da best :)
Hi,
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.
re: my previous post. The wordpress url should read http://my.ip.address/wordpress/wp-admin/wp-login.php*
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 .
Sa-weeet. Did the job. Now I can sleep at night again.
Ranzabar, awesome! Glad I was able to help you (hopefully) get a good night of sleep.
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 :)
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
ftp://ftp.gnupg.org/gcrypt/libgpg-error/libgpg-error-1.11.tar.bz2
and here
ftp://ftp.gnupg.org/gcrypt/libgcrypt/libgcrypt-1.5.0.tar.bz2
and put them into /usr/ports/distfiles
also some issues when installing phpMyAdmin, problems with openjdk6, just find it in
/usr/ports/java/openjdk6
then
make install clean
then return to phpMyAdmin and follow instructions as provided here.
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…
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.
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.
nice tutorial, tks.
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
addind
suPHP_Engine on
in httpd.conf.
Just writing it here in case someone lands from google. Both useful.
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.
Just want to thank you for your detail tutorial which helps me a lot
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.
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.
[…] http://www.iceflatline.com/ http://caffetine.org/ […]
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.
Clay, I think you just did. Thanks for adding your knowledge to the discussion.
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 !!!
Icarus, awesome. Glad it worked well for you. Thanks for the kind words.
Nice with this tutorial to get WordPress up and running locally… just working “out of the box” on my FreeBSD 10.0-BETA3.
Cheers,
Harry
Harry, thanks for the kind words. Glad to hear it worked on FreeBSD 10. I have not had a chance to test it yet.
Thanks. Very accurate. The best AMP tutorial I’ve seen so far.
JakDaRippa, thanks very much for the kind words.
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?
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.
Thanks for taking the time to write this up iceflatline. I’ve used it twice to setup two separate servers.
Very well written.
Cheers!
FreeNAS User, thanks for the kind words.
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
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.
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.
Chris, thanks for the update. I’ll revise the post as soon as I can.
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?
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…
Goose, yes indeed, it should be ‘make install clean’. Thanks for alerting me to the error. The post has been updated.
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.
thingle, okay I’ll have a look as soon as I get a moment.
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.
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.
Okay, using the ports and steps described in the post I encountered no issues. I’ll try again using PHP 5.6.
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.
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 http://www.ebbmar.com/?p=258)
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.
Jay
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!
therooster, Great! glad it worked for you. Thanks for commenting.
Jay, I’m glad you got all working.
By the way, I reinstalled using the following ports:
www/mod_php56
lang/php56/
lang/php56-extensions
Everything worked as expected, so I have updated the post to reflect these new ports.
[…] thanks to ‘iceflatline’ (http://www.iceflatline.com/2011/11/how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd/) for his write-up on putting this all […]
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.
naugehyde, good to know! Thanks for sharing this.
noob question here:
how do i change an option from the install options?
mat, I’m not sure I understand the question. Which install options are you referring to?
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.
Gotcha. Thanks for letting me know.
Great tutorial. Thank you so much! I performed this in a FreeNAS portjail and works brilliantly!
Ankur, good to hear! Thanks for letting me know.
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.
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.
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!
bish, you’re very welcome. And thanks for the kind words.
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
Gary
Thanks heaps for this tutorial, you’ve been a lifesaver. Now I can play with wordpress to my heart’s content.
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.
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?
Garyjg269. No. ownCloud is a self-hosted file sync and share server based on Linux. It’s not really a web server.
Hi and thanks for the reply… what I was meaning is what others have done, install owncloud into a jail.
ref link https://forums.freenas.org/index.php?threads/how-to-owncloud-using-nginx-php-fpm-and-mysql.17786/
https://forums.freenas.org/index.php?threads/drkks-definitive-guide-to-installing-owncloud-in-freenas-or-freebsd.19605/
but I’ve love to use your install…
Thanks,
Gary
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?
Fantastic! Everything worked flawlessly. Thank you for the wonderful tutorial.
Scott, great! Glad it worked well for you.
[…] 1. how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd […]
it’s great!
But it’s out-of-date.
Now, there is PHP 7.0.x.
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 ??
FWIW, apache24 is working fine, MySQL appears to be working fine, PHP appears to be working fine as far as a php.info 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.
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?
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.
Pim, thanks. Are you installing databases/mysql57-server or an older version?
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!
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 https://www.freebsd.org/doc/handbook/network-ftp.html.
Thanks for the great tutorial, worked great.
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.
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.
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.
thanks, i used this guide to install apache, mysql and php to my freebsd.
Regards
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:
php70-zlib-7.0.26_2
php70-zip-7.0.26_2
php70-xmlwriter-7.0.26_2
php70-xmlreader-7.0.26_2
php70-xml-7.0.26_2
php70-tokenizer-7.0.26_2
php70-sqlite3-7.0.26_2
php70-simplexml-7.0.26_2
php70-session-7.0.26_2
php70-posix-7.0.26_2
php70-phar-7.0.26_2
php70-pdo-7.0.26_2
php70-openssl-7.0.26_2
php70-opcache-7.0.26_2
php70-odbc-7.0.26_2
php70-mysqli-7.0.26_2
php70-mcrypt-7.0.26_2
php70-mbstring-7.0.26_2
php70-json-7.0.26_2
php70-iconv-7.0.26_2
php70-hash-7.0.26_2
php70-gd-7.0.26_2
php70-ftp-7.0.26_2
php70-filter-7.0.26_2
php70-fileinfo-7.0.26_2
php70-exif-7.0.26_2
php70-dom-7.0.26_2
php70-curl-7.0.26_2
php70-ctype-7.0.26_2
php70-calendar-7.0.26_2
php70-bz2-7.0.26_2
php70-bcmath-7.0.26_2
php70-7.0.26_2
php70-pdo_sqlite-7.0.26
php70-extensions-1.1
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?
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.
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,
-Rusty
Rusty, no, sorry, I’ve not encountered that error before. I assume you also installed the appropriate mod_php* and php*-extensions?
[…] 1. how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd […]