Installing Maria DB
Last update: 23-April-2026
You can install Maria DB or other database manager separately.
I invite you to see this manual to install Maria DB.
https://linuxcastle.blogspot.com/2023/08/installing-maria-db-on-ubuntu-22.html
Install Apache2
Type on console:
sudo apt-get -y install apache2
Up to this point you can check the correct installation of apache go hadead browser and type: http:://localhost
In this case default port is 80.
Install PHP 8
Type this comand:
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Then it will be displayed as the following image:
Update apt changes
Install PHP vesion 8.1
Then it will be displayed as the following image:
Type Y for continue:
For verify php type:
Install PHP additional packages
This is an optional step.
If you need to install advanced systems you will need to install some of these packets.
Type this command for install aditional packets.
sudo apt install php8.1-mysql php8.1-mbstring php8.1-xml php8.1-curl php8.1-gd php8.1-zip php8.0-intl
Then it will be displayed as the following image:
I recommend restart apache for not restart machine.
sudo systemctl restart apache2
Config Apache publication folder
By default publication folder "/var/www/html" does not have privileges.
Change owner folder.
sudo chown www-data:www-data /var/www/html/
Type for see owner permision:
You need give change folder permission for not require root password into public folder.
sudo chmod 777 /var/www/html/
In this image you can see that folder var/www/html change color and observe permissions
You can now create new folder without need root password.
Testing public new sites.
If you followed the steps in the previous point, now you can create a file with the following command
Create a new folder:
Type this command for create a new PHP page using the command "echo".
echo "<?php echo phpinfo();" > /var/www/html/test/index.php
Go browser and type http://localhost/test/ and you should see a page like this:
Configuring Apache Mod_rewrite
This is an optional step.
If you are thinking work with some framework like yii or laravel, you will need configure a modulo for preaty urls.
The Mod_rewrite module is not enabled by default, so it has to be enabled manually, you can follow these steps to do it.
sudo systemctl restart apache2
Enable access to read .htaccess files
Edit the following file from the console with the command:
sudo nano /etc/apache2/apache2.conf
You must locate within the file the section that says:
"<Directory /var/www/>":
You must change within that section where it says
"AllowOverride None"
for
"AllowOverride All"
With this change it will be allowed to use the ".htaccess" file for all the sites that are published on the apach server.
Save file using nano with "Ctrl+w" and confirm "Y" and "Enter"
Once changed save the file.
Restart apache to apply the changes.
sudo systemctl restart apache2
Cloning new projects into Apache
I recommend doing it this way because if you clone first and just changing the permissions of your project folder inside git will show all the git files as new files. For this reason I recommend following the steps below.
I recomend first create a new folder with permison for write later clone into the folder.
Example:
chmod -R 777 /var/www/html/miprojectfolder
Ther clone into folder created "/var/www/html/miprojectfolder":
If you subfolder into your repository you have to move all content into sub folder to one level up.
mv -f /var/www/html/miprojectfolder/your_git_sub_folder/{.,}* /var/www/html/miprojectfolder/
If you need give write permissions to folders for example:
chmod -R 777 /var/www/html/miprojectfolder/runtime
Adding VirtualHost (Optional)
This examples use Yii framework for website installed on /var/www/html/auditoria
Install this FPM (FastCGI Process Manager) package: It is an alternative implementation of PHP FastCGI.
sudo apt install php8.3 php8.3-fpm
Start service
sudo systemctl start php8.3-fpm
Edit file for config virtualHost
sudo nano /etc/apache2/sites-available/auditoria.conf
<VirtualHost *:80>
ServerName auditoria.local
ServerAdmin webmaster@localhost
DocumentRoot /var/www/html/auditoria/web
<Directory /var/www/html/auditoria/web>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# PHP-FPM (socket PHP 8.3)
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.3-fpm.sock|fcgi://localhost/"
</FilesMatch>
ErrorLog ${APACHE_LOG_DIR}/auditoria_error.log
CustomLog ${APACHE_LOG_DIR}/auditoria_access.log combined
</VirtualHost>
Enable proxy_fcgi It allows setting environment variables based on request attributes (such as IP, browser, or headers).
Enable virtual host previously added
sudo a2ensite auditoria.conf
Add hosts config for resolve domain into file: /etc/hosts
Add this line on top
127.0.0.1 auditoria.local
Restart apache servide
sudo systemctl reload apache2
Try using; http://auditoria.local this will point to www/html/auditoria/web
You can add a file .txt to try read.
References:
https://tutoriales-yii2.blogspot.com/2022/08/instalar-apache-php-7.4-mysql-en-ubuntu-22.html
Comments
Post a Comment