{"id":426,"date":"2013-01-27T09:20:20","date_gmt":"2013-01-27T12:20:20","guid":{"rendered":"http:\/\/blog.abratel.com.br\/?p=426"},"modified":"2013-01-27T09:38:03","modified_gmt":"2013-01-27T12:38:03","slug":"como-instalar-apache-mysql-php-e-phpmyadmin-no-freebsd","status":"publish","type":"post","link":"https:\/\/blog.abratel.com.br\/?p=426","title":{"rendered":"Como instalar Apache, MySQL, PHP, e phpMyAdmin no FreeBSD"},"content":{"rendered":"<p>Creditos: http:\/\/www.iceflatline.com\/2011\/11\/how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd\/<\/p>\n<p>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\u2019ll be able to use your \u201cAMP\u201d server to do web development, code testing, maintain local copies of your web sites, etc.<\/p>\n<p>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:<\/p>\n<p>FreeBSD 9.1-RELEASE<br \/>\napache22-2.2.23_3<br \/>\nmysql-server-5.5.29<br \/>\nphp5-5.4.10<br \/>\nphp5-extensions-1.7<br \/>\nphpMyAdmin-3.5.5<br \/>\nWordPress v3.5<br \/>\nThe following steps discussed in this post assume you have the FreeBSD Ports Collection installed. If not, you can install it by using the following commands:<\/p>\n<p>portsnap fetch<br \/>\nportsnap extract<br \/>\nIf the Ports Collection is already installed, make sure to update it:<\/p>\n<p>portsnap fetch update<br \/>\nOkay, let\u2019s get started. All commands are issued as the root user or by simulating the root user by using the command su. While building the various ports you should accept all default configuration options unless otherwise instructed.<\/p>\n<p>Install Apache<\/p>\n<p>Navigate to the Apache server port and build it:<\/p>\n<p>cd \/usr\/ports\/www\/apache22<br \/>\nmake install clean<br \/>\nOnce Apache has been successfully installed, add the following line to \/etc\/rc.conf so that the Apache server will start automatically at system boot.<\/p>\n<p>echo &#8216;apache22_enable=&#8221;YES&#8221;&#8216; >> \/etc\/rc.conf<br \/>\nNow let\u2019s start Apache to make sure it works:<\/p>\n<p>\/usr\/local\/etc\/rc.d\/apache22 start<br \/>\nPoint your web browser to the host name or IP address of the FreeBSD host you\u2019ve installed Apache on and you should see the venerable \u201cIt Works.\u201d<\/p>\n<p>Install MySQL.<\/p>\n<p>Now let\u2019s build the MySQL server:<\/p>\n<p>cd \/usr\/ports\/databases\/mysql55-server<br \/>\nmake install clean<br \/>\nAdd the following line to \/etc\/rc.conf:<\/p>\n<p>echo &#8216;mysql_enable=&#8221;YES&#8221;&#8216; >> \/etc\/rc.conf<br \/>\nAnd start the mysql server:<\/p>\n<p>\/usr\/local\/etc\/rc.d\/mysql-server start<br \/>\nThen set a password for the MySQL root user:<\/p>\n<p>\/usr\/local\/bin\/mysqladmin -u root password &#8216;your-password&#8217;<br \/>\nInstall PHP<\/p>\n<p>Next, we\u2019ll build PHP. Before we proceed, however, we need to add a configuration option so that PHP build includes support for the Apache server. Start with the following commands:<\/p>\n<p>cd \/usr\/ports\/lang\/php5<br \/>\nmake config<br \/>\nA menu should come up allowing you to select\/deselect various build options. You should select \u201cBuild Apache module\u201d by highlighting the option with the arrow keys and hitting the space bar, then hit Enter, which should bring you back to the command prompt. Now proceed with building the port:<\/p>\n<p>make install clean<br \/>\nNow let\u2019s add the requisite extensions to PHP to round out its capabilities. Before we build this port though we\u2019ll want to add support for both MySQL and MySQLi (an improved interface to MySQL) in order to communicate with the MySQL server.<\/p>\n<p>cd \/usr\/ports\/lang\/php5-extensions\/<br \/>\nmake config<br \/>\nIn the corresponding menu you should select \u201cMySQL database support\u201d and \u201cMySQLi database support,\u201d then proceed with building the port:<\/p>\n<p>make install clean<br \/>\nInstall phpMyAdmin<\/p>\n<p>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\u2019s nice tool to have. Here again we\u2019ll want to add support for MySQL and MySQLi before building the port:<\/p>\n<p>cd \/usr\/ports\/databases\/phpmyadmin\/<br \/>\nmake config<br \/>\nHere you should ensure that both \u201cMYSQL M(DB_connect): PHP MySQL support via mysql client\u201d and \u201cMYSQLI M(DB_connect) PHP Improved MySQL client support\u201d are selected, then proceed with building the port:<\/p>\n<p>make install clean<br \/>\nConfiguration<\/p>\n<p>Now that we have the requisite ports built and installed it\u2019s time to configure them. First, let\u2019s 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.<\/p>\n<p>cp \/usr\/local\/etc\/php.ini-development \/usr\/local\/etc\/php.ini<br \/>\nNow let\u2019s configure Apache. Open the file \/usr\/local\/etc\/apache22\/httpd.conf in your favorite editor and look for the following line:<\/p>\n<p>DirectoryIndex index.html<br \/>\nAnd change it so it reads as follows:<\/p>\n<p>DirectoryIndex index.html index.htm index.php<br \/>\nThen 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 two AddType lines:<\/p>\n<p>1<br \/>\nAddType application\/x-httpd-php .php<br \/>\n2<br \/>\nAddType application\/x-httpd-php-source .phps<br \/>\n3<\/p>\n<p>4<br \/>\nAlias \/phpmyadmin &#8220;\/usr\/local\/www\/phpMyAdmin&#8221;<br \/>\n5<\/p>\n<p>6<br \/>\n<Directory \"\/usr\/local\/www\/phpMyAdmin\"><br \/>\n7<br \/>\nOptions None<br \/>\n8<br \/>\nAllowOverride None<br \/>\n9<br \/>\nOrder allow,deny<br \/>\n10<br \/>\nAllow from all<br \/>\n11<br \/>\n<\/Directory><br \/>\nAs an optional step, if you\u2019d like to add multilanguage support to Apache, uncomment the following line:<\/p>\n<p>Include etc\/apache22\/extra\/httpd-languages.conf<br \/>\nThen open the language settings file \/usr\/local\/etc\/apache22\/extra\/httpd-languages.conf and add the following line to the end of the file:<\/p>\n<p>AddDefaultCharset On<br \/>\nNow restart Apache:<\/p>\n<p>\/usr\/local\/etc\/rc.d\/apache22 restart<br \/>\nThat\u2019s it for our Apache configuration. Now let\u2019s configure phpMyAdmin. We\u2019ll do this by creating the file \/usr\/local\/www\/phpMyAdmin\/config.inc.php, the basic configuration file for phpMyAdmin. Traditionally, users have manually created 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 phpMyAdmin:<\/p>\n<p>mkdir \/usr\/local\/www\/phpMyAdmin\/config &#038;&#038; chmod o+w \/usr\/local\/www\/phpMyAdmin\/config<br \/>\nThen 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 \u201cNew server\u201d and then select the \u201cAuthentication\u201d tab. Under the \u201cAuthentication type\u201d choose \u201chttp\u201d 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 \u201croot\u201d from the \u201cUser for config auth\u201d(See Figure 1).<\/p>\n<p>Figure 1<br \/>\nNow select \u201cSave\u201d and you will be returned you to the Overview page where you should see a new server listed. Select \u201cSave\u201d again in the Overview page to save your configuration as \/usr\/local\/www\/phpMyAdmin\/config\/config.inc.php. Now let\u2019s move that file to \/usr\/local\/www\/phpMyAdmin where phpMyAdmin can make use of it.<\/p>\n<p>mv \/usr\/local\/www\/phpMyAdmin\/config\/config.inc.php \/usr\/local\/www\/phpMyAdmin<br \/>\nNow let\u2019s 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 \u201croot\u201d 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\u2019s remove it and wrap up by restarting the Apache and MySQL servers:<\/p>\n<p>rm -r \/usr\/local\/www\/phpMyAdmin\/config<br \/>\n\/usr\/local\/etc\/rc.d\/apache22 restart<br \/>\n\/usr\/local\/etc\/rc.d\/mysql-server restart<br \/>\nTesting our installation using WordPress<\/p>\n<p>WordPress is a full-featured website\/blog platform that makes heavy use of Apache, MySQL and PHP. We\u2019ll 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\u2019s start by downloading the latest WordPress directly from the developers site to your home directory and untarring the package:<\/p>\n<p>fetch http:\/\/wordpress.org\/latest.tar.gz<br \/>\ntar -zxvf latest.tar.gz<br \/>\nYou 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\u2019s copy the file ~\/wordpress\/wp-config-sample.php to use as a template:<\/p>\n<p>cp ~\/wordpress\/wp-config-sample.php ~\/wordpress\/wp-config.php<br \/>\nOpen ~\/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:<\/p>\n<p>1<br \/>\n\/\/ ** MySQL settings &#8211; You can get this info from your web host ** \/\/<br \/>\n2<br \/>\n\/** The name of the database for WordPress *\/<br \/>\n3<br \/>\ndefine(&#8216;DB_NAME&#8217;, &#8216;wordpress&#8217;);<br \/>\n4<\/p>\n<p>5<br \/>\n\/** MySQL database username *\/<br \/>\n6<br \/>\ndefine(&#8216;DB_USER&#8217;, &#8216;root&#8217;);<br \/>\n7<\/p>\n<p>8<br \/>\n\/** MySQL database password *\/<br \/>\n9<br \/>\ndefine(&#8216;DB_PASSWORD&#8217;, &#8216;your-mysql-password&#8217;);<br \/>\nNow move the wordpress directory to Apache\u2019s document root:<\/p>\n<p>mv ~\/wordpress\/ \/usr\/local\/www\/apache22\/data\/<br \/>\nNext, let\u2019s create an MySQL database for our WordPress installation. Open phpMyAdmin in your browser and create a database by selecting the \u201cDatabases\u201d tab at the top. Enter a name for it in the \u201cCreate a new database\u201d field. For purposes of our example, I\u2019ll use \u201cwordpress\u201d as the database name. You\u2019re free to use a different database name, just make sure to use the same name in the define(\u2018DB_NAME\u2019, \u2018your-DB-name\u2019); line in ~\/wordpress\/wp-config.php as described above. Then select \u201cCreate.\u201d<\/p>\n<p>Now let\u2019s 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 \u201cInstall WordPress.\u201d Then login with your newly created WordPress credentials and you should be presented with the default WordPress administration page.<\/p>\n<p>Figure 2<br \/>\nCommon problems<\/p>\n<p>You may run into the following error when attempting to build the Apache port:<\/p>\n<p>httpd-2.2.21.tar.bz2 doesn&#8217;t seem to exist in \/usr\/ports\/distfiles\/apache22.<br \/>\n=> Attempting to fetch http:\/\/www.apache.org\/dist\/httpd\/httpd-2.2.21.tar.bz2<br \/>\nfetch: httpd-2.2.21.tar.bz2: local file (7229347 bytes) is longer than remote file (5324905 bytes)<\/p>\n<p>=> port manually into \/usr\/ports\/distfiles\/apache22 and try again.<br \/>\n*** Error code 1<br \/>\nTo fix this problem, simply remove the file from \/usr\/ports\/distfiles\/apache22 (in this case httpd-2.2.21.tar.bz2) and run make config clean again.<\/p>\n<p>Another error that occasionally pops up when attempting to start the Apache server is the following:<\/p>\n<p>httpd: apr_sockaddr_info_get() failed for <some-host-name><br \/>\nhttpd: Could not reliably determine the server&#8217;s fully qualified domain name, using 127.0.0.1 for ServerName<br \/>\n\/usr\/local\/etc\/rc.d\/apache22: WARNING: failed to start apache22<br \/>\nThis can be fixed by adding a line to \/etc\/hosts. First, verify your hostname by running the hostname command:<\/p>\n<p>hostname<br \/>\nThen add the following to \/etc\/hosts:<\/p>\n<p>hostname   IP-address-of-your-freebsd-box<br \/>\nFinally, 403 permission problems seem to frequently pop up when trying to access phpMyAdmin. 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\/apache22\/httpd.conf. As an example, a missing \u201c\/\u201d in the Alias statement cost me two hours of troubleshooting time!<\/p>\n<p>Conclusion<\/p>\n<p>Well, that\u2019s it. A few hours of your time with the FreeBSD Ports Collection and you can a get a fully configured \u201cAMP\u201d web development server up and running on your FreeBSD box.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creditos: http:\/\/www.iceflatline.com\/2011\/11\/how-to-install-apache-mysql-php-and-phpmyadmin-on-freebsd\/ 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\u2019ll be able to use your \u201cAMP\u201d server to do web development, code testing, maintain local copies of your&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/426"}],"collection":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=426"}],"version-history":[{"count":0,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=\/wp\/v2\/posts\/426\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=426"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=426"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.abratel.com.br\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=426"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}