This is the old XigmaNAS forum in read only mode,
it will taken offline by the end of march 2021!



I like to aks Users and Admins to rewrite/take over important post from here into the new fresh main forum!
Its not possible for us to export from here and import it to the main forum!

(HOW-TO) AMP server with phpMyAdmin in Jail

Jails with XigmaNAS
Forum rules
Set-Up GuideFAQsForum Rules
Post Reply
BlackPeter
Starter
Starter
Posts: 40
Joined: 03 Nov 2013 19:45
Location: Spain
Contact:
Status: Offline

(HOW-TO) AMP server with phpMyAdmin in Jail

Post by BlackPeter »

FreeBSD 9.1-RELEASE
apache24-2.4.6
mysql-server-5.6.12
php5-5.4.17
php5-extensions-1.7
phpMyAdmin-4.0.4.1
WordPress v3.5.2

The 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:
portsnap fetch
portsnap extract

If the Ports Collection is already installed, make sure to update it:
portsnap fetch update

Okay, let’s 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.

Install Apache

Navigate to the Apache server port and build it:
cd /usr/ports/www/apache24
make install clean

Once Apache has been successfully installed, add the following line to /etc/rc.conf so that the Apache server will start automatically at system boot.
echo 'apache24_enable="YES"' >> /etc/rc.conf

Now let’s start Apache to make sure it works:
/usr/local/etc/rc.d/apache24 start

Point your web browser to the host name or IP address of the FreeBSD host you’ve installed Apache on and you should see the venerable “It Works.”

Install MySQL.

Now let’s build the MySQL server:
cd /usr/ports/databases/mysql55-server
make install clean

Add the following line to /etc/rc.conf:
echo 'mysql_enable="YES"' >> /etc/rc.conf

And start the mysql server:
/usr/local/etc/rc.d/mysql-server start

Then set a password for the MySQL root user:
/usr/local/bin/mysqladmin -u root password 'your-password'

Install PHP

Next, we’ll 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:
cd /usr/ports/lang/php5
make config

A menu should come up allowing you to select/deselect various build options. You should select “Build Apache module” 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:
make install clean

Now let’s add the requisite extensions to PHP to round out its capabilities. Before we build this port though we’ll want to add support for both MySQL and MySQLi (an improved interface to MySQL) in order to communicate with the MySQL server.
cd /usr/ports/lang/php5-extensions/
make config

In the corresponding menu you should select “MySQL database support” and “MySQLi database support,” then proceed with building the port:
make install clean

Install phpMyAdmin

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’s nice tool to have. Here again we’ll want to add support for MySQL and MySQLi before building the port:
cd /usr/ports/databases/phpmyadmin/
make config

Here you should ensure that both “MYSQL M(DB_connect): PHP MySQL support via mysql client” and “MYSQLI M(DB_connect) PHP Improved MySQL client support” are selected, then proceed with building the port:
make install clean

Configuration

Now that we have the requisite ports built and installed it’s time to configure them. First, let’s 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.
cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

Now let’s configure Apache. Open the file /usr/local/etc/apache24/httpd.conf in your favorite editor and look for the following line:
DirectoryIndex index.html

And change it so it reads as follows:
DirectoryIndex index.html index.htm index.php

Then 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:
1 AddType application/x-httpd-php .php
2 AddType application/x-httpd-php-source .phps
3
4 Alias /phpmyadmin "/usr/local/www/phpMyAdmin"
5
6 <Directory "/usr/local/www/phpMyAdmin">
7 Options None
8 AllowOverride None
9 Require all granted
10 </Directory>

As an optional step, if you’d like to add multilanguage support to Apache, uncomment the following line:
Include etc/apache24/extra/httpd-languages.conf

Then open the language settings file /usr/local/etc/apache24/extra/httpd-languages.conf and add the following line to the end of the file:
AddDefaultCharset On

Now restart Apache:
/usr/local/etc/rc.d/apache24 restart

That’s it for our Apache configuration. Now let’s configure phpMyAdmin. We’ll 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:
mkdir /usr/local/www/phpMyAdmin/config && chmod o+w /usr/local/www/phpMyAdmin/config

