Annotation of wikisrc/pkgsrc/how_to_install_a_lamp_server.mdwn, revision 1.7

1.6       gutterid    1: **LAMP** is a an acronym for a combined set of software to run a web server containing the following software products: **Apache, MySQL, and Perl, Python, or PHP**. The "L" stands for Linux, therefore there is also an acronym named **WAMP** representing the Windows operating system. This also means that the title of this article is misleading. The approach is to install the same combined set of software, but using NetBSD as the operating system instead of Linux. 
1.2       schmonz     2: 
                      3: We will install all components using pkgsrc, building all packages from source. An installation using existing binaries provided by ftp.netbsd.org is not possible. 
                      4: 
                      5: **Contents**
                      6: 
                      7: [[!toc]]
                      8: 
1.6       gutterid    9: #  Installing the Apache web server
1.2       schmonz    10: 
1.4       sevan      11: The new Apache 2.4 server comes with two different threading models from which [prefork](http://httpd.apache.org/docs/2.4/mod/prefork.html) is installed by default. It is **not** recommended to use the Worker model, if you wish to use Apache and PHP. As that is the case, we will install a default Apache 2.4 server. 
1.2       schmonz    12:     
1.5       sevan      13:     # cd /usr/pkgsrc/www/apache24
1.2       schmonz    14:     # make install clean clean-depends
                     15: 
                     16: 
1.6       gutterid   17: This will install the Apache 2.4 server and all its dependencies. If your build was successful, you should now edit the Apache configuration file _`/usr/pkg/etc/httpd/httpd.conf`_ to fit your needs. At least set the `Listen` Attribute and your `ServerName`. Please ensure that if your machine's hostname does not globally resolve, to put it into your `/etc/hosts` file, otherwise Apache will refuse to start.
1.2       schmonz    18: 
1.6       gutterid   19: If you wish to start the Apache web server at boot time, please copy the rc.d example script from `/usr/pkg/share/examples/rc.d/apache` to `/etc/rc.d` and then add `apache=yes` to your `/etc/rc.conf` file.   
1.2       schmonz    20: 
                     21:     
                     22:     # cp /usr/pkg/share/examples/rc.d/apache /etc/rc.d
1.6       gutterid   23: 
1.2       schmonz    24: 
                     25: If you want to copy the rc.d scripts automatically with pkgsrc, you can use: 
                     26:     
                     27:     PKG_RCD_SCRIPTS=YES 
1.6       gutterid   28: 
1.2       schmonz    29: 
                     30: in your /etc/mk.conf 
                     31: 
                     32:   
1.6       gutterid   33: You can now start, stop, and restart the Apache web server using _apachectl_, or using boot script _/etc/rc.d/apache_
1.2       schmonz    34: 
1.6       gutterid   35: To start the server enter: 
1.2       schmonz    36:     
                     37:     # apachectl start
1.6       gutterid   38: 
1.2       schmonz    39: 
                     40: or 
                     41:     
                     42:     # /etc/rc.d/apache start
1.6       gutterid   43: 
1.2       schmonz    44: 
                     45: To stop the server, substitute start with stop. If you're running a production server, pay attention to the [apachectl graceful](http://httpd.apache.org/docs/2.0/programs/apachectl.html) option. 
                     46: 
                     47: #  Installing MySQL 
                     48: 
1.6       gutterid   49: You can skip this part, if you don't want to install a MySQL server. To install the MySQL server enter: 
1.2       schmonz    50:     
1.6       gutterid   51:     # cd /usr/pkgsrc/databases/mysql57-server
1.2       schmonz    52:     # make install clean clean-depends
                     53: 
1.6       gutterid   54: 
                     55: This will install the MySQL server and all its dependencies, like the MySQL client.
1.2       schmonz    56: 
                     57: ##  Configuring the MySQL server 
                     58: 
                     59: Please copy the example start script to /etc/rc.d 
                     60:     
                     61:     # cp /usr/pkg/share/examples/rc.d/mysqld /etc/rc.d
                     62:     
                     63: 
                     64: and add **mysqld=yes** to your **/etc/rc.conf**
                     65: 
1.6       gutterid   66: You can now start, stop, and restart the MySQL server using 
1.2       schmonz    67:     
                     68:     # /etc/rc.d/mysqld start
                     69:     
                     70: 
                     71: to start and respectively stop and restart. 
                     72: 
1.6       gutterid   73: The default MySQL server database root password is empty. For security reasons, you should set your root password as soon as possible. 
1.2       schmonz    74: 
1.6       gutterid   75: You can pass most of the options to the server via the file /etc/my.cnf. If you want the server to listen only on localhost, for instance, create _/etc/my.cnf_ and add 
1.2       schmonz    76:     
                     77:     [mysqld]
                     78:     port=3306
                     79:     bind-address=127.0.0.1
                     80: 
1.6       gutterid   81: 
                     82: and restart your MySQL server. To check if your MySQL server is really listening only on localhost, use [[basics/sockstat]]. 
1.2       schmonz    83:     
                     84: 
                     85:     # sockstat -l
                     86: 
1.6       gutterid   87: 
1.7     ! gutterid   88: For many more options, consider reading the MySQL [Documentation](https://dev.mysql.com/doc/refman/5.7/en/).
1.2       schmonz    89: 
                     90: 
1.6       gutterid   91: #  Installing the PHP module for Apache
1.2       schmonz    92:     
                     93:     # cd /usr/pkgsrc/www/ap-php
                     94:     # make install clean
                     95: 
1.6       gutterid   96: 
                     97: This will install by default the latest version of PHP 7.x and the PHP7 module for Apache 2.4 
1.2       schmonz    98: 
                     99: ##  Configuring PHP 
                    100: 
1.6       gutterid  101: You should now add the LoadModule and the PHP Handlers definitions to your Apache Configuration File `/usr/pkg/etc/httpd/httpd.conf`
1.2       schmonz   102: 
                    103: Add following lines: 
                    104:     
1.4       sevan     105:     LoadModule php7_module /usr/pkg/lib/httpd/mod_php7.so
1.6       gutterid  106: 
1.2       schmonz   107: 
                    108: and 
                    109:     
                    110:     AddType application/x-httpd-php .php
1.6       gutterid  111: 
1.2       schmonz   112: 
                    113: and if you wish 
                    114:     
                    115:     DirectoryIndex index.html index.php
1.6       gutterid  116: 
1.2       schmonz   117: 
                    118: #  Installing the MySQL module for PHP 
                    119: 
1.6       gutterid  120: This step is important and enables you to make MySQL database connections from your PHP script. 
1.2       schmonz   121:     
                    122:     cd /usr/pkgsrc/databases/php-mysql/
                    123:     make install clean
1.6       gutterid  124: 
1.2       schmonz   125: 
                    126: Now edit `/usr/pkg/etc/php.ini` and add the line 
                    127:     
                    128:     extension=mysql.so
                    129: 
                    130: 
1.6       gutterid  131: You need this to enable MySQL functions in your PHP module. 
                    132: 
                    133: Now restart your Apache web server. To test if PHP is working, create a small file called test.php in your document root directory, which is by default `/usr/pkg/share/httpd/htdocs`, containing only one line with the function phpinfo(). 
1.2       schmonz   134:     
                    135:     <?php phpinfo(); ?>
                    136: 
                    137: 
1.6       gutterid  138: If you use PHP7 and wish to use short tags like `<? phpinfo() ?>`, then edit your `/usr/pkg/etc/php.ini` file and change option `short_open_tag = Off `to `On` to make this line work. In PHP7 short_open_tag is off by default. 
                    139: 
                    140: Open your browser and point it to this URL:
1.2       schmonz   141:     
                    142:     http://127.0.0.1/test.php
                    143: 
                    144: 
1.6       gutterid  145: You should now see a website with information regarding your PHP installation and a table named mysql, in the middle of the document, with MySQL information.
                    146: 
                    147: That's it. You can now install software like a [phpMyAdmin](http://pkgsrc.se/databases/phpmyadmin), or a [Wiki](http://www.mediawiki.org). Have fun. 
1.2       schmonz   148: 
                    149: #  See also 
                    150: 
                    151:   * [[pkgsrc/How to use pkgsrc]]
                    152:   * [[pkgsrc/How to install a MySQL Server]]
                    153: 
                    154: #  Commands 
                    155: 
                    156:   * [[basics/sockstat]]

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb