Home > Back-end >  How to properly setup my environment to develop with PHP in Ubuntu 22.04 LTS?
How to properly setup my environment to develop with PHP in Ubuntu 22.04 LTS?

Time:08-08

I am a noob on PHP development, and I am trying to properly setup my environment. All I did was install the Lamp stack on my pc (I installed them separately).

The problem is that in Ubuntu the DocumentRoot folder is located in "/var/www/html" which is a root folder, so developing inside it is really troublesome. Then my idea was to change the DocumentRoot folder to a folder like "/home/user/..." but the problem is that I always get the 403 forbidden error, no matter what I do.

Ialready changed the DocumentRoot folder inside apache2.conf, the 000-default.conf, changed the permissions by running chmod and chwon, tried to add a new site inside of sites-available folder, like I did everything I could find online, but I can't get rid of this error.

So I am doing something wrong, should I be able to develop inside the default folder? I know this can be a really noob like question, but I just don't know and couldn't find any other way.

I have some experience developing in Node btw, but never used PHP and apache before, but I need to learn.

CodePudding user response:

Here is One Way (Probably not the best but it works)

You can stick to using /var/www/html but whatever folders you decide to use you will need to set the User and Groups correctly.

Out of the box Apache2 uses owner:group of www-data for both.

In /etc/apache2/apache2.conf where APACHE_RUN_USER and APACHE_RUN_GROUP are defined in /etc/apache2/envvars

export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data

So you could change those to suit OR simply add your user to the www-data group... NOTE if you do decide to alter these you will need to restart the apache2 server.

To add your user to the www-data group.

sudo usermod -a -G www-data $USER

Where $USER will be your currently logged in username. If your user name is "Fred" you can simply type that in place of $USER. NOTE: You will need to log out and log back in for the change to take effect.

You can check this with the command

$ groups

which should show your user being in the www-data group.

And then you could go...

sudo chown -R $USER:www-data /var/www/html/

And depending upon your project you'll need to set whatever permissions on your Folders/Files you need.

  • Related