Then 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 “New server” and then select the “Authentication” tab. Under the “Authentication type” choose “http” 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 “root” from the “User for config auth”(See Figure 1).



Now select “Save” and you will be returned you to the Overview page where you should see a new server listed. Select “Save” again in the Overview page to save your configuration as /usr/local/www/phpMyAdmin/config/config.inc.php. Now let’s move that file to /usr/local/www/phpMyAdmin where phpMyAdmin can make use of it.
mv /usr/local/www/phpMyAdmin/config/config.inc.php /usr/local/www/phpMyAdmin

Now let’s 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 “root” 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’s remove it and wrap up by restarting the Apache and MySQL servers:
rm -r /usr/local/www/phpMyAdmin/config
/usr/local/etc/rc.d/apache24 restart
/usr/local/etc/rc.d/mysql-server restart

Testing our installation using WordPress

WordPress is a full-featured website/blog platform that makes heavy use of Apache, MySQL and PHP. We’ll 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’s start by downloading the latest WordPress directly from the developers site to your home directory and untarring the package:
fetch http://wordpress.org/latest.tar.gz
tar -zxvf latest.tar.gz

You 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’s copy the file ~/wordpress/wp-config-sample.php to use as a template:
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php

Open ~/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:
1 // ** MySQL settings - You can get this info from your web host ** //
2 /** The name of the database for WordPress */
3 define('DB_NAME', 'wordpress');
4
5 /** MySQL database username */
6 define('DB_USER', 'root');
7
8 /** MySQL database password */
9 define('DB_PASSWORD', 'your-mysql-password');

Now move the wordpress directory to Apache’s document root:
mv ~/wordpress/ /usr/local/www/apache24/data/

Next, let’s create an MySQL database for our WordPress installation. Open phpMyAdmin in your browser and create a database by selecting the “Databases” tab at the top. Enter a name for it in the “Create database” field. For purposes of our example, I’ll use “wordpress” as the database name. You’re free to use a different database name, just make sure to use the same name in the define(‘DB_NAME’, ‘your-DB-name’); line in ~/wordpress/wp-config.php as described above. Then select “Create.”

Now let’s 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/word ... nstall.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 “Install WordPress.” Then login with your newly created WordPress credentials and you should be presented with the default WordPress administration page.



Common problems

An error that occasionally pops up when attempting to start the Apache server is the following:
httpd: apr_sockaddr_info_get() failed for <some-host-name>
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName
/usr/local/etc/rc.d/apache24: WARNING: failed to start apache24

This can be fixed by adding a line to /etc/hosts. First, verify your hostname by running the hostname command:
hostname

Then add the following to /etc/hosts:
hostname IP-address-of-your-freebsd-box

Finally, 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/apache24/httpd.conf. As an example, a missing “/” in the Alias statement cost me two hours of troubleshooting time!

Conclusion

Well, that’s it. A few hours of your time with the FreeBSD Ports Collection and you can a get a fully configured “AMP” web development server up and running on your FreeBSD box.
Hostname it-service.sytes.net
Version 12.0.0.4 - Reticulus (revision 6743)
Compiled 06/09/2019 01:26:07
Platform OS FreeBSD 12.0-RELEASE-p5 #0 r348788M: Fri Jun 7 22:53:38 CEST 2019
Platform x64-full on Intel(R) Core(TM)2 Duo CPU E7500 @ 2.93GHz
System Wistron Corporation ProLiant DL120 G5

Snunn1
Starter
Starter
Posts: 35
Joined: 05 Sep 2013 21:55
Status: Offline

Re: (HOW-TO) AMP server with phpMyAdmin in Jail

Post by Snunn1 »

NAS4Free 10.2.0.2.2545 P14 Embedded on 1GB USB Key
HP N40L Microserver - 8GB ECC RAM, 3x Seagate 500GB RAIDZ1, 1x Seagate 500GB UFS & 1x 200GB SATA
Extensions: RRDGraphs

Post Reply

Return to “Jails”