jamroll has asked for the wisdom of the Perl Monks concerning the following question:

greetings, fellow and superior Monks to me... :)

I have just rid myself of THEE absolute worstest (yes, it's not a word) virus ever created, Windows (specifically windows 10) and upgraded to Ubuntu 17.04. I'm completely noob, so I know not all of exactly what info you folks need to assist, so forgive me if i left something critical out.

anyways, here goes.

i am fairly certain i have perl installed (although i have no clue how to check). i know i have apache2 installed - i can get it to show web pages when i point my browser at http://localhost/index.html (which i have since deleted and replaced with all my perl scripts).

i do NOT use a cgi-bin folder, cuz that just confuses the bejeepers outta me, and i don't think it's really necessary for the task at hand. I just dump all of my scripts into /var/www/html (and the modules i create are under a subfolder, ./Pm).

at first, i was getting a 403 error (forbidden). after about two hours of searching, and fiddling, i managed to get that error to go away, and now, apache2 serves up my code to the browser (which is a might bit better than the 403 error, i should add) but it's still not quite right, of course. lord knows I don't want users seeing my code....(there's nothing unbecoming of a good coder going on here, just don't want my ugly code displayed for the entire world to laugh at). alas, i just cannot figure out how to get apache2 to run the script, rather than just sending the code as plain text to the browser.

many sites are telling me to download all kinds of things and compile those things, and make tons of modifications to files in a bazillion places. when i had this setup on winblows, i had little to no problem just uncommenting "LoadModule cgi_module modules/mod_cgi.so" in the httpd.conf file...but, none of these lines exist in the apache2.conf file i find on this setup, so i hesitate just dumping that line into the conf file. so, i follow other instructions, and mod the conf file as directed, and i get this:
% sudo /etc/init.d/apache2 restart [....] Restarting apache2 (via systemctl): apache2.serviceJob for apac +he2.service failed because the control process exited with error code +. See "systemctl status apache2.service" and "journalctl -xe" for detail +s. failed! jamroll@Vaio:/usr/src$ systemctl status apache2.service ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendo +r preset: enabled) Drop-In: /lib/systemd/system/apache2.service.d └─apache2-systemd.conf Active: failed (Result: exit-code) since Sat 2017-07-15 13:41:26 PD +T; 10s ago Process: 29328 ExecStop=/usr/sbin/apachectl stop (code=exited, statu +s=1/FAILURE) Process: 29816 ExecStart=/usr/sbin/apachectl start (code=exited, sta +tus=1/FAILURE) Main PID: 28931 (code=exited, status=0/SUCCESS) CPU: 61ms Jul 15 13:41:25 Vaio systemd[1]: Starting The Apache HTTP Server... Jul 15 13:41:26 Vaio apachectl[29816]: AH00526: Syntax error on line 1 +76 of /etc/apache2/apache2.conf: Jul 15 13:41:26 Vaio apachectl[29816]: Invalid command 'PerlModule', p +erhaps misspelled or defined by a module not included in the Jul 15 13:41:26 Vaio apachectl[29816]: Action 'start' failed. Jul 15 13:41:26 Vaio apachectl[29816]: The Apache error log may have m +ore information. Jul 15 13:41:26 Vaio systemd[1]: apache2.service: Control process exit +ed, code=exited status=1 Jul 15 13:41:26 Vaio systemd[1]: Failed to start The Apache HTTP Serve +r. Jul 15 13:41:26 Vaio systemd[1]: apache2.service: Unit entered failed +state. Jul 15 13:41:26 Vaio systemd[1]: apache2.service: Failed with result ' +exit-code'. [2]+ Stopped systemctl status apache2.service
this is so very very cryptic to a total noob...

honestly, i don't wish to use cgi-bin or any other folder. i like my current setup of just dumping them all into /var/www/html it has served me well in the past, and i wish to stick with it.

um, what else...

oh yes - i wish to not have to "sudo" into the conf files all the time - my password is not easy to type. it's cumbersome having to work that way all the time for a simple one line config, or having to go in/out restart apache, realize there's an error, and repeat. can take hours to solve one little booboo and it's frustrating to have to jump through all of these hoops! is there an easier way to accomplish my taks without having to always sudo into my editor to edit the apache2.conf file? can't i just tell the system to give me unfettered access to that file? no one uses this computer but me (i have a wife, and one kid here, but they use their own machines and have no access to this machine without my really strong password, so local access can be wide open on this puppy).

so, again, if i missed something, forgive me - i'm on a MASSIVE learning curve here, and may not even realize you need more info. i'm on tilt, and a one man band as it were. I'm the host, developer and all other things web-site related. 100% alone on this. So, with that said, allow me to make one more note: I'm totally noob. so, info given has to be SIMPLE, and EASY for a noob to understand. you can't just say "chmod this file", as I may not know what that means or even how to accomplish the task (let me just add that i have figured out chmod, i just use that as an example of how you might confuse Jarett by saying "just do this"...it's NOT that simple)...i'm transitioning from winblows to linux so i have all these silly MS notions in my head. best if you can relate windows to linux for me....i'm a quick study - certainly am well versed in the techy world, so some jargon is okay, save for linux jargon, you might lose me...see?

