# Setup and test a variety of languages for development, quickly and efficiently (FreeBSD 13)



## decuser (Jun 20, 2021)

I use a lot of programming languages, this is a distillation of how I get them installed and tested for others who might not have gone that far down this road 

What gets installed and tested: python, java, ruby, perl, apache, php, and xdebug, sqlite, mysql, LaTeX

# snapshot just in case we rm -fr /boot, / or something else
sudo bectl create languages

# first we install the languages, then test

----------
-- python - install a recent python w/tcl-tk support using pyenv to manage multiples
----------
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init --path)"' >> ~/.bash_profile

reenter shell
exit
ssh laptop

pyenv install -l
PYTHON_CONFIGURE_OPTS="--with-tcltk-includes='-I/usr/local/include' --with-tcltk-libs='-L/usr/local/lib -ltcl8.6 -ltk8.6'" pyenv install 3.9.5
pyenv global 3.9.5

# if you have some scripts and manpages, copy 'em over and test
mkdir -p ~/bin
mkdir -p ~/man/man1
scp server:/Users/wsenn/bin/dircmp ~/bin/
scp server:/Users/wsenn/man/man1/dircmp.1 ~/man/man1
echo 'export PATH="~/bin:$PATH"' >> .bash_profile
echo 'export MANPATH="${HOME}/man:$MANPATH"' >> .bash_profile

reenter shell
exit
ssh laptop

dircmp --help
man dircmp
python --version
Python 3.9.5

----------
-- java (openjdk 11 ymmv)
----------
pkg install -y `pkg search ^openjdk | grep openjdk11-11 | awk '{print $1}'`
java -version
openjdk version "11.0.10" 2021-01-19
OpenJDK Runtime Environment (build 11.0.10+9-1)
OpenJDK 64-Bit Server VM (build 11.0.10+9-1, mixed mode)

----------
-- ruby - install using rbenv and ruby-build for multiples
----------
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile

reenter shell
exit
ssh laptop

mkdir -p "$(rbenv root)"/plugins
git clone https://github.com/rbenv/ruby-build.git "$(rbenv root)"/plugins/ruby-build
curl -fsSL https://github.com/rbenv/rbenv-installer/raw/master/bin/rbenv-doctor | bash
rbenv install --list
MAKE=make rbenv install 3.0.1
rbenv global 3.0.1

reenter shell
exit
ssh laptop

ruby --version
ruby 3.0.0p0 (2020-12-25 revision 95aff21468) [x86_64-freebsd12.2]

----------
-- perl - install using perlbrew for multiples
----------
curl -L https://install.perlbrew.pl | bash
echo 'source ~/perl5/perlbrew/etc/bashrc' >> ~/.bash_profile

reenter shell
exit
ssh laptop

perlbrew available
perlbrew --notest install perl-5.35.1

# test
# perlbrew use perl-5.35.1
perlbrew switch perl-5.35.1

reenter shell
exit
ssh laptop
perl --version
This is perl 5, version 35, subversion 1 (v5.35.1) built for amd64-freebsd

----------
-- apache, php, and xdebug
----------
sudo pkg install -y apache24 php74 mod_php74 php74-pecl-xdebug

Apache config:    /usr/local/etc/apache24/httpd.conf
-- Listen 80
-- DocumentRoot "/usr/local/www/apache24/data"
-- <Directory "/usr/local/www/apache24/data">
-- User www
-- Group www
-- CustomLog "/var/log/httpd-access.log" common
-- LoadModule headers_module lib/httpd/modules/mod_headers.so
-- LoadModule php7_module libexec/apache24/libphp7.so

sudo vi /usr/local/etc/apache24/httpd.conf
1. change AllowOverride None to AllowOverride All except for cgi-bin
2. change ServerName www.example.com:80 to ServerName localhost
3. uncomment LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
4. uncomment LoadModule deflate_module lib/httpd/modules/mod_deflate.so
5. uncomment LoadModule expires_module lib/httpd/modules/mod_expires.so
6. change DirectoryIndex index.html to: DirectoryIndex index.php index.html
7. add to config after dir_module section
<FilesMatch "\.php$">
    SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
    SetHandler application/x-httpd-php-source
</FilesMatch>

sudo cp /usr/local/etc/php.ini-development /usr/local/etc/php.ini

pkg info -l mod_php74
mod_php74-7.4.20:
    /usr/local/libexec/apache24/libphp7.so
    /usr/local/share/licenses/mod_php74-7.4.20/LICENSE
    /usr/local/share/licenses/mod_php74-7.4.20/PHP301
    /usr/local/share/licenses/mod_php74-7.4.20/catalog.mk

php -v
PHP 7.4.20 (cli) (built: Jun  6 2021 01:13:39) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Xdebug v3.0.3, Copyright (c) 2002-2021, by Derick Rethans

cat /usr/local/www/apache24/data/index.html
<html><body><h1>It works!</h1></body></html>

sudo sysrc -f /etc/rc.conf apache24_enable="yes"
sudo service apache24 start

# add to top of ini file (after \[PHP\])
sudo vi /usr/local/etc/php.ini
zend_extension=/usr/local/lib/php/20190902/xdebug.so

cat /usr/local/etc/php/ext-20-xdebug.ini
zend_extension=xdebug.so
sudo service apache24 restart

----------
-- sqlite - best database ever
----------
installed during system install, otherwise: pkg install -y sqlite3
sqlite3 --version
3.34.1 2021-01-20 14:10:07 10e20c0b43500cfb9bbc0eaa061c57514f715d87238f4d835880cd846b9ealt1

----------
-- mysql - standard open source db, postgres works fine too
----------
installed during system install, but not enabled - to install: pkg install mysql57-client mysql57-server
sudo sysrc -f /etc/rc.conf mysql_enable="YES"
sudo sysrc -f /etc/rc.conf mysql_args="--skip-grant-tables"

sudo service mysql-server start
mysql -u root
> FLUSH PRIVILEGES;
> ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
> \q
sudo service mysql-server stop
sudo sysrc -x mysql_args
sudo service mysql-server start
mysql -u root -p

----------
-- LaTeX - if you don't do tex, skip, but if you wanna be sure you have it all 
----------
# fastest and most reliable way
# the time it takes to download the 4gb texlive distro
# plus another 25 minutes of processing
# vs hours and hours and hours and hours and using their web enabled installer...

xrefs


			Acquiring TeX Live as an ISO image - TeX Users Group
		



			Quick install - TeX Live - TeX Users Group
		


Download the iso and copy it
I used the torrent on mac and left it running for a while after

scp server:/Users/wsenn/_workarea/_CD_DVD/texlive2021-20210325.iso .
sudo -s
mdconfig -a -f texlive2021-20210325.iso
mount_cd9660 /dev/md0 /mnt
rm -rf /usr/local/texlive
rm -rf ~/.texlive2021
cd /mnt
perl install-tl -gui text

===== truncated output from installer (takes a good 30 minutes)
Loading ./tlpkg/texlive.tlpdb
Installing TeX Live 2021 from: . (verified)
Platform: amd64-freebsd => 'FreeBSD on x86_64'
...

Enter command:

# choose O for Options, P to get letter, R to return to main menu,
# then I to kick off install
Enter command: O
Enter command: P
Enter command: R
Enter command: I
...

cd
umount /mnt
mdconfig -d -u md0
exit

# adjust the following to match reality
cat << "EOF" >> .bash_profile
PATH=/usr/local/texlive/2021/bin/amd64-freebsd/:$PATH; export PATH
MANPATH=/usr/local/texlive/2021/texmf-dist/doc/man:$MANPATH; export MANPATH
INFOPATH=/usr/local/texlive/2021/texmf-dist/doc/info:$INFOPATH; export INFOPATH
EOF
exit
reenter

latex --version

pdfTeX 3.141592653-2.6-1.40.22 (TeX Live 2021)
kpathsea version 6.3.3
Copyright 2021 Han The Thanh (pdfTeX) et al.
There is NO warranty.  Redistribution of this software is
covered by the terms of both the pdfTeX copyright and
the Lesser GNU General Public License.
For more information about these matters, see the file
named COPYING and the pdfTeX source.
Primary author of pdfTeX: Han The Thanh (pdfTeX) et al.
Compiled with libpng 1.6.37; using libpng 1.6.37
Compiled with zlib 1.2.11; using zlib 1.2.11
Compiled with xpdf version 4.03

