Absolute Rookie: Testing info.php and getting the code

Ubuntu 20.04 LTS, Linode 2GB
Apache 2.4
mysql Ver 8.0.19-0ubuntu5 for Linux on x86_64
PHP 7.4.3

I have installed a LAMP stack using the instructions on https://www.linode.com/docs/web-servers/lamp/how-to-install-a-lamp-stack-on-ubuntu-18-04/ and I worked through this guide as well https://www.linode.com/docs/websites/hosting-a-website-ubuntu-18-04/

When I go to test the info.php to verify that PHP is working, I just get the code. I checked the syntax and verified that everything is running. The Apache2 "It Works" default page shows up as expected when I test the IP in a browser.

Is there something that I'm missing for this configuration (PHP 7.4.3)? Modules? I've gone back through the config files a million times and tried to tick through solutions that other users/blogs have suggested. Alot of what is out there seems outdated when it comes to PHP 7.4 so I'm trying to be mindful and deliberative in my troubleshooting. I'm thinking that somehow I set PHP up wrong. Do I start over??

Again, I'm a complete idiot when it comes to this stuff - I'm a GIS guy just trying to set up a web mapping server lol. Go easy on me

32 Replies

It would be helpful if you posted your Apache configuration for this. FWIW, this is quite a common problem that we've probably all encountered at one time or another.

-- sw

If you're using PHP-FPM (the FastCGI Process Manager) which is the recommended way nowadays, you need to enable the configuration:

a2enconf php7.4-fpm

Then restart Apache.

systemctl restart apache2

@stevewi

Thanks so much for responding! What is the best way to post/share the contents of apache2.conf? Is there a way to post code in here and avoid Markdown so everything isn't huge font from the '#'s?

@andysh

Thanks for your help! I tried a2enconf php7.4-fpm and got this

ERROR: Conf php7.4-fpm does not exist!

@jgale73 --

You write:

Thanks so much for responding! What is the best way to post/share the contents of apache2.conf? Is there a way to post code in here and avoid Markdown so everything isn't huge font from the '#'s?

