File:  [NetBSD Developer Wiki] / wikisrc / pkgsrc / how_to_install_a_lamp_server.mdwn
Revision 1.5: download - view: text, annotated - select for diffs
Mon Aug 6 21:22:03 2018 UTC (2 years, 5 months ago) by sevan
Branches: MAIN
CVS tags: HEAD
Formatting

    1: **LAMP** is a an acronym for a combined set of software to run a Webserver containig following Software Products: **Apache, Mysql 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. 
    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: 
    9: #  Installing the Apache webserver 
   10: 
   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. 
   12:     
   13:     # cd /usr/pkgsrc/www/apache24
   14:     # make install clean clean-depends
   15:     
   16: 
   17: This will install the Apache 2.4 server and all it's dependencies. The package currently depends on 10 other packages like perl, gmake and libtool to name a few. All dependencies are build before the Apache webserver is build, otherwise it wouldn't be dependencies. 
   18: 
   19: 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 machines hostname does not globally resolve, to put it into your `/etc/hosts` file, otherwise Apache will refuse to start. 
   20: 
   21: If you wish to start the Apache webserver at boottime, 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.   
   22: 
   23:     
   24:     # cp /usr/pkg/share/examples/rc.d/apache /etc/rc.d
   25:     
   26: 
   27: If you want to copy the rc.d scripts automatically with pkgsrc, you can use: 
   28:     
   29:     PKG_RCD_SCRIPTS=YES 
   30:     
   31: 
   32: in your /etc/mk.conf 
   33: 
   34:   
   35: You could now start, stop and restart the Apache Webserver using _apachectl_ or using boot script _/etc/rc.d/apache_
   36: 
   37: To start the Server enter: 
   38:     
   39:     # apachectl start
   40:     
   41: 
   42: or 
   43:     
   44:     # /etc/rc.d/apache start
   45:     
   46: 
   47: 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. 
   48: 
   49: #  Installing MySQL 
   50: 
   51: You can skip this part, if you don't want to install a MySQL Server. To install the MySQL Server enter: 
   52:     
   53:     # cd /usr/pkgsrc/databases/mysql56-server
   54:     # make install clean clean-depends
   55:     
   56: 
   57: This will install the mysql server and all it's dependencies, like the mysql client. 
   58: 
   59: ##  Configuring the MySQL server 
   60: 
   61: Please copy the example start script to /etc/rc.d 
   62:     
   63:     # cp /usr/pkg/share/examples/rc.d/mysqld /etc/rc.d
   64:     
   65: 
   66: and add **mysqld=yes** to your **/etc/rc.conf**
   67: 
   68: You can now start, stop and restart the MySQL server using 
   69:     
   70:     # /etc/rc.d/mysqld start
   71:     
   72: 
   73: to start and respectively stop and restart. 
   74: 
   75: The default mysql server database root password is empty. For security reasons, you should set your root password as soon as possible. 
   76: 
   77: 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 
   78:     
   79:     [mysqld]
   80:     port=3306
   81:     bind-address=127.0.0.1
   82:     
   83: 
   84: and restart your mysql server. To check, if your mysql server is really listening only on localhost, use [[basics/sockstat]]. 
   85:     
   86: 
   87:     # sockstat -l
   88:     
   89: 
   90: For much more Options, consider reading the MySQL [Documentation](http://dev.mysql.com/doc/refman/5.6/en/). 
   91: 
   92: 
   93: #  Installing the PHP Module for Apache
   94:     
   95:     # cd /usr/pkgsrc/www/ap-php
   96:     # make install clean
   97:     
   98: 
   99: This will install by default the latest Version of PHP 7.x and the PHP7 Module for Apache 2.4 
  100: 
  101: ##  Configuring PHP 
  102: 
  103: You should now add the Module and the PHP Handlers to your Apache Configuration File `/usr/pkg/etc/httpd/httpd.conf`
  104: 
  105: Add following lines: 
  106:     
  107:     LoadModule php7_module /usr/pkg/lib/httpd/mod_php7.so
  108:     
  109: 
  110: and 
  111:     
  112:     AddType application/x-httpd-php .php
  113:     
  114: 
  115: and if you wish 
  116:     
  117:     DirectoryIndex index.html index.php
  118:     
  119: 
  120: #  Installing the MySQL module for PHP 
  121: 
  122: This step is important and enables you to make mysql database connections from your php script. 
  123:     
  124:     cd /usr/pkgsrc/databases/php-mysql/
  125:     make install clean
  126:     
  127: 
  128: Now edit `/usr/pkg/etc/php.ini` and add the line 
  129:     
  130:     extension=mysql.so
  131:     
  132: 
  133: You need this to enable mysql functions in your php module. 
  134: 
  135: Now restart your Apache webserver. 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(). 
  136:     
  137:     <?php phpinfo(); ?>
  138:     
  139: 
  140: 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 working. In PHP7 short_open_tag is off by default. 
  141: 
  142: Open your browser and point it to this url: 
  143:     
  144:     http://127.0.0.1/test.php
  145:     
  146: 
  147: 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 informations. 
  148: 
  149: 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. 
  150: 
  151: #  See also 
  152: 
  153:   * [[pkgsrc/How to use pkgsrc]]
  154:   * [[pkgsrc/How to install a MySQL Server]]
  155:   * [[How to build NetBSD-current]]
  156: 
  157: #  Commands 
  158: 
  159:   * [[basics/sockstat]]

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