Done with LaTeX!

======================= TESTS

mkdir -p ~/tests
cd ~/tests

-----------------------------
---- c
-----------------------------
cat > hello.c << EOF
#include<stdio.h>
int main(void)
{
printf("Hello! This is a C program.\n");
return 0;
}
EOF
cc hello.c -o helloc
./helloc

-----------------------------
---- c++
-----------------------------
cat > hello.C << EOF
#include "iostream"
int main(void)
{
    std::cout << "Hello! This is a C++ program.\n";
    return 0;
}
EOF
c++ hello.C -o hellocpp
./hellocpp

-----------------------------
---- java
-----------------------------
cat > Hello.java << EOF
public class Hello {
    public static void main(String [] args) {
        System.out.println("Hello! This is a Java program");
    }
}
EOF
javac Hello.java
java Hello

-----------------------------
---- ruby
-----------------------------
cat > hello.rb << EOF
puts "Hello! This is a ruby program.\n"
EOF
ruby hello.rb

-----------------------------
---- perl
-----------------------------
cat > hello.pl << EOF
printf("Hello! This is a perl program.\n");
EOF
perl hello.pl

-----------------------------
---- python
-----------------------------
cat > hello.py << EOF
name="python"
print(f"Hello! This is a {name} program.")
EOF
python hello.py

-----------------------------
---- python tcltk
-----------------------------
cat > hellotcltk.py << EOF
import tkinter as tk
class Application(tk.Frame):
    def __init__(self, master=None):
        super().__init__(master)
        self.master = master
        self.pack()
        self.create_widgets()
    def create_widgets(self):
        self.hi_there = tk.Button(self)
        self.hi_there["text"] = "Hello World\n(click me)"
        self.hi_there["command"] = self.say_hi
        self.hi_there.pack(side="top")
        self.quit = tk.Button(self, text="QUIT", fg="red",
                              command=self.master.destroy)
        self.quit.pack(side="bottom")
    def say_hi(self):
        print("hi there, everyone!")
root = tk.Tk()
app = Application(master=root)
app.mainloop()
EOF
python hellotcltk.py

----------
-- LaTeX
----------
cat > hello.tex << EOF
\documentclass[a4paper]{article}
\begin{document}
Hello world!
\end{document}
EOF
latex hello.tex
dvi2tty hello.dvi

----------
-- sqlite
----------
cat > hello.sql << EOF
create table test ( testid primary key, name varchar(128) not null );
insert into test values (1, "hello");
insert into test values (2, "world");
select * from test;
EOF
cat hello.sql | sqlite3 hello.db

-----------------------------
---- mysql
-----------------------------
cat > hello-mysql.sql << EOF
create database scratch;
use scratch;
create table test ( testid int not null, name varchar(128) not null, primary key(testid) );
insert into test values (1, "hello");
insert into test values (2, "world");
select * from test;
drop table test;
drop database scratch;
EOF
mysql -u root -p < hello-mysql.sql

-----------------------------
---- apache, php, xdebug
-----------------------------
sudo -s
cat << 'EOF' > /usr/local/www/apache24/data/index.php
<?php
    echo '<html><body><h1>PHP works!</h1></body></html>';
?>
EOF
echo '<?php phpinfo();?>' > /usr/local/www/apache24/data/phpinfo.php
server
exit

browse to:
browse to http://localhost
browse to http://localhost/index.html
browse to http://localhost/phpinfo.php

(look for xdebug in php info output)

php -r 'echo "Hello! This is a php program.\n";'

# if everything's cool and you didn't wreck the system, clean up
sudo bectl destroy -o languages


----------



## Alain De Vos (Jun 21, 2021)

I added these lines in .zshrc, as each language has an install directory

```
export PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:/home/x/bin
export PATH=$PATH:/home/x/.local/bin # PYTHON PIP
export PATH=$PATH:/home/x/.rvm/bin   # RUBY
export PATH=$PATH:/home/x/go/bin     # GO
export PATH=$PATH:/home/x/perl5/bin  # PERL
```


----------