Post it between lines of 3 backticks (```). That's the Markdown marker for code.

As for your problems a2enconf, you actually need to do a few things here:

  • Make sure php-fpm is installed (I believe you need to install it explicitly):

sudo apt-get install php-fpm

  • Enable the configuration for php-fpm. As @andysh said, you need to enable the apache2 configuration for php-fpm. Go to /etc/apache2/conf-available and look for something with a name like php<version>-fpm and:

sudo a2enconf php<version>-fpm

and make sure it's running:

sudo systemctl start php<version>-fpm

You can find out what <version> should be from

php --version

  • In order to get requests for PHP pages to work with php-fpm you need to load/configure a couple of modules:

sudo a2enmod proxy
sudo a2enmod proxy_fcgi

  • Restart apache2.

sudo systemctl restart apache2

Just FYI, there are several utilities for managing apache2 configuration:

  1. a2[en|dis]conf -- enable/disable configurations;
  2. a2[en|dis]mod -- enable/disable modules; and
  3. a2[en|dis]site -- enable/disable sites.

They are your friends.

  • Once you get everything running right, you can cause php<version>-fpm and apache2 to start up at boot time with

sudo systemctl enable apache2
sudo systemctl enable php<version>-fpm

To disable boot-start, use the same commands but substitute disable.

I hope this helps.

-- sw

@stevewi

Really appreciate your help! I think we're on the right track here, but when I try

sudo systemctl start php 7.4 -fpm

I get this…

Failed to start php.service: Unit php.service not found.
Failed to start 7.4.service: Unit 7.4.service not found.

Here is what I get on the version:

php --version
PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

I checked the status and it seems to be running..

systemctl status php7.4-fpm
● php7.4-fpm.service - The PHP 7.4 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php7.4-fpm.service; enabled; vendor pr>
Active: active (running) since Tue 2020-05-05 10:36:29 MDT; 13min ago
Docs: man:php-fpm7.4(8)
Process: 19256 ExecStartPost=/usr/lib/php/php-fpm-socket-helper install /ru>
Main PID: 19238 (php-fpm7.4)
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req>
Tasks: 3 (limit: 2282)
Memory: 7.4M
CGroup: /system.slice/php7.4-fpm.service
├─19238 php-fpm: master process (/etc/php/7.4/fpm/php-fpm.conf)
├─19254 php-fpm: pool www
└─19255 php-fpm: pool www

@jgale73

That's great, so the PHP-FPM side of things is good.

Just to give you a bit of background - there are 2 ways to run PHP with Apache. You can use PHP-FPM, which is a separate service that Apache talks to that specifically manages PHP processes. Or you can use the PHP module, which embeds the PHP runtime within the Apache processes.

The second approach works perfectly fine but isn't very performant and is memory-hungry when your Apache deals with a lot of requests, so the preferred approach is to use PHP-FPM.

If the previous guides you followed asked you to install the PHP Apache module, the PHP-FPM config won't be applied.

So uninstall this module:

apt remove libapache2-mod-php7.4

Ensure the PHP-FPM config is enabled:

a2enconf php7.4-fpm

As @stevewi said, ensure these 2 modules are enabled:

sudo a2enmod proxy
sudo a2enmod proxy_fcgi

Finally give Apache a kick:

systemctl restart apache2

Awesome, did all of that without issue. How do you guys recommend testing it in the browser? I've been using the info.php file test and just tried it again, and I still get just the code

@andysh

You write:

The second approach works perfectly fine but isn't very performant and is memory-hungry when your Apache deals with a lot of requests, so the preferred approach is to use PHP-FPM.
 
If the previous guides you followed asked you to install the PHP Apache module, the PHP-FPM config won't be applied.
 
So uninstall this module:
 
apt remove libapache2-mod-php7.4

The biggest problem, however with mod_php is that it's not thread-safe…so, if you want to use it, you're stuck with the old, mid-1990s- vintage prefork style of multiple-request handling (multiple processes that spawn/die periodically to service requests)…with all of its embedded cruft to save process-fork latency. It's slow and has a pretty heavy-duty impact on system resources. Rock-solid though…

In later years, apache2 has come up with event and worker styles of multiple-request handling. These use threads instead of processes. worker is basically prefork with threads replacing processes -- somewhat faster and less consumptive of system resources but fairly inefficient.

event is the newest style…it was written from the ground up to be multi-threaded (and to manage the threads effectively). It's the least impactful on system resources with (IMHO) the best performance. I use event

As worker and event have aged (and improved), prefork is starting to fade away…except for commercial shared-hosting environments that are still running on kernels that don't or barely-support threads (or still use the long-ago-deprecated apache-1.3).

@jgale73 --

You write:

Awesome, did all of that without issue. How do you guys recommend testing it in the browser? I've been using the info.php file test and just tried it again, and I still get just the code

Post the apache config for your site (between the three-backtick lines) and we can take a look. This is an easy problem to solve… I know I've run into it…I'm sure @andysh has as well.

Also, post the content of info.php between 3-backtick lines too… That will be helpful in diagnosis as well.

-- sw

``` # This is the main Apache server configuration file.

#
#
# Summary of how the Apache 2 configuration works in Debian:
# The Apache 2 web server configuration in Debian is quite different to
# upstream's suggested way to configure the web server. This is because Debian's
# default Apache2 installation attempts to make adding and removing modules,
# virtual hosts, and extra configuration directives as flexible as possible, in
# order to make automating the changes and administering the server as easy as
# possible.

# It is split into several files forming the configuration hierarchy outlined
# below, all located in the /etc/apache2/ directory:
#
#    /etc/apache2/
#    |-- apache2.conf
#    |   `--  ports.conf
#    |-- mods-enabled
#    |   |-- *.load
#    |   `-- *.conf
#    |-- conf-enabled
#    |   `-- *.conf
#     `-- sites-enabled
#        `-- *.conf
#
#
# * apache2.conf is the main configuration file (this file). It puts the pieces
#   together by including all remaining configuration files when starting up the
#   web server.
#
# * ports.conf is always included from the main configuration file. It is
#   supposed to determine listening ports for incoming connections which can be
#   customized anytime.
#
# * Configuration files in the mods-enabled/, conf-enabled/ and sites-enabled/
#   directories contain particular configuration snippets which manage modules,
#   global configuration fragments, or virtual host configurations,
#   respectively.
#
#   They are activated by symlinking available configuration files from their
#   respective *-available/ counterparts. These should be managed by using our
#   helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2disconf. See
#   their respective man pages for detailed information.
#
# * The binary is called apache2. Due to the use of environment variables, in
#   the default configuration, apache2 needs to be started/stopped with
#   /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 directly will not
#   work with the default configuration.


# Global configuration
#

#
# ServerRoot: The top of the directory tree under which the server's
# configuration, error, and log files are kept.
#
# NOTE!  If you intend to place this on an NFS (or otherwise network)
# mounted filesystem then please read the Mutex documentation (available
# at <URL:http://httpd.apache.org/docs/2.4/mod/core.html#mutex>);
# you will save yourself a lot of trouble.
#
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"

#
# The accept serialization lock file MUST BE STORED ON A LOCAL DISK.
#
#Mutex file:${APACHE_LOCK_DIR} default

#
# The directory where shm and other runtime files will be stored.
#

DefaultRuntimeDir ${APACHE_RUN_DIR}

#
# PidFile: The file in which the server should record its process
# identification number when it starts.
# This needs to be set in /etc/apache2/envvars
#
PidFile ${APACHE_PID_FILE}

#
# Timeout: The number of seconds before receives and sends time out.
#
Timeout 300

#
# KeepAlive: Whether or not to allow persistent connections (more than
# one request per connection). Set to "Off" to deactivate.
#
KeepAlive On

#
# MaxKeepAliveRequests: The maximum number of requests to allow
# during a persistent connection. Set to 0 to allow an unlimited amount.
# We recommend you leave this number high, for maximum performance.
#
MaxKeepAliveRequests 50

#
# KeepAliveTimeout: Number of seconds to wait for the next request from the
# same client on the same connection.
#
KeepAliveTimeout 5


# These need to be set in /etc/apache2/envvars
User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

#
# HostnameLookups: Log the names of clients or just their IP addresses
# e.g., www.apache.org (on) or 204.62.129.132 (off).
# The default is off because it'd be overall better for the net if people
# had to knowingly turn this feature on, since enabling it means that
# each client request will result in AT LEAST one lookup request to the
# nameserver.
#
HostnameLookups Off

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the severity of messages logged to the error_log.
# Available values: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the log level for particular modules, e.g.
# "LogLevel info ssl:warn"
#
LogLevel warn

# Include module configuration:
IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

# Include list of ports to listen on
Include ports.conf


# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
    Options FollowSymLinks
    AllowOverride None
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride None
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride None
    Require all granted
</Directory>

#<Directory /srv/>
#    Options Indexes FollowSymLinks
#    AllowOverride None
#    Require all granted
#</Directory>




# AccessFileName: The name of the file to look for in each directory
# for additional configuration directives.  See also the AllowOverride
# directive.
#
AccessFileName .htaccess

#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>


#
# The following directives define some format nicknames for use with
# a CustomLog directive.
#
# These deviate from the Common Log Format definitions in that they use %O
# (the actual bytes sent including headers) instead of %b (the size of the
# requested file), because the latter makes it impossible to detect partial
# requests.
#
# Note that the use of %{X-Forwarded-For}i instead of %h is not recommended.
# Use mod_remoteip instead.
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

# Include of directories ignores editors' and dpkg's backup files,
# see README.Debian for details.

# Include generic snippets of statements
IncludeOptional conf-enabled/*.conf

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet


<FilesMatch \.php$>

SetHandler application/x-httpd-php7

</FilesMatch>
<?php
phpinfo();
?>

Again, I'm grateful for the help! I've been spinning my wheels on this for a while now.

@jgale73 --

Your PHP file looks ok. The configuration module php7.4-fpm.conf that you enabled with sudo a2enconf php7.4-fpm has a much-more-encompassing version of your <FilesMatch>...</FilesMatch> directives.

Here's what I would do:

First, remove the <FilesMatch>...</FilesMatch> directives. You can comment them out by preceding each line with a #. You don't need them.

Second, do this:

sudo grep -E '^\s*listen\s*=\s*[a-zA-Z/]+' /etc/php/7.4/fpm/pool.d/www.conf

You should get back something that looks like this:

listen = /var/run/php/php7.4-fpm.sock

or

listen = /run/php/php7.4-fpm.sock

These are equivalent.

If you don't find the above, or get something like

listen = 127.0.0.1:9000

you'll have to change the configuration of php-fpm accordingly. You want to use the first form…not the second (comment out the form you have and insert the form you want; save the file and restart php-fpm). If things were successful, after the restart, you should have a file called php7.4-fpm.sock in [/var]/run/php.

This is the (working) configuration from a PHP-based site I maintained. The only difference is that I use PHP 7.3.

Don't forget to restart php-fpm and apache2 as appropriate.

Let us know how this goes…

-- sw

@stevewi is exactly right, although I’ve never had to fiddle to that depth with the default config files on a standard install (other than the time I upgraded Apache 2.2 to 2.4 and had to figure out how it all worked as the standard OS packages hadn’t caught up with the changes!)

If you’re still seeing the PHP code, Apache isn’t even trying to send the request to PHP-FPM. I totally agree with @stevewi, that < FilesMatch > section is trying to send the request through the older PHP module, so that can be removed.

Failing that, can you run “ls /etc/apache2/conf-enabled” and “ls /etc/apache2/mods-enabled” and post the results? (Sorry for the lack of formatting, I’m on a mobile that doesn’t have a backtick character on the keyboard!)

If you’re still stuck in about 12 hours time when I’m awake again, I don’t mind firing up a 20.04 Linode and documenting my steps to get this simple example working for you.

BINGO!! That did the trick, I get the proper phpinfo page now. I can't thank you guys enough. I would have NEVER figured this out. Many thanks!

Last questions, I promise:
Where do you recommend going from here. Do I continue to the "Add DNS Records" guide? Is there a way to test one of my website pages - or is that down the road more? The guides take you to DNS and Reverse DNS then that's it. My website is ready to go and has been live before..difference is that somebody else set up the server, I just had to drop the website into the public html folder.

Brilliant!

Getting your site on the Linode now will depend on the website and CMS used. Typically you will have your files and a database.

Will you be likely to host multiple websites on your Linode in future?

If not, you could get away with putting your website files into /var/www/html and voila.

Alternatively you can create a directory /var/www/yourwebsite.com, and copy the default site configuration file in /etc/apache2/sites-available/000-default.conf - e.g. “cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/yourwebsite.com.conf”

Then edit /etc/apache2/sites-available/yourwebsite.com.conf to set the DocumentRoot to /var/www/yourwebsite.com and the ServerName to yourwebsite.com.

Finally enable your site with “a2ensite yourwebsite.com”

I find to test your site, before you touch the DNS, set up your server with the actual domain name and change your local machine’s hosts file to fool your machine into thinking that yourwebsite.com lives on your.linode.ip.address. That way you can test your Linode yourself whilst everyone else is still looking at your current hosting.

Here’s a good article that explains the hosts file and how to change it: https://www.hostgator.com/help/article/how-do-i-change-my-hosts-file

When you’re ready to switch over, this will involve changing your DNS records for yourwebsite.com to point to your Linode’s IP address. If your DNS is wrapped up with your current hosting package, you’ll need to set your domain up on Linode’s DNS service and give it up to 30 minutes to activate, before switching your domain’s nameservers at the registrar.

If you do need to change the nameservers, I’d recommend you change the IP address of yourwebsite.com to your Linode first with your current provider, before you change the nameservers.

@andysh --

The only reason I know all that stuff about php-fpm's configuration is back on Ubuntu 12.04 (Pharting PoolFrog…or whatever it was called…it was "P" though), I installed PHP from a PPA just to get support for master/server IPC using local-domain sockets (to boost PHP performance). The released packages only supported internet-domain sockets for this.

There's lots of wonderful stuff /etc/php/7.4/fpm/pool.d/www.conf:

  • location/permissions of the socket;
  • stuff about the number/characteristics of php-fpm pool servers;
  • log locations/formats;
  • etc etc etc

You can have more one "named" set of servers (defined by multiple .conf files /etc/php/7.4/fpm/pool.d) -- each with separate proxy sockets -- for segmentation of PHP proxy requests to the master by whatever criteria you chose (by site for example). This is all light years ahead of anything you could do with mod_php!

@jgale73 … Glad you got it working!

-- sw

Yes indeed, I like the idea of more than one "named" set of servers and I'm really impressed with what one can do with all of this. It is mind boggling, quite frankly.

Since I'm GIS/ mapping guy, and somewhat OCD, I've had this mapping and mobile application stuck in my head for years. Last year in my graduate program I got a chance to develop my idea as a website and host it on the University server. Once I saw that it was viable, I had to at least try to get it out there. It's very primitive in terms of website design as I pretty much taught myself HTML, CSS, JAVA along the way. What drives the site is real-time and near-real-time data and the mapping elements are beautiful. I savor the challenge of wading into areas like this (Linux, Apache, PHP, MYSQL) where I am completely lost. My career has been one of baptism by fire, so what the hell.

I am so impressed with the kind of support you guys provided here, and the knowledge base that is built up in these communities. Part of my "day job" is software support for mapping applications, so I can certainly appreciate how much we accomplished today. It's good to be here, even as I continue to blunder my way through this. Again, many thanks, like I said, I would have never figured this out.

@jgale73 --

You're quite welcome! I'm glad I could help!

So, with respect to the .conf files in /etc/php/7.4/fpm/pool.d… Suppose you have 3 files:

  • www.conf
  • foo.conf
  • bar.conf

Each defines set of servers:

  • php-fpm: pool www
  • php-fpm: pool foo
  • php-fpm: pool bar

that all communicate with the php-fpm: master process. Here's a brief article about how to set up multiple pools in php-fpm:

https://www.cloudbooklet.com/how-to-install-php-fpm-with-apache-on-ubuntu-18-04-google-cloud/

This is how to set up a pool per virtual host. The configuration you enabled in php7.4-fpm config only sets up everything for the www pool. You've probably learned enough today to puzzle out the article!

-- sw

@stevewi

Thanks for the additional explanation, very useful!

I'm pretty familiar now with PHP-FPM, Apache and even Nginx as of the past 12 months, but it was certainly a learning curve some time ago (somewhere between 14.04 and 16.04 IIRC.)

I love PHP-FPM, it's so flexible compared to mod_php, and I prefer having the separation between PHP and the web server. For the past few years I've used Ondrej's PPA to always get the latest version of PHP and Apache, although now I use Nginx and their official repo (still use Ondrej's PPA though.)

@jgale73

No worries at all, glad we could help and best of luck with your idea!

Well, I had the everything working, then I set up the DNS lol. I followed @andysh advice above and put my site up at /var/www/html, just to test it, then got to it using the IP. It worked perfectly, so I worked up the courage to proceed with the DNS setup using the https://www.linode.com/docs/platform/manager/dns-manager/ guide.

I gave everything 3 days to propagate, then went to test the domain www.406rivermaps.com. When I try to find it in a browser, I get the old 404 Not Found error-The requested URL was not found on this server. I'm thinking that I did something wrong either in the .config files at /etc/apache2/sites-available/ or messed something up on the DNS/RDNS setup.

I've spent some time looking in to it and used the intodns.com site to get a report on the DNS. There is a red flag for the NS and SOA regarding the nameservers (recursive queries and "NSs have same SOA serial"). I could post the report if it helps.

Again, I'm at that familiar point where I need to seek advice before goofing around with things and making it worse. I'd be grateful for any thoughts on how to troubleshoot.

Many Thanks!
JG

@jgale73 --

You write:

I've spent some time looking in to it and used the https://intodns.com site to get a report on the DNS. There is a red flag for the NS and SOA regarding the nameservers (recursive queries and "NSs have same SOA serial"). I could post the report if it helps.

http://intodns.com doesn't like the way Linode configures it's name servers. You can't control that. Don't worry about it.

You write:

I gave everything 3 days to propagate, then went to test the domain www.406rivermaps.com. When I try to find it in a browser, I get the old 404 Not Found error-The requested URL was not found on this server. I'm thinking that I did something wrong either in the .config files at /etc/apache2/sites-available/ or messed something up on the DNS/RDNS setup.

I think your DNS is ok. A ping[6] of both 406rivermaps.com and www.406rivermaps.com resolve ok. I think its your website configuration(s). If you could post those, that would be very helpful.

Also, listings (the output of ls -l) for

/etc/apache2/sites-available
/etc/apache2/sites-enabled

would be helpful too.

Thanks in advance…

-- sw

Thanks @stevewi

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf```
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet 
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerName 406rivermaps.com
    ServerAlias www.406rivermaps.com
    #ServerAdmin webmaster@406rivermaps.com
    DocumentRoot /var/www/406rivermaps.com

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
# domain: 406rivermaps.com
# public: /var/www/html/406rivermaps.com/public_html/

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  #ServerAdmin webmaster@406rivermaps.com
  ServerName  406rivermaps.com
  ServerAlias www.406rivermaps.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/406rivermaps.com
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/406rivermaps.com/log/error.log
  CustomLog /var/www/html/406rivermaps.com/log/access.log combined
</VirtualHost>

ls -l

total 156
-rw-r--r-- 1 root root 149919 May 2 19:46 'sudo journalctl'
-rw-r--r-- 1 root root 883 May 3 20:35 'sudo systemctl restart apache2'
-rw-r--r-- 1 root root 1134 May 3 15:58 'udo systemctl restart apache2'

/etc/apache2/sites-available

  • 000-default.conf
  • 406rivermaps.com.conf
  • default-ssl.conf

/etc/apache2/sites-enabled

  • 406rivermaps.com.conf
  • example.com.conf

@jgale73 --

Thanks.

You write:

ls -l
 
total 156
-rw-r--r-- 1 root root 149919 May 2 19:46 'sudo journalctl'
-rw-r--r-- 1 root root 883 May 3 20:35 'sudo systemctl restart apache2'
-rw-r--r-- 1 root root 1134 May 3 15:58 'udo systemctl restart apache2'

I don't know what or where these are. They look like failed attempts at output redirection…

You write:

/etc/apache2/sites-enabled
 
406rivermaps.com.conf
example.com.conf

example.com.conf is extraneous and is probably a dangling symlink. You can get rid of it by:

sudo rm -f /etc/apache2/sites-enabled/example.com.conf

-- sw

[@jgale73] (/community/user/jgale73) --

You write:

ServerAdmin webmaster@localhost
DocumentRoot /var/www/html

...

    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet 

The </VirtualHost> is an error… There's no opening <VirtualHost>. You need to remove it.

-- sw

@jgale73 --

You write:

<VirtualHost *:80>

    ...

    #ServerName www.example.com

    ServerName 406rivermaps.com
    ServerAlias www.406rivermaps.com
    #ServerAdmin webmaster@406rivermaps.com
    DocumentRoot /var/www/406rivermaps.com

    ...

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    ...

    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

...

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  #ServerAdmin webmaster@406rivermaps.com
  ServerName  406rivermaps.com
  ServerAlias www.406rivermaps.com

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /var/www/html/406rivermaps.com
  # Log file locations
  LogLevel warn
  ErrorLog  /var/www/html/406rivermaps.com/log/error.log
  CustomLog /var/www/html/406rivermaps.com/log/access.log combined
</VirtualHost>

So, if one <VirtualHost> definition is good, two must be better, eh? ;-) You have two different definitions of the same <VirtualHost>. I can't tell if these are in two different files or just one. If it's two files, get rid of the first one. If all this is in a single file, remove everything between and including the first <VirtualHost></VirtualHost> pair.

Also, in the second <VirtualHost></VirtualHost> pair, these:

ErrorLog  /var/www/html/406rivermaps.com/log/error.log
CustomLog /var/www/html/406rivermaps.com/log/access.log combined

put the log files in the <DocumentRoot>. You don't (ever!) want to do this. Change these to look like this:

    ErrorLog ${APACHE_LOG_DIR}/406rivermaps.error.log
    CustomLog ${APACHE_LOG_DIR}/406rivermaps.access.log combined

and they'll go to the same place as the server log files. This location may be the file system root (/) if ${APACHE_LOG_DIR} is not defined.

FWIW, here is a link to the Apache2 documentation: http://httpd.apache.org/docs/2.4/

-- sw

Viola! Thanks so much @stevewi

I'm glad that I asked for help and stopped crap shooting solutions. I don't know why I had two virtual host definitions…the setup guide isn't that clear, just says to plug in your domain and call it good.

Regardless, us rookies should verse ourselves in the fundamentals a little before wading in. Hopefully I'll be able to help people here someday.

What are your thoughts on SSL? I was going to work these steps next
https://www.linode.com/docs/security/ssl/install-lets-encrypt-to-create-ssl-certificates/

Again, many thanks for your time and expertise!
JG

@jgale73

SSL is a good thing. For a mapping site like yours it’s prob going to be a requirement.

I just helped another user with LetsEncrypt… it was pretty easy. The certbot took care of everything.

If you end up setting up mail on your site you can use the same cert for secure SMTP, POP3s & IMAPs…as long as the domain name is the same.

— sw

Excellent, thanks for your thoughts on that. I will proceed with caution

For future reference,

/usr/sbin/apachectl -t

will do a syntax check on your configuration. It can save you a lot of grief!

— sw

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct