0

I'm working on Debian Testing. I see local http sites at localhost/~myhome/... To this end I made the classic change to /etc/apache2/mods-available/php8.2.conf

To re-enable php in user directories comment the following lines
...

However I have an https site in which .htaccess I added

RewriteEngine on
RewriteCond %{HTTP_HOST} ^sito.net$ [OR]
RewriteCond %{HTTP_HOST} ^sito.it$ [OR]
RewriteCond %{HTTP_HOST} ^www.sito.it$
RewriteRule ^/?$ "http\:\/\/www\.site\.net" [R=301,L]`

and still from local I cannot see it, receiving:

Internal Server Error
The server encountered an internal error or misconfiguration
and was unable to complete your request.`
Please contact the server administrator at webmaster@localhost
to inform them of the time this error occurred, and the actions
you performed just before this error.
More information about this error may be available
in the server error log.
Apache/2.4.58 (Debian) Server at localhost Port 80`

I followed some (old) instructions found in this thread: How do I allow HTTPS for Apache on localhost?

I did the following steps:

# openssl req -x509 -newkey rsa:2048 -keyout mykey.key -out mycert.pem -days 365 -nodes
#cp mycert.pem mykey.key /etc/ssl/private/
#a2enmod ssl
#a2ensite default-ssl.conf
#systemctl restart apache2

but receiving:

root@debian:~# systemctl restart apache2
Job for apache2.service failed because the control process exited with error code.
See "systemctl status apache2.service" and "journalctl -xeu      apache2.service" for details.

And after:

root@debian:~# systemctl status apache2.service
× apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; preset: enabled)
Active: failed (Result: exit-code) since Mon 2023-12-04 21:35:15 CET; 8s ago
Docs: https://httpd.apache.org/docs/2.4/
Process: 4216 ExecStart=/usr/sbin/apachectl start (code=exited, status=1/FAILURE)
    CPU: 93ms

dic 04 21:35:15 debian systemd[1]: Starting apache2.service - The Apache HTTP Server...
dic 04 21:35:15 debian apachectl[4218]: AH00526: Syntax error on line 227 of /etc/apache2/apache2.conf:
dic 04 21:35:15 debian apachectl[4218]: Cannot define multiple Listeners on the same IP:port
dic 04 21:35:15 debian systemd[1]: apache2.service: Control process exited, code=exited, status=1/FAILURE
dic 04 21:35:15 debian systemd[1]: apache2.service: Failed with result 'exit-code'.
dic 04 21:35:15 debian systemd[1]: Failed to start apache2.service - The Apache HTTP Server.

The line referring to that error:

# Include the virtual host configurations:
IncludeOptional sites-enabled/*.conf
Listen 80
NameVirtualHost *:80
<VirtualHost *:443>
DocumentRoot "/home/samiel/public_html"  #your wamp www root dir
ServerName debian
SSLEngine on
SSLCertificateFile "/etc/ssl/certs/mycert.pem"
SSLCertificateKeyFile "/etc/ssl/certs/mykey.key"

I am unable to make any further attempts...

New contributor
user41063 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
1
  • I would first "dump" your whole running config with apachectl -S
    – Turdie
    2 days ago

1 Answer 1

1

First install apt install libapache2-mod-php8.2

Dump your whole running config with apachectl -S

And when you want to make an application available to be served by apache, it's best practice to create a virtual host in /etc/apache2/sites-available

An example of a virtual host looks like this

    <VirtualHost *:80>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

    DocumentRoot /var/www/html

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

    RewriteEngine on
    RewriteCond %{SERVER_NAME} =yourdomain.com [OR]
    RewriteCond %{SERVER_NAME} =www.yourdomain.com
    RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

<VirtualHost *:443>
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

    DocumentRoot /var/www/html

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

    SSLEngine on
    SSLCertificateFile /etc/ssl/certs/yourdomain.crt
    SSLCertificateKeyFile /etc/ssl/private/yourdomain.key
    SSLCertificateChainFile /etc/ssl/certs/yourdomain.ca-bundle

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

    <FilesMatch \.php$>
        SetHandler "proxy:unix:/var/run/php/php8.2-fpm.sock|fcgi://localhost/"
    </FilesMatch>
</VirtualHost>

Then save it in /etc/apache2/sites-available/ as yoursite.conf

  • Then enable the vhost sudo a2ensite yourdomain.conf
  • Test your configuration sudo apachectl configtest
  • If everything is ok restart apache sudo systemctl restart apache2
2
  • Thank you for your detailed answer. I created a .crt and a .key certificate by command: openssl req -x509 -newkey rsa:2048 -keyout mykey.key -out mycert.pem -days 365 -nodes. How can I create a .ca-bundle too?
    – user41063
    yesterday
  • For example openssl req -x509 \ -sha256 -days 356 \ -nodes \ -newkey rsa:2048 \ -subj "/CN=demo.mlopshub.com/C=US/L=San Fransisco" \ -keyout rootCA.key -out rootCA.crt but you need create new self signed certs, because they need to be signed with the ca certificate devopscube.com/create-self-signed-certificates-openssl
    – Turdie
    yesterday

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .