Apache and PHP newbie help installing

Discussions Regarding Software

Moderator: Moderators

Post Reply
Douglas_E_Knapp
Growing Hen
Posts: 113
Joined: Sat Nov 03, 2012 8:53

Apache and PHP newbie help installing

Post by Douglas_E_Knapp » Sun Jan 15, 2017 11:10

Hello,
I am clueless. I have equo i appache2 and php but I can't seem to learn how to make it open up a simple webpage or.php. What settings do I need to change? Where should the website be placed in directory? Can I change that? How should my browser point at the page? I want to do this locally only for the moment so that I can white and test web sites.

Thanks lots,

The lost one.
Douglas E Knapp

[edit by sabayonino] : edited thread title as "Apache and PHP newbie help installing"

joost
Sagely Hen
Posts: 2742
Joined: Fri Nov 17, 2006 12:11
Location: The Netherlands
Contact:

Re: Appache2 and PHP newbie help installing

Post by joost » Mon Jan 16, 2017 11:35

First of all it is Apache, not appache2. (https://httpd.apache.org/)

After install you should first of all make sure apache server is running.

From a root shell you can check:

Code: Select all

linux1 ~ # systemctl status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib64/systemd/system/apache2.service; enabled; vendor preset: enabled)
   Active: active (running) since Tue 2017-01-03 01:23:10 CET; 1 weeks 6 days ago
  Process: 24125 ExecReload=/usr/sbin/apache2 $APACHE2_OPTS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 2034 (apache2)
   CGroup: /system.slice/apache2.service
           ├─ 2034 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24133 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24134 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24135 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24136 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24137 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─24138 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─26694 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           └─26695 /usr/sbin/apache2 -D DEFAULT_VHOST -D INFO -D SSL -D PHP -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND

Jan 03 01:23:10 linux1 systemd[1]: Started The Apache HTTP Server.
Jan 03 01:23:16 linux1 apache2[2034]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Jan 08 03:10:01 linux1 systemd[1]: Reloading The Apache HTTP Server.
Jan 08 03:10:02 linux1 apache2[16233]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Jan 08 03:10:02 linux1 systemd[1]: Reloaded The Apache HTTP Server.
Jan 16 03:10:01 linux1 systemd[1]: Reloading The Apache HTTP Server.
Jan 16 03:10:02 linux1 apache2[24125]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Jan 16 03:10:02 linux1 systemd[1]: Reloaded The Apache HTTP Server.
If it is not running you can do:

Code: Select all

# systemctl start apache2
If you want it to start when you boot the system you can do:

Code: Select all

# systemctl enable apache2
If you want PHP enable you first of all need PHP to be installed on the system:

Code: Select all

equo install dev-lang/php
Now we must configure the Apache webserver to load the php module:
edit /etc/conf.d/apache2
look for the line APACHE2_OPTS= and append -D PHP
Save the file and restart apache2 webserver

Code: Select all

# systemctl restart apache2
Now open a webbrowser and go to: http://127.0.0.1 (this is your localhost URL)

This will load whatever is in index file is in /var/www/localhost/htdocs on the server.
If you wish to change the defaults on where the DOCUMENTROOT is, you can have a look at the Gentoo wiki.

https://wiki.gentoo.org/wiki/Apache
https://wiki.gentoo.org/wiki/PHP
My blog | Mastodon | Please support Sabayon: Become a Patron

Douglas_E_Knapp
Growing Hen
Posts: 113
Joined: Sat Nov 03, 2012 8:53

Re: Apache and PHP newbie help installing

Post by Douglas_E_Knapp » Mon Jan 16, 2017 12:50

Ok, I believe you and thanks but why then are many of the commands apache2?

OK, I am going to log my results as I follow your help. Perhaps this will help the next seeker of answers. :-)

It would seem to be dead.

Code: Select all

 Frog-pc britta # systemctl status apache2
          ● apache2.service - The Apache HTTP Server
          Loaded: loaded (/usr/lib64/systemd/system/apache2.service; disabled; vendor preset: disabled)
          Active: inactive (dead)
Turned it on and it seems to have started but I would guess some configuration needs to happen.

Code: Select all

Frog-pc britta # systemctl -l status apache2
● apache2.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib64/systemd/system/apache2.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2017-01-16 12:13:59 CET; 49s ago
 Main PID: 3838 (apache2)
   CGroup: /system.slice/apache2.service
           ├─3838 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─3841 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─3843 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─3844 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─3845 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           ├─3846 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND
           └─3847 /usr/sbin/apache2 -D PHP -D DEFAULT_VHOST -D INFO -D SSL -D SSL_DEFAULT_VHOST -D SUEXEC -D LANGUAGE -DFOREGROUND

Jan 16 12:13:59 Frog-pc systemd[1]: Started The Apache HTTP Server.
Jan 16 12:14:00 Frog-pc apache2[3838]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Already installed PHP.
Already edited etc/conf.d/apache2.
Just started it before so don't need a restart.
Looked at the localhost and IT WORKS! is there! :-)

Then I put file:///media/Threeterabyte/Media/Website/Journey%20To%20The%20Stars/index.html in the chrome browser it opens the webpage but when I put in the same but with testphph.php it downloads the file and does NOT run it. How can this be changed?

http://127.0.0.1/testphp.php
Works just fine.

Is there anything I should do for security?

Maybe I should be googling this question but what is a virtual host and why does no need one? Is it just a new web address?

Thanks LOTS!
Douglas E Knapp.

joost
Sagely Hen
Posts: 2742
Joined: Fri Nov 17, 2006 12:11
Location: The Netherlands
Contact:

Re: Apache and PHP newbie help installing

Post by joost » Mon Jan 16, 2017 14:33

Then I put file:///media/Threeterabyte/Media/Website/Journey%20To%20The%20Stars/index.html in the chrome browser it opens the webpage but when I put in the same but with testphph.php it downloads the file and does NOT run it. How can this be changed?
Opening a file using the file:// protocol will only parse the html in the webbrowser engine. It can't process a .php file and therefor will offer it as a download.( your webbrowser can't process .php or .asp files those are processed on the server and when done the server sends the result in HTML or XML to the webclient )

Your webserver ONLY hosts files located in the documentroot.
So this translates into:

On your filesystem
/var/www/localhost/htdocs/myfile.html

In your webbrowser
http://127.0.0.1/myfile.html

I suggest you try to Google a bit and learn how things work. It is all about what happens clientside (HTML result) and what happens serverside (PHP preprocessing).
My blog | Mastodon | Please support Sabayon: Become a Patron

Douglas_E_Knapp
Growing Hen
Posts: 113
Joined: Sat Nov 03, 2012 8:53

Re: Apache and PHP newbie help installing

Post by Douglas_E_Knapp » Mon Jan 16, 2017 21:15

Thanks. I understand it without the google. The problem is finding tutorials that are aimed at people that know computers but are clueless about web servers. The tutorials are always way to dumb and poorly made or else they are super over my head without the basic assumptions spelled out. Thanks for your help.

I have one last big problem. How do I properly set the users, groups and permissions so that my user (me) can access the var/www/localhost/htdocs on sabayon. I have found so stuff but it is always for Ubuntu and Sab is not the same.
Thanks again.

Post Reply