Apr 14, 2006
My Digital Life Editorial Team

Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 5

Installing Apache 2.2, MySQL 5 and PHP 5 in FreeBSD 6.0 for a Reliable Web Server

Part 5 – Installing PHP Hypertext Preprocessor Scripting Language 5 and PHP 5 Extensions

  1. Install by enter the following commands on FreeBSD OS command line, wait for previous command to finish before running the next command:

    cd /usr/ports/lang/php5
    make install clean

  2. If you’re prompted, select “use Apache 2.x instead”.
  3. Continue with the following commands to install PHP5 extensions and modules to enable the support of the modules in Apache:

    cd /usr/ports/lang/php5-extensions
    make config

  4. At Options for php5-extension 1.0 menu, select all PHP extensions and modules that you may use with Apache webserver. This is a part of the configuration for PHP, where you need to enable features of PHP that come in modules, such as ability to manage user sessions, interface with databases and many others. Default extensions such as ctype functions support, HASH Message Digest Framework support, session support and etc have been selected. Other popular extensions that you most likely to be in used are MySQL database support and GD library support. Use space bar to select or unselect the extensions and press Enter when done.
  5. Continue the installation of php5-extensions with the following commands:

    make install clean

  6. If there are any message the pops up and prompts you to select some options or configurations, you can just accept the default settings by pressing Enter. Some modules that may prompt you for action include php5-gd, php5-mbstring and php5-sqlite.
  7. Edit the Apache configuration file in order to enable Apache web server to load the PHP modules when initialization:
    1. Go to Apache configuration file location by cd /usr/local/etc/apache2/
    2. Edit Apache configuration file by vi httpd.conf
    3. Search for LoadModule lines, after the last LoadModule line, but within the same section, add the following 2 lines:

      AddType application/x-httpd-php .php
      AddType application/x-httpd-php-source .phps

  8. Optionally, copy /usr/local/etc/php.ini-recommended or /usr/local/etc/php.ini-dist to /usr/local/etc/php.ini (in same directory), which will enable you to tune and change the default settings of behaviours of PHP.
  9. Start the Apache HTTP web server by using apachectl start (or restart Apache HTTP web server by using apachectl restart). apachectl is located in /usr/local/sbin, if you encounter Command not found problem, try to change directory to its location.
  10. PHP5 installation done.

