Support #868
Install a FreeBSD, Apache2, MySQL, PHP Web Server on FreeBSD
Description
- Table of contents
- Prepare the Environment
- Install MySQL Server
- Create Databases and Users
- Install Apache
- Install PHP
- Resources
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
- and run the following SQL queries to create the somedb database and someuser user:
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/
- Set your timezone:
- 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
- And adjust the index to use php files:
- 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>
- And add the following
- 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(); ?>
- And add the following contents:
- To see if it works, open a web browser and go to http://localhost/test.php
Resources¶
Updated by Daniel Curtis about 8 years ago
- Status changed from New to In Progress
- % Done changed from 0 to 50
Updated by Daniel Curtis about 8 years ago
- Status changed from In Progress to Resolved
- % Done changed from 50 to 100