I hope i have conveyed well enough, and pray you guys get it and don't poop on me too hard for missing some details...i'm happy to do exactly what you need from me....

sincerely on tilt,

jarett

oh...i guess you'd like to see my apache2.conf file, eh? lol

in its entirety:

# This is the main Apache server configuration file. It contains the # configuration directives that give the server its instructions. # See http://httpd.apache.org/docs/2.4/ for detailed information about # the directives and /usr/share/doc/apache2/README.Debian about Debian + specific # hints. # # # Summary of how the Apache 2 configuration works in Debian: # The Apache 2 web server configuration in Debian is quite different t +o # upstream's suggested way to configure the web server. This is becaus +e Debian's # default Apache2 installation attempts to make adding and removing mo +dules, # virtual hosts, and extra configuration directives as flexible as pos +sible, 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 o +utlined # 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 t +he pieces # together by including all remaining configuration files when start +ing up the # web server. # # * ports.conf is always included from the main configuration file. It + is # supposed to determine listening ports for incoming connections whi +ch 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 fro +m their # respective *-available/ counterparts. These should be managed by u +sing our # helpers a2enmod/a2dismod, a2ensite/a2dissite and a2enconf/a2discon +f. See # their respective man pages for detailed information. # # * The binary is called apache2. Due to the use of environment variab +les, in # the default configuration, apache2 needs to be started/stopped wit +h # /etc/init.d/apache2 or apache2ctl. Calling /usr/bin/apache2 direct +ly 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 (availab +le # 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 amoun +t. # We recommend you leave this number high, for maximum performance. # MaxKeepAliveRequests 100 # # KeepAliveTimeout: Number of seconds to wait for the next request fro +m 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 peo +ple # had to knowingly turn this feature on, since enabling it means that # each client request will result in AT LEAST one lookup request to th +e # 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 module +s, 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 /v +ar/www. # The former is used by web applications packaged in Debian, # the latter may be used for local directories served by the web serve +r. 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> PerlModule ModPerl::Registry <location "/var/www/html"> sethandler perl-script perlhandler ModPerl::Registry options +ExecCGI </location> <Directory /var/www/html> Options Indexes FollowSymLinks ExecCGI AllowOverride All Require all granted allow from all </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 us +e %O # (the actual bytes sent including headers) instead of %b (the size of + the # requested file), because the latter makes it impossible to detect pa +rtial # requests. # # Note that the use of %{X-Forwarded-For}i instead of %h is not recomm +ended. # Use mod_remoteip instead. # LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Ag +ent}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

Replies are listed 'Best First'.
(Mostly OT) Re: perl and apache2 on ubuntu 17.04
by hippo (Archbishop) on Jul 15, 2017 at 21:38 UTC
    i am fairly certain i have perl installed (although i have no clue how to check).

    Run perl -v and you'll find out.

    oh yes - i wish to not have to "sudo" into the conf files all the time ...

    Run sudo -i. Don't forget to exit when you are done. This is not secure but it'll do what you ask. Better to amend sudoers to increase the timeout - but that's more advanced and for another day.

    i had little to no problem just uncommenting "LoadModule cgi_module modules/mod_cgi.so" in the httpd.conf file...but, none of these lines exist in the apache2.conf file

    Ubuntu has its own unique way of laying out apache. If you stick with that, then use a2enable to enable modules rather than editing the conf files. You will also need SetHandler in there somewhere, maybe ubuntu does that for you too, so grep the whole conf tree to find it.

    Most of this has very little to do with perl. You can just as easily write a demo CGI in bash (say) and you'll have the same problems. If you need ubuntu-specific help you will have better luck asking on an ubuntu forum such as askubuntu. Good luck.

Re: perl and apache2 on ubuntu 17.04
by huck (Prior) on Jul 15, 2017 at 22:04 UTC

    When i want to run perl files out of /cgi-bin i add these

    <Directory /var/www/html/cgi-bin/> Options Indexes FollowSymLinks AllowOverride None Order allow,deny Allow from all AllowOverride None Satisfy Any Options +ExecCGI AddHandler cgi-script .cgi .pl </Directory>
    This may give you a clue as to what to add

    Then from the command line i also run

    sudo a2enmod cgi sudo apache2ctl restart

