Keep your system up-to-date:
sudo apt update
sudo apt upgrade -y
Add the PHP PPA and install PHP 8.1 along with necessary extensions:
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update
sudo apt install php8.1 php8.1-dev php8.1-mysql php8.1-cli php-pear build-essential php8.1-common php8.1-zip php8.1-gd php8.1-mbstring php8.1-curl php8.1-xml php8.1-bcmath -y
Install Apache and configure it for PHP:
sudo apt install apache2 libapache2-mod-php
sudo apt install mysql-server
sudo a2enmod rewrite
sudo a2enmod php8.1
sudo apache2ctl configtest
sudo systemctl restart apache2
Update the default Apache configuration file:
sudo nano /etc/apache2/sites-available/000-default.conf
Add the following inside the <VirtualHost *:80>
block:
<Directory /home/user_name/mutall_projects>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
DocumentRoot /home/user_name/mutall_projects
Set permissions for the project directory:
sudo chown -R www-data:www-data /home/user_name/mutall_projects
sudo chmod -R 755 /home/user_name/mutall_projects
sudo pecl install ds
sudo pecl install pdo_mysql
Edit the PHP configuration files:
sudo nano /etc/php/8.1/apache2/php.ini
sudo nano /etc/php/8.1/cli/php.ini
Uncomment these lines:
extension=pdo_mysql
extension=ds.so
sudo apt-get install phpmyadmin
If needed, enable Apache configuration:
sudo a2enconf phpmyadmin
sudo systemctl restart apache2
If phpMyAdmin is not accessible, add the alias:
sudo nano /etc/apache2/sites-available/000-default.conf
Add inside <VirtualHost *:80>
:
Alias /phpmyadmin /usr/share/phpmyadmin
Restart Apache:
sudo systemctl restart apache2
Access MySQL:
sudo mysql
Run these SQL commands:
CREATE USER 'phpmyadmin'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'phpmyadmin'@'localhost' WITH GRANT OPTION;
FLUSH PRIVILEGES;
Secure the installation:
sudo mysql_secure_installation
sudo systemctl restart php8.1-fpm
sudo systemctl restart apache2
Create a test PHP file:
echo "" | sudo tee /home/user_name/mutall_projects/test.php
Access the file in your browser: http://localhost/test.php