• Skip to primary navigation
  • Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

apache

Ubuntu 20.04 LTS Lamp Server

by Ulysses · Nov 10, 2020

Here’s how to install a LAMP server on the latest Ubuntu 20.04 LTS.

Install Apache.

apt install apache2
systemctl status apache2
systemctl is-enabled apache2

apt install apache2 systemctl status apache2 systemctl is-enabled apache2

Install MariaDB.

apt install mariadb-server mariadb-client
systemctl status mariadb
systemctl is-enabled mariadb
mysql_secure_installation

apt install mariadb-server mariadb-client systemctl status mariadb systemctl is-enabled mariadb mysql_secure_installation

Install PHP.

apt install php libapache2-mod-php php-mysql
systemctl restart apache2

apt install php libapache2-mod-php php-mysql systemctl restart apache2

Enable ssl and mod_rewrite.

a2enmod ssl
a2enmod rewrite
systemctl restart apache2

a2enmod ssl a2enmod rewrite systemctl restart apache2

Filed Under: Linux Tagged With: apache, lamp, lts, mariadb, mod_rewrite, php, ssl, ubuntu 20.04

Clients Connected to Apache

by Ulysses · Jul 25, 2020

Here’s how to find if clients are connected to Apache or Nginx service.

netstat -tn src: 80
netstat -tn src: 443

netstat -tn src: 80 netstat -tn src: 443

Filed Under: Linux Tagged With: 443, 80, apache, clients, connection

Standard SSL Policy

by Ulysses · Feb 9, 2020

Here’s a standard template for SSL Apache found in /etc/apache2/sites-available/default-ssl.conf.

<IfModule mod_ssl.c>
<VirtualHost _default_:443>
   ServerAdmin your-email@your-domain.com
   ServerName www.yourdomain.com
   ServerName yourdomain.com
   DocumentRoot /var/www/your-domain.com
   ErrorLog /var/www/your-domain.com/log/error.log
   CustomLog /var/www/your-domain.com/log/access.log combined
   <Directory /var/www/your-domain.com>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride All
      Require all granted
   </Directory>
   SSLCertificateFile /etc/letsencrypt/live/your-domain.com/fullchain.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem
   Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>

<IfModule mod_ssl.c> <VirtualHost _default_:443> ServerAdmin your-email@your-domain.com ServerName www.yourdomain.com ServerName yourdomain.com DocumentRoot /var/www/your-domain.com ErrorLog /var/www/your-domain.com/log/error.log CustomLog /var/www/your-domain.com/log/access.log combined <Directory /var/www/your-domain.com> Options Indexes FollowSymLinks MultiViews AllowOverride All Require all granted </Directory> SSLCertificateFile /etc/letsencrypt/live/your-domain.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/your-domain.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>

Enable SSL.

# Enable SSL Module
a2enmod ssl
systemctl restart apache2.service
# Enable SSL Apache Config
a2ensite default-ssl
systemctl restart apache2.service
# Alternate way to restart.
service apache2 restart

# Enable SSL Module a2enmod ssl systemctl restart apache2.service # Enable SSL Apache Config a2ensite default-ssl systemctl restart apache2.service # Alternate way to restart. service apache2 restart

Filed Under: Linux Tagged With: 443, apache, config, ssl

WordPress Permalinks Not Working

by Ulysses · Jan 28, 2020

Here’s a couple of things you can do to check if WordPress permalinks is not working.

  1. Make sure .htaccess has the right permissions.
  2. Make sure a2enmod Apache module is enabled.
  3. Restart the Apache server.
chmod 664 /var/www/domain.com/.htaccess
a2enmod rewrite
systemctl restart apache2

chmod 664 /var/www/domain.com/.htaccess a2enmod rewrite systemctl restart apache2

Filed Under: Linux Tagged With: .htaccess, a2enmod, apache, restart, rewrite, wordpress

GCP Web Server

by Ulysses · Jan 8, 2020

Here’s a quick script to stand up a web server based on Centos image.

gcloud compute instances create [VM-NAME] \
    --zone=[ZONE] \
    --image-family=debian-9 \
    --image-project=debian-cloud \
    --tags=allow-ssh,allow-health-check \
    --subnet=lb-subnet \
    --metadata=startup-script='#! /bin/bash
apt-get update
apt-get install apache2 -y
a2ensite default-ssl
a2enmod ssl
vm_hostname="$(curl -H "Metadata-Flavor:Google" \
http://169.254.169.254/computeMetadata/v1/instance/name)"
echo "Page served from: $vm_hostname" | \
tee /var/www/html/index.html
systemctl restart apache2'