Re: perl and apache2 on ubuntu 17.04
by shmem (Chancellor) on Jul 16, 2017 at 17:39 UTC

    What hippo and huck said. Some bits to add:

    I just dump all of my scripts into /var/www/html (and the modules i create are under a subfolder, ./Pm).

    Stuffing CGI files into cgi-bin is just a convention to keep executables and static content separate. You might as well tell apache to treat certain files in the DocumentRoot as executalble CGI files.

    # important config bits as from huck for DocumentRoot <Directory /var/www/html> ... Options +ExecCGI AddHandler cgi-script .cgi .pl ... </Directory>

    This marks as and makes into executables files ending with either .cgi or .pl

    just at the root of your http servers document tree, including subfolders.

    You might want to add directives to the subfolder Pm, so people don't get to see your afwul modules either :-P

    oh yes - i wish to not have to "sudo" into the conf files all the time - my password is not easy to type.

    huck told you to run sudo -i which creates a login shell. I'm always using sudo -s which just creates a new shell (without all the stuff a proper login does). Since I want use all my personal quirks as a root user also (i.e. just want to impersonate myself with super powers), I have this line in /etc/sudoers:

    Defaults !env_reset

    The blanks are a real tab, and you must edit this file (/etc/sudoers) with visudo. With that line, I preserve environment, shell and other settings (e.g. ~/.vimrc) as I'm used to and don't have to sync stuff between /root and my homedir. But one must keep in mind that some programs re-create their files which after the fact aren't accessible as a less priviledged user, e.g. ~/.lesshst used by less(1), so be careful. If something goes wrong after impersonating yourself, check the ownership and permissions of files in your home directory, specially files and directories that begin with a dot (".").

    so some jargon is okay, save for linux jargon, you might lose me...see?

    That's ok, just don't hesitate to ask, even (in my case, other monks might not want that) with a private message.

    perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
Re: perl and apache2 on ubuntu 17.04
by chacham (Prior) on Jul 17, 2017 at 11:18 UTC

    worstest (yes, it's not a word)

    worstest n. worstestshire sauce made outside the shire. The word seems fishy until you get into the hobbit of using it.

Re: perl and apache2 on ubuntu 17.04
by jamroll (Beadle) on Jul 18, 2017 at 20:33 UTC
    thank you so much for ALL of that input. it worked well, although it did take a while. managed to connect my www webaddress to my public IP and all is working as you might expect, mostly. at least, Apache is now returning SOMETHING...albeit very confusing.

    you see, an issue has cropped up since these changes. now none of my modules work. my main site code (for .pl scripts) is stored in the /var/www/html/ and my modules are stored in /var/www/html/Pm

    here's a simple module i have stored in /var/www/html/Pm/ - it's just my 'TEMPLATE.pm' so i don't mess up making new modules:
    package Pm::TEMPLATE; # change TEMPLATE to whatever you need it to be #/ # a template pm so i don't gotta type all this all the time #/ use strict; use warnings; use Exporter; use vars qw($VERSION @ISA @EXPORT_OK); use CGI; $VERSION = 1.00; @ISA = qw(Exporter); @EXPORT_OK = qw( an_exported_sub ); use lib "/var/www/html/Pm"; # in case other modules i make need to be +added into this module my $TABLE_BORDER = 0; my $DEBUG = 0; sub an_exported_sub($$) { #* # an exported sub description/information #* my ($param1, $param2) = @_; # param one && param 2 return 1; # a return value of 1 #usage: my $val = an_exported_sub($someval, $someotherval); } 1;
    now...the main code mytest.pl (stored in /var/www/html/):
    #!/usr/bin/perl # must have's! use strict; use warnings; use CGI::Carp qw(fatalsToBrowser); use DBI; use URI::Escape; use lib "/var/www/html/Pm"; use TEMPLATE qw(an_exported_sub); my $DEBUG = 0; my $output = "content-type: text/plain\n\n"; print $output . an_exported_sub(1, 2); exit 1;
    i use geany and i can press F8 on TEMPLATE.pm - compiles just fine. press F8 on mytest.pl and it compiles just fine, too. so i'm a bit lost as to why an_exported_sub(1, 2) isn't found...which is unbelievably mind-boggling!

    when i run this, i get the following error msg: Undefined subroutine &main::an_exported_sub called at /var/www/html/mytest.pl line 18.

      Under these conditions

      use lib "/var/www/html/Pm"; use TEMPLATE qw(an_exported_sub);
      shouldnt this
      package Pm::TEMPLATE;
      instead be this
      package TEMPLATE;

      added:Or instead do you want

      use lib "/var/www/html";

        omg! if that's the issue, wow...i've been struggling for hours. checking...

        yup. that worked (removing Pm:: from package statement)!! thank you so very much, huck! I will add those who have helped me in this to my "special thanks" section on my website

        that's awesome! I got a 1 lol. yay me, and yay huck! :D
      sub an_exported_sub($$) {

      Can you explain why you are using the prototype? If not, remove it and try again.

        when i remove ($$) from the subroutine's declaration, and modify 'mytest.pl' to reflect those changes, i still get the exact same error. i tried an_exported_sub() and &an_exported_sub() and &an_exported_sub, all gave back the same results...no such sub.
        there is giant reason i use prototypes. but, i would like to know WHY it's such a giant deal that i do. many ask why. i can't see it mattering in the grand-scheme. but, to answer, i have LOTS of subs in many different modules. I cannot possibly recall what EVERY single one needs for params. This prototyping, at least, let's me know if i put in too many params, or not enough. nice and convenient. does it affect the issue at hand to leave it in? if not, then why even ask???