Diff for /wikisrc/pkgsrc/how_to_install_a_lamp_server.mdwn between versions 1.4 and 1.6

version 1.4, 2018/08/06 21:16:52 version 1.6, 2021/09/04 21:30:15
Line 1 Line 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.   **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. 
   
 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.   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. 
   
Line 6  We will install all components using pkg Line 6  We will install all components using pkg
   
 [[!toc]]  [[!toc]]
   
 #  Installing the Apache webserver   #  Installing the Apache web server
   
 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.   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. 
           
 # cd /usr/pkgsrc/www/apache24      # cd /usr/pkgsrc/www/apache24
     # make install clean clean-depends      # make install clean clean-depends
       
   
 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.   
   
 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.   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.
   
 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.     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.   
   
           
     # cp /usr/pkg/share/examples/rc.d/apache /etc/rc.d      # cp /usr/pkg/share/examples/rc.d/apache /etc/rc.d
       
   
 If you want to copy the rc.d scripts automatically with pkgsrc, you can use:   If you want to copy the rc.d scripts automatically with pkgsrc, you can use: 
           
     PKG_RCD_SCRIPTS=YES       PKG_RCD_SCRIPTS=YES 
       
   
 in your /etc/mk.conf   in your /etc/mk.conf 
   
       
 You could now start, stop and restart the Apache Webserver using _apachectl_ or using boot script _/etc/rc.d/apache_  You can now start, stop, and restart the Apache web server using _apachectl_, or using boot script _/etc/rc.d/apache_
   
 To start the Server enter:   To start the server enter: 
           
     # apachectl start      # apachectl start
       
   
 or   or 
           
     # /etc/rc.d/apache start      # /etc/rc.d/apache start
       
   
 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.   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. 
   
 #  Installing MySQL   #  Installing MySQL 
   
 You can skip this part, if you don't want to install a MySQL Server. To install the MySQL Server enter:   You can skip this part, if you don't want to install a MySQL server. To install the MySQL server enter: 
           
     # cd /usr/pkgsrc/databases/mysql56-server      # cd /usr/pkgsrc/databases/mysql57-server
     # make install clean clean-depends      # make install clean clean-depends
       
   
 This will install the mysql server and all it's dependencies, like the mysql client.   
   This will install the MySQL server and all its dependencies, like the MySQL client.
   
 ##  Configuring the MySQL server   ##  Configuring the MySQL server 
   
Line 65  Please copy the example start script to  Line 63  Please copy the example start script to 
   
 and add **mysqld=yes** to your **/etc/rc.conf**  and add **mysqld=yes** to your **/etc/rc.conf**
   
 You can now start, stop and restart the MySQL server using   You can now start, stop, and restart the MySQL server using 
           
     # /etc/rc.d/mysqld start      # /etc/rc.d/mysqld start
           
   
 to start and respectively stop and restart.   to start and respectively stop and restart. 
   
 The default mysql server database root password is empty. For security reasons, you should set your root password as soon as possible.   The default MySQL server database root password is empty. For security reasons, you should set your root password as soon as possible. 
   
 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   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 
           
     [mysqld]      [mysqld]
     port=3306      port=3306
     bind-address=127.0.0.1      bind-address=127.0.0.1
       
   
 and restart your mysql server. To check, if your mysql server is really listening only on localhost, use [[basics/sockstat]].   
   and restart your MySQL server. To check if your MySQL server is really listening only on localhost, use [[basics/sockstat]]. 
           
   
     # sockstat -l      # sockstat -l
       
   
 For much more Options, consider reading the MySQL [Documentation](http://dev.mysql.com/doc/refman/5.6/en/).   
   
   For many more options, consider reading the MySQL [Documentation](http://dev.mysql.com/doc/refman/5.6/en/). 
   
 #  Installing the PHP Module for Apache  
   #  Installing the PHP module for Apache
           
     # cd /usr/pkgsrc/www/ap-php      # cd /usr/pkgsrc/www/ap-php
     # make install clean      # make install clean
       
   
 This will install by default the latest Version of PHP 7.x and the PHP7 Module for Apache 2.4   
   This will install by default the latest version of PHP 7.x and the PHP7 module for Apache 2.4 
   
 ##  Configuring PHP   ##  Configuring PHP 
   
 You should now add the Module and the PHP Handlers to your Apache Configuration File `/usr/pkg/etc/httpd/httpd.conf`  You should now add the LoadModule and the PHP Handlers definitions to your Apache Configuration File `/usr/pkg/etc/httpd/httpd.conf`
   
 Add following lines:   Add following lines: 
           
     LoadModule php7_module /usr/pkg/lib/httpd/mod_php7.so      LoadModule php7_module /usr/pkg/lib/httpd/mod_php7.so
       
   
 and   and 
           
     AddType application/x-httpd-php .php      AddType application/x-httpd-php .php
       
   
 and if you wish   and if you wish 
           
     DirectoryIndex index.html index.php      DirectoryIndex index.html index.php
       
   
 #  Installing the MySQL module for PHP   #  Installing the MySQL module for PHP 
   
 This step is important and enables you to make mysql database connections from your php script.   This step is important and enables you to make MySQL database connections from your PHP script. 
           
     cd /usr/pkgsrc/databases/php-mysql/      cd /usr/pkgsrc/databases/php-mysql/
     make install clean      make install clean
       
   
 Now edit `/usr/pkg/etc/php.ini` and add the line   Now edit `/usr/pkg/etc/php.ini` and add the line 
           
     extension=mysql.so      extension=mysql.so
       
   
 You need this to enable mysql functions in your php module.   
   
 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().   You need this to enable MySQL functions in your PHP module. 
   
   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(). 
           
     <?php phpinfo(); ?>      <?php phpinfo(); ?>
       
   
 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.   
   
 Open your browser and point it to this url:   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. 
   
   Open your browser and point it to this URL:
           
     http://127.0.0.1/test.php      http://127.0.0.1/test.php
       
   
 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.   
   
 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.   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.
   
   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. 
   
 #  See also   #  See also 
   
   * [[pkgsrc/How to use pkgsrc]]    * [[pkgsrc/How to use pkgsrc]]
   * [[pkgsrc/How to install a MySQL Server]]    * [[pkgsrc/How to install a MySQL Server]]
   * [[How to build NetBSD-current]]  
   
 #  Commands   #  Commands 
   

Removed from v.1.4  
changed lines
  Added in v.1.6


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