A web server has been setup with the FreeBSD with Apache, MySQL and PHP. The document root of the web server (where you should put your HTML and PHP files is at /usr/local/www/apache22/data/ and you will need a SecureFTP (SFTP) client such as WinSCP to upload your files to web server securely.

Related posts:

  1. Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 4
  2. Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 3
  3. Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 2
  4. Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 – Part 1
  5. Install Web Server in Windows XP with Apache2, PHP5 and MySQL4 – Part 3

28 Comments

  • I would also change the AddType lines to AddHandler. AddType is not meant for serverside.

  • This php setup doesn't support mysql element. Drupal can't detect that mysql is running… I hope this could be modified and be of help to others.

  • This is a fine series of articles!

    The only real change I would suggest is executing portsnap or cvsup after the base installation, before installing apache, mysql and php.

  • i have been spent M*N*F (>=28972387) hours to figure out why PHP source did not get interpreted. It's end up to short_open_tag has to be turned on if you are using <?. Good luck guys.

  • Lol, you should put this somewhere…

    Befor testing… REBOOT! XD

    30 minutes lost trying to fix apache + php and all that was required was reboot ¬¬

  • Should the problem with downloadable sourcecodes exist for anyone else, if it was just a problem occurring from localhost, changing the listening port from the default 80 to *:80 might help. It is highly likely that in the above mentioned cases Apache had not much to do with serving the files on localhost.

    Fedora does not have less dependancies, they are just handeld elswehere out of user eyes.

    Understanding the package & port system and when and why to update is part of the game.

    For those who go for Fedora on servers, you might opt for ubuntu instead. it's easy and fast as well as free.

  • This series of articles has been very, very helpful. Many thanks for your contribution!

  • I've been trying to install Timetrex and it requires Apache, php and postgresql. Postgresql is not a problem because I install it from source. But as you can see from above, the FreeBSD ports system is so often in a state of flux that you're not guaranteed anything that will work.

    On this issue, the bosses, and I myself got so fed up with the results from FreeBSD that we installed Fedora and then took the vendors installation file, which only works on Linux and got on with the task.

    With so many dependencies and librairies to update, the FreeBSD ports system as left me feeling very cautious about using it and it harkens me back to the old M$ "dll – hell" days when Windows 3x and Win9x were such a pain to deal with.

  • edit.. I meant " .. would treat PHP files as text files .." and not CGI.

    Long day =0

  • I uninstalled, reinstalled making double sure to include the Apache model, still no dice. So I uninstalled again and reinstalled without CLI and CGI and it still would startup no errors, but it would list the directories in document source and would treat cgi files as text files. All my configs were in order, so I thought maybe it needed a reboot… and walah. Working like a charm.

    I think Unix is for massochists =)

  • reinstall was unsuccessful

  • Trying to install the package php5 without port sources via

    pkg_add -r php5

    only this doesnt install the apache module by the looks of it..

    nor does it build it..

    I dont want the sources on the server because it is to be a production server.. i'm gunna try a reinstall…

  • I had same issue.

    Try make config and unselect CGI and be sure to select APACHE.

    Check at end of install that you have a line like:chmod 755 /usr/local/libexec/apache22/libphp5.so

    I config without CLI ang CGI.

  • I'm running into the same issue. My php files are trying to download instead.

    I've gone over everything three and four times yet nothing.

    I've checked the additional spaces as well and no luck.

    Any assistance is appreciated!!

  • Thanks Ben, have since corrected the error.

  • Had run into the same problem as those above with the extra spaces in the AddType declaration but solved it before looking at the comments. Would recommend updating the article as, all in all, this is a great tutorial. Thanks.

    Ben

  • I've Done it successfully. It doesnt work..

    How do i access it?

    ive typed http://192.168.1.9

  • Recompile php5 with 'Apache Module' included.

    'cd /usr/ports/lang/php5'

    'make deinstall' ignore warnings

    'make config' make sure to select apache module

    'make install'

  • Thanks for point out, has since corrected the error.

  • Ahmet gave a working answer. I was having the same problems, until I noticed the extra space before the file extention, now everything works like a charm!

  • I'm having the same problem as Bruce above. I'm using FreeBSD 6.1, Apache 2.2, and PHP 5.1.4. My ports tree is fresh and synched.

    I installed the PHP5 port with Apache module support. The installation completes without complaining, but there is no Apache module built. The file /usr/local/libexec/apache22/libphp5.so does not exist. It doesn't exist anywhere else in the filesystem either. Something is broken with this port. I see source files in the work directories , like /usr/ports/lang/php5/work/php-5.1.4/sapi/apache that look appropriate to this module… but are not getting compiled. Any insights?

  • When you add the following lines to httpd.conf file, make sure you removed the extra spaces (there are 2 extra spaces in the original article, following doesnt't have).

    AddType application/x-httpd-php .php

    AddType application/x-httpd-php-source .phps

  • You might missed to install the php for apache, only cgi and cli.

    CD /usr/ports/php5

    make config

    then

    make install clean

    mayby you have to do

    make deinstall && make reinstall

  • Beside, make sure you updated to latest ports tree with portsnap or cvsup.

  • Hi Bruce, you may give mod_php5 a try, but I think you will lose some functionalities such as command line CLI. Or else try to make clean in php5 first. Reinstalling from Apache again worth a try too. Note that you should install Apache first, and php5 will detect which version of Apache you're running.

  • Yes, I certainly did add the AddType's

    the php5 port installation did not auto update httpd.conf with 'LoadModule php5_module libexec/apache22/libphp5.so'. I would manually add it but the libphp5.so does not exist in the mentioned directory. Any idea's? I installed from the /usr/ports/lang/php5 port. I heard using /usr/ports/www/mod_php5 port may work. Would/should it make any difference?

  • Did you add the followng lines to your httpd.conf?

    AddType application/x- httpd-php . php

    AddType application/x- httpd-php-source . phps

    Normally, ports installation will auto update the httpd.conf with php5 load module. Check if your httpd.conf has the following line, if not try to add:

    LoadModule php5_module libexec/apache22/libphp5.so

  • Hi, I am trying to install, php5 with apache2.2 on freebsd 6.1. I have followed the instructions on this page. I can get apache running well, but php will not interpret any pages. I have a file; info.php with in it, but when I load it from a browser it tries to *download* the php file not display it. Furthermore, the httpd.conf does not have a entry to load the php module as a shared object. should it? its as if apache has not idea how to process php's. Any guideance would be appreciated!

    kind regards

Leave a comment

Notify me of followup comments via e-mail. You can also subscribe without commenting.

Subscribe

Free email subscriptions
Get latest updates in email for free:

Translate This Page