Make PHP Workspace
I use Debian 13 Trixie, but my configs will also work on Debian-based Ubuntu, Linux Mint, and other Linux distros (with slight differences).
1. First, we will install the latest version of PHP available at this time.
Add ondrej/php DPA
Because PHP 8.4 packages are not available in any of the current Debian or Ubuntu software repositories, the PHP packages must come from another repo.
Ondřej Surý maintains a package archive that contains compiled binaries of all current PHP versions, for Ubuntu and Debian. It also ships several PECL extensions including PECL extensions for PHP core extensions unbundled in PHP 8.4.
Once this repository is added, the initial installation and updates can be done with the standard apt commands.
sudo apt-get update
sudo apt-get -y install lsb-release ca-certificates curl apt-transport-https
sudo curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb
sudo dpkg -i /tmp/debsuryorg-archive-keyring.deb
sudo sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list'
sudo apt-get update
PHP CLI and PHP-FPM (recommended)
It is recommended to install PHP-FPM to integrate PHP with web-servers such as Apache, Nginx, and Caddy.
sudo apt install php8.4-cli php8.4-fpm
Install PHP Extensions
sudo apt install php8.4-common php8.4-{bcmath,bz2,curl,gd,gmp,intl,mbstring,opcache,readline,xml,zip,mysql,pgsql,redis,imagick,memcached,soap,xmlrpc,exif,ftp,ldap,sodium}
2. Install Nginx
sudo apt install nginx nginx-extras
3. Install MySQL (users using distros other than debian, type "mysql-server" instead of "mariadb-server")
sudo apt install mariadb-server
Create a custom user as desired.
sudo mysql -u root -p
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'strong_password';
CREATE DATABASE myapp_db;
GRANT ALL PRIVILEGES ON myapp_db.* TO 'myapp_user'@'localhost';
FLUSH PRIVILEGES;
exit
To connect:
mysql -u myapp_user -p myapp_db
4. Install PostgreSQL
sudo apt install postgresql postgresql-contrib
Create a custom user as desired.
sudo -u postgres psql
CREATE USER myapp_user WITH PASSWORD 'strong_password';
CREATE DATABASE myapp_db WITH OWNER myapp_user;
GRANT ALL PRIVILEGES ON DATABASE myapp_db TO myapp_user;
\q
To connect:
psql -U myapp_user -d myapp_db
5. Install Composer
sudo apt install composer
6. Install Laravel
composer global require laravel/installer
7. Install phpMyAdmin (optional)
sudo apt install phpmyadmin
Configure Nginx to use phpMyAdmin
sudo nano /etc/nginx/sites-available/default
Add the following location block inside the server
block:
location /phpmyadmin {
alias /usr/share/phpmyadmin/;
index index.php index.html index.htm;
location ~ ^/phpmyadmin/(.+\.php)$ {
alias /usr/share/phpmyadmin/$1;
fastcgi_pass unix:/run/php/php8.4-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/phpmyadmin/$1;
include fastcgi_params;
}
location ~* ^/phpmyadmin/(.+\.(jpg|jpeg|gif|css|png|js|ico|html|xml|txt))$ {
alias /usr/share/phpmyadmin/$1;
}
}
Restart Nginx
sudo systemctl restart nginx