Project

General

Profile

Support #868

Install a FreeBSD, Apache2, MySQL, PHP Web Server on FreeBSD

Added by Daniel Curtis about 8 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Web Server
Target version:
Start date:
11/10/2016
Due date:
% Done:

100%

Estimated time:
1.50 h
Spent time:

Description

This is a guide on how to set up a FAMP Web Server on FreeBSD.

Prepare the Environment

  • Make sure the system is up to date:
    pkg update && pkg upgrade
    

Install MySQL Server

  • Start by installing the mariadb100-server and mariadb100-client packages:
    pkg install mariadb100-{server,client}
    
  • Copy a base MySQL configuration to use:
    cp /usr/local/share/mysql/my-small.cnf /var/db/mysql/my.cnf
    
  • Enable and start mysql at boot:
    echo 'mysql_enable="YES"' >> /etc/rc.conf
    service mysql-server start
    
  • Prepare the database for use by running the secure installation:
    mysql_secure_installation
    
    • NOTE: Choose a strong root password and answer yes to all questions.

Create Databases and Users

  • Login to MySQL and create appropriate databases and users.
    mysql -u root -p
    
    • and run the following SQL queries to create the somedb database and someuser user:
      CREATE DATABASE somedb CHARACTER SET utf8;
      
      CREATE USER 'someuser'@'localhost' IDENTIFIED BY 'SuperSecretPassword';
      
      GRANT ALL PRIVILEGES ON somedb.* TO 'someuser'@'localhost';
      
      FLUSH PRIVILEGES;
      
      quit
      

Install Apache

  • Install apache:
    pkg install apache24
    
  • Enable and start apache at boot:
    echo 'apache24_enable="YES"' >> /etc/rc.conf
    service apache24 start
    

Install PHP

  • Install php and php-apache:
    pacman -S php56 mod_php56
    
  • Configure the default PHP settings
    cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
    
  • Edit the php config file:
    vi /usr/local/etc/php.ini
    
    • Set your timezone:
      date.timezone = America/Los_Angeles
      open_basedir = /usr/local/www/:/home/:/tmp/:/usr/local/share/pear/
      
  • Edit the main apache config file again:
    vi /usr/local/etc/apache24/httpd.conf
    
    • And adjust the index to use php files:
      DirectoryIndex index.php
      
  • Create a php56 config to be included by apache:
    vi /usr/local/etc/apache24/php56.conf
    
    • And add the following
      <FilesMatch "\.php$">
          SetHandler application/x-httpd-php
      </FilesMatch>
      <FilesMatch "\.phps$">
          SetHandler application/x-httpd-php-source
      </FilesMatch>
      
  • Restart apache:
    service apache24 restart
    
  • Create a file called test.php in your Apache DocumentRoot directory:
    vi /usr/local/www/apache24/data/test.php
    
    • And add the following contents:
      <?php phpinfo(); ?>
      

Resources

Also available in: Atom PDF