Saturday, August 24, 2024
(2024) Install PHP and MariaDB(sql) on Linux Mint
Got a shiny new SSD? It’s the perfect opportunity to install a fresh copy of Linux Mint! Along with the new operating system, I’ll be diving into the installation of PHP and a SQL server to set up my development environment. Join me as we explore the steps to get everything up and running smoothly. Let’s dig in!
Firewall
Before anything let's check if we have firewall enabled?
sudo ufw status
If not, enable it!
sudo ufw enable
Install PHP
Install PHP 8.1
sudo apt-get install php8.1
This will also install Apache2.
Destination directory
I prefer to use /srv directory for my development server, so we will prepare it:
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 $(whoami)
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:
sudo nano /etc/apache2/sites-available/000-default.conf
# /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:
sudo nano /etc/apache2/ports.conf
Listen 8080
mod_rewrite
We will need
mod_rewrite enabled so that we can access "post_name" routes in Wordpress.
sudo a2enmod rewrite
sudo systemctl restart apache2
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/
SQL server
Install SQL server
sudo apt install mariadb-server mariadb-client
sudo mysql_secure_installation
Now download
phpMyAdmin and extract it in
/srv/phpmyadmin. After that, in your browser, go to url:
http://localhost:8080
Ah we have an issue. Extensions are missing!
sudo apt-get install php-{mysql,curl,gd,mbstring,xml,zip,intl,imagick,bcmath,json,exif,opcache,php-mysqli}
And restart:
sudo systemctl restart apache2
If you get Session errors, just restart browser few times.
PHP Projects
Go to directory:
/srv/webroot/public/
You can place Wordpress project in "public" directory and Symfony project goes in "webroot".
Additional: Can't edit files from PHP
This happens when, for example you can't install Wordpress plugin.
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