Table of Contents
Local Server Setup
Of course we need a device for the server we are going to set up, it would be ridiculous to buy a tower server for serious amounts. So we will use an old laptop. I use my old laptop for this purpose. The server will not be open to the external network, but you can provide this if you want. You will need a static IP for this. Most ISPs offer static IP services for a reasonable fee. If you wish, you can purchase these services and provide external access by using the information I will explain in my article with a few small settings. I will not give information about this subject in this article. If you want to learn, you need to redirect TCP connections to this server that we will set up over your Modem.
FreeBSD Installation
First of all from the FreeBSD website download the installation package of the desired version.
What we need to know is the processor architecture of the device we are going to install. Since I am going to install on an old laptop and it has a 32-bit intel processor, I choose i386. If installing on a 64-bit device, amd64 should be selected. Arm processors are used on mac computers. For others see [Supported platforms page](https://www.freebsd.org/platforms/#_supported_platforms).
After selecting the architecture, go to the FTP page and choose the installation option. The RELEASE version should always be installed.
I'll use the https://download.freebsd.org/releases/i386/i386/ISO-IMAGES/13.1/ page, as this is the most up-to-date version at the time of writing.
- FreeBSD-versionarchitecture-bootonly.iso
- This is an archive containing only the necessary files for the boot phase. It only takes us up to the network settings and then the necessary files are downloaded from the internet and installed.
- FreeBSD-versionarchitecture-bootonly.iso.xz
- This is an archived and compressed version of the above file. They are essentially the same file.
- FreeBSD-versionarchitecture-disc1.iso
- If we are going to install using a CD, we need to use an image file. After burning the image to a CD, the installation starts.
- FreeBSD-versionarchitecture-disc1.iso.xz
- Archived and compressed version of the above file.
- FreeBSD-versionarchitecture-dvd1.iso
- It is the image file that can be used if we are going to install using a DVD. Unlike the CD version, it also includes extra files. It allows a basic installation without the need for an internet connection.
- FreeBSD-versionarchitecture-dvd1.iso.xz
- It is also compressed to save size. After downloading, you need to unzip it with any archiving program.
- FreeBSD-versionarchitecture-memstick.img
- It is the image that should be used if installation is to be done using a Flash Disk. With programs like Rufus, the image file is written to a flash disk and the installation is done. I will use this.
- FreeBSD-versionarchitecture-memstick.img.xz
- Compressed version of the image above.
- FreeBSD-versionarchitecture-mini-memstick.img
- Like Bootonly, it is only the image that will allow us to pass the boot phase. The difference is that we boot using flash. Then we download the necessary packages with an internet connection.
- FreeBSD-versionarchitecture-mini-memstick.img.xz
- Compressed version of the image above.
The required image is downloaded and the device is formatted. Installation can be done using basic installation steps. If we are going to install a small-scale server. ZFS file system should not be used. I don't want to prolong the basic installation steps here…
After the installation is finished, reboot
is done and login. Now we can install the necessary packages and configure our server.
With the code kldload i915kms
you can enable the video card (for Intel video card.). This is a temporary solution. You have to repeat it with every reboot. For now, let's use it for comfortable reading.
Installing Packages
Installing the Package System
We will use the package system to install our programs. Installing from ports is very time consuming and can be a headache. You can install the package system by typing the following codes in order.
pkg -y pkg update -f pkg upgrade
Installation of Required Packages
I install these programs because they are the ones I use all the time. You can skip this step if you want.
pkg install -y python27 python3 bash wget
MySQL Setup
Look for packages with the pkg search mysql
command. Install one of the following.
pkg install -y mysql55-server mysql55-client pkg install -y mysql56-server mysql56-client pkg install -y mysql57-server mysql57-client pkg install -y mysql80-server mysql80-client
The reason I install mysql-client is that I use mysql connectors in the programs I write, if you don't have such a need, you don't need to install the client.
Mysql opens automatically at startup
With the following code, mysql starts automatically every time we turn on the computer.
sysrc mysql_enable="YES"
MySQL Settings
ee /usr/local/etc/mysql/my.cnf
We will make a small edit in the config file with the ee editor. In the config file there should be a line like bind adress 127.0.0.1
. We should turn this line into a comment line by putting #
at the beginning.
service mysql-server start
Start mysql with the command. Now we can make settings for the root user.
mysql_secure_installation
We run Mysql's auxiliary installation script with the command. Here it will ask us some questions and you can answer them according to yourself. It will ask you for the root password at first. Since we have just installed, there is no password yet, we will pass directly with enter and then we will set our own root password.
mysql -u root -p
We can now log in with the command. You will use your new password here. MySQL installation ends here. Now, after logging in, you can run any query you want on the command line. You can exit with exit;
.
Installation of 32 bit Libraries
If you are installing on a 64 bit device and you need 32 bit libraries, you can automatically install 32 bit libraries with the command below. Of course you need to have wget installed. In the example code, copy the image file you used in the installation and correct the version part.
wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/12.2-RELEASE/lib32.txz tar Jxpvf lib32.txz -C / rm -rf lib32.txz
Local Web Server Setup
The steps here are the settings I have applied on my local server. You may need to make some changes according to your needs.
Apache and PHP Installation
I don't use things like NGIX, I'm a bit old school, I like to have everything under my control, so I use apache and php. There are other things I use, but that should be enough to set up a basic web server.
pkg install -y apache24 pkg install -y php74 mod_php74 php74-bz2 php74-curl php74-mysqli php74-extensions php74-json php74-mbstring php74-session sysrc apache24_enable="YES"
You can install using the command above. I am using php74, if you want a different version you can search in packages with search command. Also, if you need other php modules, don't forget to install them.
Apache Ayarları
ee /usr/local/etc/apache24/httpd.conf
We will make some edits to the httpd.conf settings file with the command.
Find the following lines and remove the #
at the beginning so that they are no longer comment lines.
Include etc/apache24/extra/httpd-vhosts.conf LoadModule rewrite_module libexec/apache24/mod_rewrite.so LoadModule ssl_module libexec/apache24/mod_ssl.so
Aşağıdaki satırı bul ve düzenle. Eğer sadece yerel olarak kullanacaksan `127.0.0.1`, eğer sunucunu internete açacaksan, domain adresini yazmalısın. (*İnternet üzerinden erişime açacaksan, en azından statik IP adresine sahip olman ve modem üzerinden gelen bağlantıları sunucuna yönlendirmen gerekmekte.*)
#ServerName www.example.com:80 ServerName 127.0.0.1:80
We will set virtual hosts on our apache server with the following command.
ee /usr/local/etc/apache24/extra/httpd-vhosts.conf
After opening it with the editor, edit the content according to the example below.
Edit the DOMAINNAME
part to your own. The example below is for a server that is not going to be connected to the internet locally. Normally we cannot use subdomains because we access local servers locally via ip address. I am indirectly showing how to set up multiple virtual hosts using subdomains so that we can test as many websites as we want in our test environment.
<VirtualHost *:80> ServerAdmin administrator@development.localhost DocumentRoot "/usr/local/www/apache24/data/DOMAINNAME.com" ServerName localhost ServerAlias DOMAINNAME.com ErrorLog "/var/log/httpd-DOMAINNAME-com-error-log" CustomLog "/var/log/httpd-DOMAINNAME-com-access-log" devmon </VirtualHost> <VirtualHost *:80> ServerAdmin administrator@development.localhost DocumentRoot "/usr/local/www/apache24/data/SUBDOMAIN.DOMAINNAME.dev" ServerName SUBDOMAIN.localhost ServerAlias SUBDOMAIN.DOMAINNAME.com ErrorLog "/var/log/SUBDOMAIN.DOMAINNAME.com-error_log" CustomLog "/var/log/SUBDOMAIN.DOMAINNAME.com-access_log" devmon </VirtualHost>
Subdomain Name Usage Locally
Let me set up a sample test environment using the above virtual host configuration file as a template…
Here we need to choose a domain name, even if it is local. The domain name you choose here should be a non-real domain name that you do not use on the computers you use, for example, if I choose google.com here, I will never be able to enter google again. When I do, it will be directed to my server.
<VirtualHost *:80> ServerAdmin administrator@development.localhost DocumentRoot "/usr/local/www/apache24/data/deneme.com" ServerName localhost ServerAlias deneme.com ErrorLog "/var/log/httpd-deneme-com-error-log" CustomLog "/var/log/httpd-deneme-com-access-log" devmon </VirtualHost> <VirtualHost *:80> ServerAdmin administrator@development.localhost DocumentRoot "/usr/local/www/apache24/data/test.deneme.com" ServerName test.localhost ServerAlias test.deneme.com ErrorLog "/var/log/test.deneme.com-error_log" CustomLog "/var/log/test.deneme.com-access_log" devmon </VirtualHost>
Now we need to edit the c:\Windows\System32\Drivers\etc\hosts
file on your computer (I assume Windows). In this file, add the following codes at the bottom.
192.168.xxx.xxx demene.com 192.168.xxx.xxx test.deneme.com
Edit the xxx parts here according to the local ip address of your freebsd device. You can find out with the ifconfig
command.
With this logic you can increase the subdomains as many times as you want. Now when you type trial.com
in any browser from a windows computer you will go to your local web server. The best part is that you can now also use subdomains. So you can type test.trial.com
and go to your subdomain. These are the disk locations on a FreeBSD machine. They are in the following order.
/usr/local/www/apache24/data/deneme.com /usr/local/www/apache24/data/test.deneme.com
Create these folders in the relevant places and put your web files in them. If you are going to use mysql database. You can login and create database and user. You can install phpmyadmin in the same way. The rest is up to your use…
mkdir /usr/local/www/apache24/data/DOMAINNAME.com mkdir /usr/local/www/apache24/data/subdomain.DOMAINNAME.com chown -R www:www /usr/local/www/apache24/data service apache24 restart
You can create the relevant folders with the commands above and restart apache. Do not forget to restart apache after completing PHP Settings.
PHP Settings
cp /usr/local/etc/php.ini-production /usr/local/etc/php.ini
Komutu ile örnek ayar dosyasını ilgili alana kopyalıyoruz.
ee /usr/local/etc/apache24/modules.d/001_mod-php.conf
We will complete the php integration over apache with the command. After opening the editor, paste the following into it.
<IfModule dir_module> DirectoryIndex index.php index.html <FilesMatch "\.php$"> SetHandler application/x-httpd-php </FilesMatch> <FilesMatch "\.phps$"> SetHandler application/x-httpd-php-source </FilesMatch> </IfModule>
Now we can use php in our test environment without any problems. The article ends here… Best regards…
Taken from UCH Wiki. https://wiki.ulascemh.com/doku.php?id=en:cs:op:bsd:localhost