Is it possible to use AWS Beanstalk's .ebextensions config to install mod_pagespeed Apache module? - apache

I'm using AWS Beanstalk for my Django/Python application, and I would like to use Google's mod_pagespeed module. Is it possible to install and run mod_pagespeed using the .ebextensions/.config file?

Download the package
Add the rpm into your ebextensions directory
create a .config file in the .ebextensions directory
add commands to the config file like this:
container_commands:
01-command:
command: rm -rf /pagespeed/ebextensions
02-command:
command: mkdir -p /pagespeed/ebextensions
03-command:
command: cp -R .ebextensions/* /pagespeed/ebextensions/
04-command:
command: rpm -U /pagespeed/ebextensions/mod-pagespeed.rpm
Ensure the commands are indented as shown, with no tabs, otherwise it wont work.
swap "mod-pagespeed.rpm" for whatever the actual rpm file name is.

Ok so I want to add Charlie Smith's answer. I would suggest you make sure you have the following things turned on.
mod_deflate - You probably want to Gzip your html, css, xml, and javascript.
Enable the rewrite domains filter in your Apache.conf if you use CDN (ex. AWS CloudFront)
Set a short cache-control for images and css so pagespeed will be able to extend the cache when you turn on the extend_cache filter.
I also like the rewrite_javascript, dns_prefetch, collapse_whitespace, and combine_javascript filters.
Here are the GitHub Gists that show you how its done.
The apache conf file
The Beanstalk container_commands (they are mostly the same as Charlie's)

Thanks guys! I got it working great following your answer #man2xxl.
You don't have to mess with the /pagespeed/extensions directory though, the beanstalk .ebextensions config can simply be:
packages:
yum:
at: []
10_setup_apache_for_mod_pagespeed:
command: "cp enable_mod_pagespeed.conf /etc/httpd/conf.d"
20_install_mod_pagespeed:
command: rpm -U -iv --replacepkgs mod-pagespeed-*.rpm
30_clear_mod_pagespeed_cache:
command: touch /var/cache/mod_pagespeed/cache.flush

You can install packages by URL. So you don't have to download and distribute the RPM. Something like this works:
packages:
rpm:
pagespeed: https://dl-ssl.google.com/dl/linux/direct/mod-pagespeed-stable_current_x86_64.rpm
files:
"/etc/httpd/conf.d/zzzz-pagespeed-options.conf":
mode: "00644"
owner: root
group: root
encoding: plain
content: |
# put your pagespeed configuration here
Note that I titled the file zzzz-pagespeed-options.conf so that the httpd server will load it last.
Another advantage of this is you really don't need include any commands whatsoever or worry about copying files over
and maintaining the files in your .ebextensions folder. You just update the files entry in the .config file.

Related

How to install Apache on OmniOS

I am attempting to install Apache on OmniOS. I followed the instructions here: option 2 https://wiki.openindiana.org/oi/3.+Installing+software+and+package+management
Ran the command:
echo $PATH results in /opt/local/sbin:/opt/local/bin:/usr/gnu/bin:/usr/sbin:/sbin
curl https://pkgsrc.joyent.com/packages/SmartOS/bootstrap/bootstrap-2016Q4-x86_64.tar.gz | gtar -zxpf - -C /
pkgin -y update
pkgin -y install apache-2.4.6 resulted in the messages Calculating dependencies...done and then nothing to do
I can not find the apache service or configuration directory as they are described here: https://docs.joyent.com/public-cloud/instances/infrastructure/images/smartos/apache
/opt/local/etc/httpd The configuration directory for Apache
svcs pkgsrc/apache Checking service for Apache
Server Info:
uname -v results in omnios-r151026-d9b45886bd
Running x86
Also running SunONE webserver
Though incomplete, my commands did make a change. My Perl scripts can no longer find DBI.
Why does the Apache install say there is nothing to do? What am I missing?
UPDATE
Ran which apache2 resulted in no apache2
Ran pkgin list to list all installed packages. Only apache
reference is apache-maven-3.5.4
Ran find . -name '*apache*' in the following directories:
\etc nothing
\opt found:
vim, el, and elc files in SUNWspro
org-apache-tools-ant-module files and folder in netbeans/3.5V11/modules/patches
apache folder in SUNWwbsvr/plugins/java/samples/webapps/jstl/src/org which contains java files
vim, tag, el and elc files in sfw --- also an apache folder in sfw which contains readme/bash type files for apache/php and one so file
apache-maven-3.5.4 files/folders in local
org-apache-xml-resolver* files in sunstudio12.1
'\usr' found:
2 vims in share/vim/vim80/syntax
apache-fcgi.conf in lib/python2.7/vendor-packages/cherrypy/scaffold
'\var' nothing
As far as I can tell, the binaries have not been installed
I tried running pkgin -y install apache-2 and it worked. It installed apache-2.4.3. Perhaps apache-2.4.6 does not exist in the repository.
This mean apache is already installed on the Linux system. To run below command which will tell the location of the system binary.
which apache2
for the configuration folder look for below directory:
/etc/apache2

How to delete all files with lftp except for cgi-bin and .ftpquota

I'm setting up a new ci/cd pipeline on gitlab. For the deployment I have to run npm run build and then copy the dist/ folder to the webserver via ftp (with lftp). To ensure a clean deployment the script should remove all files except the folder cgi-bin and the file .ftpquota on the webserver first and then copy the files.
I've researched through the web and haven't found a suitable solution. With the flag --delete, lftp deletes all files.
Thats my script so far:
- lftp -c "set ftp:ssl-allow no; open -u $USERNAME,$PASSWORD $HOST; mirror -Rnev dist/ ./ --ignore-time --delete --parallel=10 --exclude-glob .git* --exclude .git/"
My current script removes all files, but I want it to remove everything except the cgi-bin folder and the .ftpquota file.
As seen in unix.stackexchange.com you should add the -x option:
Please check it

AWS Elastic Beanstalk: Reload configs files without redeploying the whole app?

Is there a way to load what is in .ebextention without redeploying the whole application with eb deploy? It seems restarting Apache is not enough.
exemple of config file:
container_commands:
01_remove_old_cron_jobs:
command: "crontab -r || exit 0"
02_cronjobs:
command: "cat .ebextensions/cron_jobs.txt > /etc/cron.d/cron_job && chmod 644 /etc/cron.d/cron_job"
leader_only: true
03_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
The plain answer is no. The config files are only executed upon deployment as part of the EB scripting pipeline. If it's only a one time operation you'd like to perform, simply eb ssh the instance and perform these manually. Upon next deploy they'll be done automatically via your config files.
You could add another container_commands e.g.:
04_reload_files:
command: "sudo service httpd reload"
Note this will work with Amazon Linux but not Amazon Linux 2 where you would need to do:
04_reload_files:
command: "sudo systemctl reload httpd.service"
AWS have a new preferred way of interacting with webserver config during deployment using the following structure (for apache) rather than .ebextensions:
~/workspace/my-app/
|-- .ebextensions
| -- httpd-proxy.config
|-- .platform
| -- httpd
| -- conf.d
| -- port5000.conf
| -- ssl.conf
-- index.jsp
Some more info available here: https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/platforms-linux-extend.html

How to install PHP extensions on Cloudbees?

I need to install mbstring (and a few other extensions) for PHP on Cloudbees. Is this possible?
Note that I'm using an updated PHP version as described here:
https://developer.cloudbees.com/bin/view/DEV/PHP+Builds
I don't think scripts have sudo access, so I can't simply use the package manager. I don't think these extensions exist as PEAR packages either. So I'm stumped.
Here is the response from Cloudbees support. Seems to work fine, just make sure you don't have any spaces in your Jenkins build path!
Our provided PHP versions don't have mbstring module activated. You will need to build your own PHP version to get it. To be sure your custom PHP build works on Cloudbees slave, you can build it with a Jenkins job on your instance (with various --with-XXX or --without-XXX options).
We are ourselves doing something like this with a script like
# Download
regex='.*(RC|alpha|beta).*'
if [[ $version =~ $regex ]]; then
wget http://downloads.php.net/dsp/php-${version}.tar.bz2
else
wget http://us3.php.net/distributions/php-${version}.tar.bz2
fi
# Unpack
tar xjf php-${version}.tar.bz2
# Build
cd php-${version}
./configure --prefix=/home/jenkins/tools/php/${php_name} \
--with-curl --with-openssl
make && make install
As a side node, you should also take care of specifying a good installation prefix with --prefix. I would choose something like /home/jenkins/tools/php/5.4/.
To store compiled php engine you could generate a tar.gz//bz2 file of target installation directory. Then, store it in your WebDAV directory, which is accessible in /private/{account}/ during a build when "Mount CloudBees DEV#cloud Private WebDav Repository" is checked.
You should add a first step to jobs requiring PHP to extract this archive. As Jenkins workspace is usually cached on DEV#Cloud, you can extract the archive only if it's not already there. That will speed up your build.

Autoconf macros for Apache and conf.d install process?

I have a package that is using the autotools to build and install.
Part of the package is a website that can be run on the local machine.
So in the package there is a .conf file that is meant to be either
copied or linked to the /etc/apache2/conf.d directory. What's the
standard way that packages would do this? If possible, I'd like for
the user not to have an extra step to make the website work. I'd like
to have them install the package and then be able to browse to
http://localhost/newpackage to get up and running.
Also, is there a way that autoconf knows about the apache install or a
standard way through then environment some how? If someone could
point me in the right direction that would be great.
Steve
The first thing you should do is to locate the apache extension tool apxs or apxs2 (depends on apache version and/or platform you are building for). After you know where your tool is located you can run queries to get certain apache config params. For example to get system config dir you can run:
apxs2 -q SYSCONFDIR
Here is a snippet of how you can locate apache extension tool: (be careful it may contain syntax errors)
dnl Note: AC_DEFUN goes here plus other stuff
AC_MSG_CHECKING(for apache APXS)
AC_ARG_WITH(apxs,
[AS_HELP_STRING([[--with-apxs[=FILE]]],
[path to the apxs, defaults to "apxs".])],
[
if test "$withval" = "yes"; then
APXS=apxs
else
APXS="$withval"
fi
])
if test -z "$APXS"; then
for i in /usr/sbin /usr/local/apache/bin /usr/bin ; do
if test -f "$i/apxs2"; then
APXS="$i/apxs2"
break
fi
if test -f "$i/apxs"; then
APXS="$i/apxs"
break
fi
done
fi
AC_SUBST(APXS)
The way to use APXS in your automake Makefile.am would look something like this:
## Find apache sys config dir
APACHE2_SYSCONFDIR = `#APXS# -q SYSCONFDIR`
## Misc automake stuff goes here
install: install-am
cp my.conf $(DESTDIR)${APACHE2_SYSCONFDIR}/conf.d/my.conf
I assume you are familiar with automake and autoconf tools.