{"id":3514,"date":"2014-04-11T00:24:52","date_gmt":"2014-04-11T05:24:52","guid":{"rendered":"http:\/\/icesquare.com\/wordpress\/?p=3514"},"modified":"2015-02-20T13:58:21","modified_gmt":"2015-02-20T19:58:21","slug":"freebsdphp-does-not-work-after-upgrading-apache-to-2-2-27","status":"publish","type":"post","link":"https:\/\/icesquare.com\/wordpress\/freebsdphp-does-not-work-after-upgrading-apache-to-2-2-27\/","title":{"rendered":"[FreeBSD]PHP does not work after upgrading Apache to 2.2.27"},"content":{"rendered":"<p>I upgraded the Apache to 2.2.27 on my FreeBSD box via portmaster. The upgrade went very smooth. After the upgrade, I found that Apache no longer rendered the PHP page correctly. In the other words, it displayed the source code of the PHP files instead of executing the code.<\/p>\n<p>Before you start doing anything, please make sure that your website is not accessible from public. For example, most web applications like to include the password information in the source code, which is accessible by public if the PHP engine is failed. You may want to restrict the public access during the fix. The easiest way is to set up a .htaccess file and restrict the access by IP address.<\/p>\n<p>Let&#8217;s come back to the fix. For some reasons, Apache\/PHP team decide to make something fun to the FreeBSD sysadmin, because they think FreeBSD sysadmin have plenty of spare time. Here is what they decide to do:<\/p>\n<p>Originally, we install Apache first, then we install PHP. When we install the PHP, we pick an option such that the PHP will install a PHP engine used by Apache. In the recent release, they decide to remove the engine from the standard PHP package. For example, if you simply use the portmaster to upgrade your PHP (In my case, PHP 5.4 and 5.5), the engine will be missing. That&#8217;s why Apache fails to render the PHP files.<\/p>\n<p>Here is what you will need to do. I suggest you to finish reading the following before doing the fix. Trust me. It may save you couple hours.<\/p>\n<p>First, make sure that Apache is working fine.<\/p>\n<p>If you are using PHP 5.4, make sure that you install this port: <strong>\/usr\/ports\/www\/mod_php5<\/strong>. If you are using PHP 5.5, install this one instead: <strong>\/usr\/ports\/www\/mod_php55<\/strong>. Make sure that you select the ZTS option. You can do it by running:<\/p>\n<pre>\r\nsudo make config\r\n<\/pre>\n<p>Notice that installing this port will reinstall the PHP package (\/usr\/ports\/lang\/php5 or \/usr\/ports\/lang\/php55). Make sure that the ZTS option is selected in PHP package as well.<\/p>\n<p>Now try to restart the Apache server. That should make the Apache to render the PHP files instead of dumping it.<\/p>\n<pre>\r\n#sudo \/usr\/local\/etc\/rc.d\/apache stop\r\n#sudo \/usr\/local\/etc\/rc.d\/apache start\r\n<\/pre>\n<p>Test the PHP files again. If you see the PHP result instead of PHP source code, congratulations! You are 20% done.<\/p>\n<p>Now go back to the command line and run the following:<\/p>\n<pre>\r\n#List the PHP extensions installed by PHP \r\nphp -m\r\n\r\n#Check whether the PHP extensions are loaded properly by PHP\r\nphp -v\r\n<\/pre>\n<p>For some reasons, I noticed that many extensions were missing during the reinstallation, such as sessions, json etc. Let&#8217;s install them back:<\/p>\n<pre>\r\n#For PHP 5.4\r\ncd \/usr\/ports\/lang\/php5-extensions\r\n\r\n#For PHP 5.5\r\ncd \/usr\/ports\/lang\/php55-extensions\r\n\r\n\r\nsudo make reinstall clean\r\n<\/pre>\n<p>Don&#8217;t forget the pecl and related packages as well. After that, try to restart your Apache server and clean up the php extension configuration:<\/p>\n<pre>\r\nnano \/usr\/local\/etc\/php\/extensions.ini\r\n<\/pre>\n<p>You will see a mess. Try to clean up the duplicated extensions and run the php -m and php -v again.<\/p>\n<p>During the fix, I notice that everything works fine except for MySQL package. Interestingly, when I ran php -m, the mysql was available. However when I ran phpinfo(), it was missing. I found that this problem only happens with PHP 5.4, but not PHP 5.5. Therefore, I decided to remove the PHP 5.4 and loaded PHP 5.5 instead.<\/p>\n<p>Simply repeat the installation and restart the server. If possible, try to reboot the machine. <\/p>\n<p>So here is the summary:<\/p>\n<ol>\n<li>Remove PHP, Extensions and PECL packages (sudo make deinstall).<\/li>\n<li>Restart Apache (sudo \/usr\/local\/etc\/rc.d\/apache stop; sudo \/usr\/local\/etc\/rc.d\/apache start).<\/li>\n<li>Verify installed extensions with php -m; php -v; and phpinfo().<\/li>\n<li>Verify the result by loading the pages on the web.<\/li>\n<li>If your page is failed, try to find out which extension is missing by checking the error log, which is typically available in in \/var\/log\/<\/li>\n<\/ol>\n<p>Hope my solutions help!<\/p>\n<p>&#8211;Derrick<\/p>\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I upgraded the Apache to 2.2.27 on my FreeBSD box via portmaster. The upgrade went very smooth. After the upgrade, I found that Apache no longer rendered the PHP page <a class=\"more-link\" href=\"https:\/\/icesquare.com\/wordpress\/freebsdphp-does-not-work-after-upgrading-apache-to-2-2-27\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[94,7,144,6,69],"tags":[8,171,172],"class_list":["post-3514","post","type-post","status-publish","format-standard","hentry","category-computer-problems-computer-help-pc-support","category-freebsd","category-sever-problem","category-technology","category-troubleshooting-technology","tag-apache","tag-freebsd","tag-php"],"jetpack_publicize_connections":[],"jetpack_shortlink":"https:\/\/wp.me\/p1sqzr-UG","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":3925,"url":"https:\/\/icesquare.com\/wordpress\/freebsdupgrade-php-5-5-to-5-6\/","url_meta":{"origin":3514,"position":0},"title":"[FreeBSD]Upgrade PHP 5.5 to 5.6","author":"Derrick","date":"February 20, 2015","format":false,"excerpt":"It is not easy to upgrade PHP 5.5 to 5.6 in FreeBSD. Without proper preparation, the upgrade process may drive you nut. Before you decide to get your hands wet, here are what I recommend you to do: Back up your files Test your website in a PHP 5.6 environment\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":31,"url":"https:\/\/icesquare.com\/wordpress\/installing-apache-php-mysql-and-memcached-on-freebsd\/","url_meta":{"origin":3514,"position":1},"title":"Installing Apache, PHP, MySQL and MemCached on FreeBSD","author":"Derrick","date":"May 19, 2009","format":false,"excerpt":"This is my note on how to to install Apache, PHP, MySQL and MemCached on a FreeBSD 7 Box. 1. MySQL Go to the mysql52-server port directory by typing the command: cd \/usr\/ports\/databases\/mysql51-server Build the port by typing: make BUILD_OPTIMIZED=yes BUILD_STATIC=yes Using these two options will speed up the execution\u2026","rel":"","context":"In &quot;FreeBSD&quot;","block_context":{"text":"FreeBSD","link":"https:\/\/icesquare.com\/wordpress\/category\/sever-problem\/freebsd\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":603,"url":"https:\/\/icesquare.com\/wordpress\/weird-php-error-after-freebsd-port-upgrade\/","url_meta":{"origin":3514,"position":2},"title":"Weird PHP Error after FreeBSD port upgrade (PHP Warning:  PHP Startup: Unable to load dynamic library)","author":"Derrick","date":"April 6, 2010","format":false,"excerpt":"Today I upgraded the port on my FreeBSD box using portmaster tools: portmaster -Dai After that, I found that the PHP gave the following weird error: php -v PHP Warning: PHP Startup: Unable to load dynamic library '\/usr\/local\/lib\/php\/20060613\/memcached.so' - \/usr\/local\/lib\/php\/20060613\/memcached.so: Undefined symbol \" php_session_create_id\" in Unknown on line 0 PHP\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2646,"url":"https:\/\/icesquare.com\/wordpress\/php-imagecreatefrompng-error\/","url_meta":{"origin":3514,"position":3},"title":"[PHP]imagecreatefrompng Error (After upgrading FreeBSD)","author":"Derrick","date":"January 25, 2012","format":false,"excerpt":"Today, I found that one of my PHP scripts stop working. After some investigations, I found that it was the function, imagecreatefrompng, which caused the problem. Interestingly, other similar functions such as imagecreatefromgif and imagecreatefromjpeg were completely working fine. The program stopped working when calling imagecreatefrompng only. [ad#adbrite-square] Initially, I\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":376,"url":"https:\/\/icesquare.com\/wordpress\/updated-what-technologies-or-toys-i-am-playing-recently\/","url_meta":{"origin":3514,"position":4},"title":"Updated: What technologies (or toys) I am playing recently?","author":"Derrick","date":"November 16, 2009","format":false,"excerpt":"Recently I am playing the following technologies (toys): Tornado Web - Not sure how long will Apache + PHP last. Time to learn Python. Tokyo Cabinet & Tyrant - Another one of my long term plans to step away from SQL. PHP API for Tokyo Tyrant -- I decide to\u2026","rel":"","context":"In &quot;Fun Stuffs&quot;","block_context":{"text":"Fun Stuffs","link":"https:\/\/icesquare.com\/wordpress\/category\/fun\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":462,"url":"https:\/\/icesquare.com\/wordpress\/tornado-web-very-fast\/","url_meta":{"origin":3514,"position":5},"title":"Tornado Web Server &#8211; Very Fast!","author":"Derrick","date":"November 29, 2009","format":false,"excerpt":"I just did a benchmark comparison on Tornado Web Server and Apache + PHP server. The result is pretty amazing. What to test: A simple Hello World application. How: ab -n 1000 -c 300 http:\/\/myserver.ip Test Environment OS: FreeBSD 7.1 CPU: Pentium III 933 MHz Ram: 256 MB PHP: 5.2.9\u2026","rel":"","context":"In &quot;Computer Problems&quot;","block_context":{"text":"Computer Problems","link":"https:\/\/icesquare.com\/wordpress\/category\/technology\/computer-problems-computer-help-pc-support\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3514","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/comments?post=3514"}],"version-history":[{"count":13,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3514\/revisions"}],"predecessor-version":[{"id":3935,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/posts\/3514\/revisions\/3935"}],"wp:attachment":[{"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/media?parent=3514"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/categories?post=3514"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/icesquare.com\/wordpress\/wp-json\/wp\/v2\/tags?post=3514"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}