Friday, June 21, 2024
How to set up a Java project on Linux?
Gradle
Gradle is a powerful and flexible build automation tool primarily used in software development to manage and automate the build processes of projects. It is often used for building, testing, and distributing software applications and libraries. Gradle is designed to handle projects of various sizes and complexities and is particularly well-suited for large-scale and multi-module projects.
Let's install the Java package:
sudo apt install default-jdk -y
Test installation:
java --version
Let's download Gradle package:
wget -c https://services.gradle.org/distributions/gradle-8.3-bin.zip -P /tmp
...and unzip into /opt directory:
sudo unzip -d /opt/gradle /tmp/gradle-8.3-bin.zip
We must setup ENV:
sudo nano /etc/profile.d/gradle.sh
sudo chmod +x /etc/profile.d/gradle.sh
Where we add into file:
export GRADLE_HOME=/opt/gradle/gradle-8.3
export PATH=${GRADLE_HOME}/bin:${PATH}
WE MUST RESTART SYSTEM!
Project
Let's prepare project:
mkdir mojProjekt
cd ./mojProjekt
gradle init
The command gradle init is used to initialize (set up) a new project or module in Gradle. This command helps create the basic structure of the project, including configuration files and other resources needed for building and managing the project.
Okay, now we can see whole structre with "tree" command:
We open "App.java" in text editor:
Project is compiled with:
gradle build
And finally, run:
gradle run
Happy coding!
Labels: java, linux
Tuesday, June 18, 2024
How to set up a PHP development server on Ubuntu 22.04
We have optimized the PHP/MariaDB server and, of course, require a read-write server configuration that allows editing files from our standard user account.
Although the PHP development server is useful, it is not entirely identical to the server where our project will be implemented. For example, issues may arise during the installation of a WordPress project. Specifically, issues may occur with HTTP requests, which could result in the server being stuck in an infinite loop.
Destination directory
For instance, we already have a /srv directory, so we will use it for our projects. We choose the public directory because some development frameworks recommend using the public directory for storing project files.
sudo mkdir /srv/webroot/
sudo mkdir /srv/webroot/public/
sudo mkdir /srv/phpmyadmin
sudo chgrp www-data /srv/webroot/public/
sudo chmod g+rwxs /srv/webroot/public/
sudo chgrp www-data /srv/webroot/
sudo chmod g+rwxs /srv/webroot/
sudo chgrp www-data /srv/phpmyadmin/
sudo chmod g+rwxs /srv/phpmyadmin/
Group
"www-data" is the group where Apache server data is stored. Therefore, let's add the user to that group to establish read and write access.
sudo usermod -a -G www-data korisnik
default.conf
Create backup of
“000-default.conf” file:
sudo cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/000-default.conf.backup
...and in original file we add:
# /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerAdmin webmaster@localhost
# DocumentRoot /home/korisnik/Servers/webroot/public
DocumentRoot /srv/webroot/public/
<Directory /srv/webroot/public>
Options Indexes FollowSymLinks
# AllowOverride None
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:8080>
ServerAdmin webmaster@localhost
DocumentRoot /srv/phpmyadmin
<Directory /srv/phpmyadmin>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
Then add 8080 to
‘/etc/apache2/ports.conf’ file:
Listen 8080
Reboot
Restart you machine after doing all of this!
Logs
We will use
Glogg application to read logs.
sudo apt-get install glogg
You can find logs in directory:
/var/log/apache2/
We will need to add user to
adm group (only on
Debian systems):
Additional: Can't edit files from PHP
Open file:
sudo nano /etc/apache2/envvars
Add yourself as user:
# export APACHE_RUN_USER=www-data
export APACHE_RUN_USER=your_username
And finally, we restart service:
sudo systemctl restart apache2
Labels: linux, php
Imagemagick - notes
ImageMagick is a powerful and widely-used software package for manipulating and converting digital images. It provides a command-line interface and a set of libraries that allow programmers to read, write, and manipulate images in various formats. ImageMagick supports a wide range of image file types, including popular formats such as JPEG, PNG, GIF, TIFF, and BMP, as well as more specialized formats.
webp to png
mogrify -format PNG *.webp
pdf to png
convert -density 300 input.pdf -quality 100 output.png
split to four equal images
convert input.jpg -crop 2x2@ +repage /tmp/input_piece%02d.jpg
Labels: bash, design, linux