{"id":84,"date":"2009-12-23T23:31:10","date_gmt":"2009-12-24T06:31:10","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=84"},"modified":"2009-12-23T23:31:10","modified_gmt":"2009-12-24T06:31:10","slug":"installing-php-5-on-freebsd","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2009\/12\/23\/installing-php-5-on-freebsd\/","title":{"rendered":"Installing PHP 5 on FreeBSD"},"content":{"rendered":"<p>A tutorial on installing PHP from the FreeBSD ports for Apache and MySQL.<\/p>\n<p>What you need to add to the httpd.conf file and which of the PHP5 ports to choose.<\/p>\n<p>Choosing which port to use<br \/>\nIn the past there were several ports for PHP such as \/www\/mod-php5, \/lang\/php5-cli, and \/lang\/php5. Since the release of PHP 5.1.14 there is now only \/lang\/php5 This port now allows you to choose if you want to install the CLI, CGI, and Apache module.<br \/>\nCLI stands for command line interpreter. It is used for running PHP scripts from the command line and makes creating shell scripts very simple if you already know PHP. The Apache PHP Module is disabled by default, so make SURE that if you plan to use this for web work that you enable it.<br \/>\nInstalling the port<br \/>\nSince all PHP ports are now combined you will need to configure it to be sure the parts you need are built.<br \/>\n# cd \/usr\/ports\/lang\/php5<br \/>\n# make config<br \/>\n# make install<br \/>\nWhen you run make config you will be shown a list of options. To use PHP with Apache make sure the Apache Module box is selected.<br \/>\nOnce php has installed you will need to install the extra modules for things such as MySQL. These modules are all located in the ports. Some of the most common modules are<br \/>\n\/usr\/ports\/databases\/php5-mysql &#8211; MySQL Database<br \/>\n\/usr\/ports\/www\/php5-session\u00a0\u00a0\u00a0 &#8211; Sessions<br \/>\n\/usr\/ports\/graphics\/php5-gd &#8211; Graphics Library<br \/>\nAdding the PHP 5 module to Apache<br \/>\nApache needs the following lines in the httpd.conf file to use php. These lines should already be added by the port but if you have problems you should double check your httpd.conf file. Note that Apache 2.x does not need the AddModule line.<br \/>\n# Apache 1.3.x<br \/>\nLoadModule php5_module\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 libexec\/apache\/libphp5.so<br \/>\nAddModule mod_php5.c<br \/>\n# Apache 2.x<br \/>\nLoadModule php5_module\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 libexec\/apache\/libphp5.so<br \/>\nIf you installed using the port and had apache installed already it should do this automatically for you.<br \/>\nNext find your DirectoryIndex section in your httpd.conf file. Apache is set up for PHP 4, but not PHP 5 currently so you will need to modify it and change the 4s to 5s like this.<br \/>\n&lt;IfModule mod_dir.c&gt;<br \/>\n&lt;IfModule mod_php3.c&gt;<br \/>\n&lt;IfModule mod_php5.c&gt;<br \/>\nDirectoryIndex index.php index.php3 index.html<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;IfModule !mod_php4.c&gt;<br \/>\nDirectoryIndex index.php3 index.html<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;IfModule !mod_php3.c&gt;<br \/>\n&lt;IfModule mod_php5.c&gt;<br \/>\nDirectoryIndex index.php index.html index.htm<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;IfModule !mod_php4.c&gt;<br \/>\nDirectoryIndex index.html<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;\/IfModule&gt;<br \/>\n&lt;\/IfModule&gt;<br \/>\nThis code is telling Apache to open index.php first you have the PHP 5 module loaded. You can change the order as you wish. Or if you just wanted to skip it you could simply add the following line to the httpd.conf file since you know you are going to have php 5.<br \/>\nDirectoryIndex index.php index.html index.htm<br \/>\nNow apache just needs to know what it should parse the PHP files with. These two lines should be added to the httpd.conf file, and can be put at the bottom if needed.<br \/>\nAddType application\/x-httpd-php .php<br \/>\nAddType application\/x-httpd-php-source .phps<br \/>\nIf want to use PHP code inside of .htm files you can just add on those extensions.<br \/>\nAddType application\/x-httpd-php .php .htm .html<br \/>\nConfiguring PHP<br \/>\nSettings for PHP are stored in \/usr\/local\/etc\/php.ini You will need to create this file by copying it from \/usr\/local\/etc\/php.ini-dist<br \/>\n# cp \/usr\/local\/etc\/php.ini-dist \/usr\/local\/etc\/php.ini<br \/>\nIn this file you can set the memory limit for programs. Turn on global variables if you must, set the max file upload size, and everything else you need.<br \/>\nTesting PHP<br \/>\nOnce you have restarted Apache so the changes take effect you are ready to test it. To test it run the following command to create a php file that you can attempt to run<br \/>\n# echo &#8220;&lt;? phpinfo(); ?&gt;&#8221; &gt;&gt; \/usr\/local\/www\/data\/test.php<br \/>\nThen point your web browser to http:\/\/yourdomain.com\/test.php and if it works you will see several pages of information on your PHP settings. If it did not work you will see only the text you typed in.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>A tutorial on installing PHP from the FreeBSD ports for Apache and MySQL. What you need to add to the httpd.conf file and which of <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2009\/12\/23\/installing-php-5-on-freebsd\/\" title=\"Installing PHP 5 on FreeBSD\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[27,36,127,149,200,203,257],"class_list":["post-84","post","type-post","status-publish","format-standard","hentry","category-misc","tag-27","tag-amit","tag-freebsd-2","tag-install","tag-php","tag-php5","tag-truelogic"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/84","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=84"}],"version-history":[{"count":0,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/84\/revisions"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=84"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=84"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=84"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}