Category

Apache

Debugging Issues with Apache2

By | Apache

Knowing the exact issue is important.


1
2
3
4
5
apachectl configtest
journalctl -xe
systemctl status apache2.service
sudo nano /var/log/apache2/error.log
netstat -ltp | grep :80 # To know if a program is occupying port 80

FYI: Apache modules reside in following. Sometimes we have mismatch of module especially after switching php version. If the loaded version is different and available version is different, that causes error too.


1
/usr/lib/apache2/modules

Installing LAMP

By | Apache, Ubuntu

Turn on PHP Short tags
Uncomment pdo_mysql, curl and other modules that are required.

1
 
1
<code lang="bash">

sudo a2enmod rewrite

1
<code lang="bash">

# For laravel 4 projects
sudo apt-get install php5.6-mcrypt;

1
<code lang="bash">

sudo apt-get install php5.6-gd;
sudo apt-get install php7.0-gd;
sudo apt-get install php7.1-gd;
sudo apt-get install php7.2-gd;

1
<code lang="bash">

sudo apt-get install php7.2-curl;

1
<code lang="bash">

sudo apt-get install php7.2-mbstring;

# For fpm

sudo apt-get install php-mbstring

1
<code lang="bash">

sudo apt-get install php7.2-xml;

1
<code lang="bash">

sudo apt-get install php5.6-mysql

1
<code lang="bash">

# For dbeaver
sudo apt-get install mysql-client

1
 
1
 

Reinstalling apache2

By | Apache

Apache breaks for me quite a few times. I wanted to make a log of commands that I run in order to reinstall apache2. Following are the commands that helped me reinstall apache2.

1
2
3
4
5
6
7
8
9
10
11
12
sudo apt-get --purge remove apache2

sudo apt-get autoremove

sudo apt-get install apache2

sudo apt-get install curl

sudo apt-get libapache2-mod-php


sudo nano /etc/apache2/httpd.conf

Inside

Directory /var/www block

1
AllowOverride All

Back to terminal.

1
2
3
4
5
6
7
8
9
10
11
sudo a2enmod rewrite

sudo a2dismod mpm_event

sudo a2enmod mpm_prefork

systemctl restart apache2

sudo a2enmod php5.6

systemctl restart apache2

How to setup a letsencrypt certificate for non www as well as www domain on Apache2?

By | Apache, letsencrypt

Let’s say you have a domain: https://www.yoursite.com. Though this is a www site you would expect it to work for non-www as well. Meaning https://yoursite.com should still take you to https://www.yoursite.com.

For your default installation perhaps you had only one certificate for the non www version and you don’t have an SSL certificate for www version. Browser is going to throw an SSL certificate error for that.

To overcome this you could run following command which covers www and non-www version.

1
sudo certbot --apache -d example.com -d www.example.com

This covers both the www and non www domains and everything should run just fine.

Next, you may want to set some htaccess rules. This article talks about  enforcing www.