gcloud compute instances create [VM-NAME] \ --zone=[ZONE] \ --image-family=debian-9 \ --image-project=debian-cloud \ --tags=allow-ssh,allow-health-check \ --subnet=lb-subnet \ --metadata=startup-script='#! /bin/bash apt-get update apt-get install apache2 -y a2ensite default-ssl a2enmod ssl vm_hostname="$(curl -H "Metadata-Flavor:Google" \ http://169.254.169.254/computeMetadata/v1/instance/name)" echo "Page served from: $vm_hostname" | \ tee /var/www/html/index.html systemctl restart apache2'

Filed Under: Cloud Tagged With: apache, debian, gcp, metadata, server, vm, web

Apache Dockerfile

by Ulysses · Dec 25, 2019

This Docker image contains Apache (httpd), a web server.

Here’s the Dockerfile.

FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs/

FROM httpd:2.4 COPY ./public-html/ /usr/local/apache2/htdocs/

Build and run your Docker image.

docker build -t my-app .
docker run -dit --name my-running-app -p 8080:80 my-app

docker build -t my-app . docker run -dit --name my-running-app -p 8080:80 my-app

Visit http://localhost:8080 to view your app.

Filed Under: Cloud, Linux Tagged With: apache, build, docker, dockerfile, run

HTTPS in CodeIgniter

by Ulysses · Jul 17, 2019

If you switched to HTTPS in Apache, make sure to update CodeIgniter’s config file.

vim /var/www/applications/config/config.php

vim /var/www/applications/config/config.php

Change the base URL to https.

$config['base_url']	= 'https://yourdomain.com/ci/';

$config['base_url'] = 'https://yourdomain.com/ci/';

Filed Under: PHP Tagged With: apache, base url, codeigniter, config, https, php

Apache & Webroot

by Ulysses · Jul 5, 2019

Where’s Apache and webroot for the different distros?

Webroot:

# Redhat, Fedora, Centos, Amazon Linux
/var/www/html
# Debian, Ubuntu, Mint
/var/www/html

# Redhat, Fedora, Centos, Amazon Linux /var/www/html # Debian, Ubuntu, Mint /var/www/html

Apache Configuration:

# Redhat, Fedora, Centos, Amazon Linux
/etc/httpd/conf/httpd.conf
# Debian, Ubuntu, Mint
/etc/apache2/sites-available/default

# Redhat, Fedora, Centos, Amazon Linux /etc/httpd/conf/httpd.conf # Debian, Ubuntu, Mint /etc/apache2/sites-available/default

Filed Under: Linux Tagged With: apache, centos, debian, fedora, mint, redhat, ubuntu, webroot

How to Rotate Apache Logs

by Ulysses · Feb 15, 2017

Apache comes with a logrotate utility. You can customize the way logrotate behaves by editing the /etc/logrotate.d/apache file. The logrotate utility has many options. In this example, we are rotating the log files that are located at the /var/www/domain.com/log/ directory. We are instructing the log files to rotate monthly for a total of 24 times. We are compressing the files by zipping them. We are using the date extension as part of the filename. We are also delaying the compression until the log has been rotated at least twice. Finally, Apache is restarted.

$ sudo nano /etc/logrotate.d/apache
/var/www/domain.com/*.log {
  monthly
  missingok
  rotate 24
  dateext
  compress
  delaycompress
  notifempty
  create 640 root adm
  sharedscripts
  postrotate
    if /etc/init.d/apache2 status > /dev/null ; then \
      /etc/init.d/apache2 reload > /dev/null; \
    fi;
  endscript
  prerotate
    if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
      run-parts /etc/logrotate.d/httpd-prerotate; \
    fi; \
  endscript
}

$ sudo nano /etc/logrotate.d/apache /var/www/domain.com/*.log { monthly missingok rotate 24 dateext compress delaycompress notifempty create 640 root adm sharedscripts postrotate if /etc/init.d/apache2 status > /dev/null ; then \ /etc/init.d/apache2 reload > /dev/null; \ fi; endscript prerotate if [ -d /etc/logrotate.d/httpd-prerotate ]; then \ run-parts /etc/logrotate.d/httpd-prerotate; \ fi; \ endscript }

To learn more about the logrotate utility, please visit the documentation.

Filed Under: Linux Tagged With: apache, logs, rotate

Get Apache Version

by Ulysses · Dec 3, 2014

To find out what version of Apache running on your server, type the following.

Ubuntu-based distros

apache2 -V

apache2 -V

Debian-based distros

apachectl -V

apachectl -V

Redhat-based distros

httpd -V

httpd -V

Filed Under: Linux Tagged With: apache, version

  • Go to page 1
  • Go to page 2
  • Go to Next Page »

Copyright © 2012–2021