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.

Share and contribute or get technical support and help at My Digital Life Forums.



24 Responses to “Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - Part 5”

  1. Bruce
    May 24th, 2006 10:23
    1

    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

  2. Administrator
    May 24th, 2006 10:30
    2

    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

  3. Bruce
    May 24th, 2006 11:54
    3

    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?

  4. Administrator
    May 24th, 2006 16:01
    4

    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.

  5. Administrator
    May 24th, 2006 16:11
    5

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

  6. Klaus
    May 29th, 2006 20:59
    6

    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

  7. Ahmet
    June 4th, 2006 10:48
    7

    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

  8. Ryan
    June 7th, 2006 05:21
    8

    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?

  9. Guilt
    June 9th, 2006 20:41
    9

    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!

  10. Administrator
    June 9th, 2006 20:59
    10

    Thanks for point out, has since corrected the error.

  11. Anonymous
    August 28th, 2006 10:55
    11

    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’

  12. GHOSt
    September 26th, 2006 16:37
    12

    I’ve Done it successfully. It doesnt work..

    How do i access it?

    ive typed http://192.168.1.9

  13. Ben
    November 29th, 2006 10:32
    13

    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

  14. Administrator
    November 29th, 2006 12:35
    14

    Thanks Ben, have since corrected the error.

  15. Wadeski
    January 6th, 2007 16:50
    15

    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!!

  16. Cedric
    January 9th, 2007 22:05
    16

    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.

  17. iKriz
    March 16th, 2007 08:28
    17

    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…

  18. iKriz
    March 16th, 2007 08:36
    18

    reinstall was unsuccessful

  19. Ryan
    April 18th, 2007 05:40
    19

    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 =)

  20. Ryan
    April 18th, 2007 05:42
    20

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

    Long day =0

  21. Bob Davis
    September 14th, 2007 17:03
    21

    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.

  22. nmow
    November 30th, 2007 09:57
    22

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

  23. Stefan Nolde
    December 11th, 2007 20:53
    23

    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.

  24. Ferco
    May 10th, 2008 01:44
    24

    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 ¬¬

Leave a Reply

You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe without commenting


Custom Search

New Articles

Incoming Search Terms for the Article

freeBSD php - php freebsd - freebsd apache mysql php - freebsd apache - apache2 freebsd - freebsd apache php mysql - freebsd apache2 - freebsd apache php - freebsd php5 - freebsd apache mysql - apache freebsd - apache php mysql freebsd - freebsd apache2 php5 - php apache freebsd - php5 freebsd - apache php freebsd - freebsd apache php5 - freebsd apache22 php5 - apache php5 freebsd - apache2 php5 freebsd - freebsd apache22 php - freebsd php mysql - apache mysql php freebsd - install php freebsd - freebsd apache2 php - installing apache on freebsd - freebsd php apache - php5 apache2 freebsd - libphp5.so freebsd - apache2 php freebsd - apache22 php - php5 apache freebsd - installing apache freebsd - freeBSD php5-extensions - install php5 freebsd - freebsd mysql php apache - install php on freebsd - freebsd apache install - freebsd install apache - apache22 php5 - download apache for freebsd - freebsd install apache2 - apache 2.2 php5 freebsd - apache22 php5 freebsd - freebsd install apache php - freebsd php5 apache2 - php mysql freebsd - freebsd php extensions - php on freebsd - Apache2 on FreeBSD - freebsd install apache php mysql - freebsd php5 apache22 - php for freebsd - install apache freebsd - apache mysql freebsd - freebsd libphp5.so - apache22 php freebsd - freebsd php install - apache 2.2 php freebsd - installing php on freebsd - all - freebsd install php5 - freebsd mysql apache php - FreeBSD apache 2.2 PHP5 - freebsd php port - install apache PHP mysql freebsd - freebsd php5 apache - download apache freebsd - Installing Web Server in FreeBSD 6.0 with Apache 2.2, MySQL 5.0 and PHP 5 - FreeBSD libphp5 - how to install php on freebsd - freebsd php mysql apache - install php apache freebsd - FreeBSD + Apache - freebsd php5 port -