curl -sL https://gist.githubusercontent.com/e-cloud/05da090856839442c5330852f73e7989/raw/webpagetest-install.sh | sudo bash -
After Installation, access http://localhost in browser.
| #! /bin/bash | |
| # see https://github.com/WPO-Foundation/webpagetest-docs/blob/master/user/Private%20Instances/README.md | |
| function download_package_if_not_exists(){ | |
| local pkg_name=$1 | |
| local pkg_addr=$2 | |
| local explicit_file=$3 | |
| if [ ! -f ~/Downloads/$pkg_name ]; then | |
| if [ explicit_file ]; then | |
| wget $pkg_addr -O ~/Downloads/$pkg_name | |
| else | |
| wget $pkg_addr -P ~/Downloads/ | |
| fi | |
| fi | |
| } | |
| download_package_if_not_exists webpagetest_17.12.zip https://github.com/WPO-Foundation/webpagetest/releases/download/WebPageTest-17.12/webpagetest_17.12.zip | |
| sudo mkdir -p /var/www/webpagetest | |
| sudo unzip -qo ~/Downloads/webpagetest_17.12.zip -d /var/www/webpagetest | |
| # grant permissions to www-data group | |
| sudo mkdir -p /var/www/webpagetest/www/{tmp,dat,results,work/jobs,work/video,logs} | |
| sudo chown -R "$USER":www-data /var/www/webpagetest | |
| sudo chmod -R 0775 /var/www/webpagetest/www/{tmp,dat,results,work/jobs,work/video,logs} | |
| # apply the default settings of webpage-test | |
| cd /var/www/webpagetest/www/settings | |
| for foo in *.sample; do | |
| cp $foo `basename $foo .sample`; | |
| done | |
| sudo sed -i 's/^-//' /var/www/webpagetest/www/settings/locations.ini | |
| cd - | |
| sudo apt-get update && \ | |
| sudo apt-get -y dist-upgrade && \ | |
| sudo apt-get remove python-pip -y && \ | |
| sudo apt-get -y install zip net-tools bind9 nginx php-fpm php-cli php-xml \ | |
| php-apcu php-gd php-zip php-mbstring php-curl php-sqlite3 beanstalkd \ | |
| imagemagick ffmpeg libjpeg-turbo-progs libimage-exiftool-perl python-setuptools \ | |
| build-essential python python-dev python-pip python-numpy python-scipy && \ | |
| sudo pip install monotonic ujson pillow pyssim | |
| # apply nginx conf for webpage-test | |
| sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/default.bk | |
| phpVer=`php -v | grep -oP "(?<=PHP )\d+.\d+"` | |
| sudo tee /etc/nginx/sites-available/default <<- EOF | |
| server { | |
| listen 80 default; | |
| server_name _; | |
| root /var/www/webpagetest/www; | |
| # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 | |
| # | |
| location ~ \.php$ { | |
| limit_except GET POST HEAD { | |
| deny all; | |
| } | |
| #fastcgi_pass 127.0.0.1:9000; | |
| fastcgi_pass unix:/run/php/php$phpVer-fpm.sock; | |
| #fastcgi_index index.php; | |
| fastcgi_param SCRIPT_FILENAME /var/www/webpagetest/www\$fastcgi_script_name; | |
| fastcgi_param HTTP_MOD_REWRITE On; | |
| include fastcgi.conf; | |
| } | |
| include /var/www/webpagetest/www/nginx.conf; | |
| } | |
| EOF | |
| sudo nginx -s reload | |
| # linux tunning | |
| if ! grep -q "soft nofile 250000" /etc/security/limits.conf; then | |
| sudo tee -a /etc/security/limits.conf <<- END | |
| * soft nofile 250000 | |
| * hard nofile 300000 | |
| END | |
| fi | |
| if ! grep -q "Increase system IP port limits to allow for more connections" /etc/sysctl.conf; then | |
| sudo tee -a /etc/sysctl.conf <<- END | |
| # Increase system IP port limits to allow for more connections | |
| net.ipv4.ip_local_port_range = 2000 65000 | |
| net.ipv4.tcp_window_scaling = 1 | |
| # number of packets to keep in backlog before the kernel starts dropping them | |
| net.ipv4.tcp_max_syn_backlog = 3240000 | |
| # increase socket listen backlog | |
| net.core.somaxconn = 65535 | |
| net.ipv4.tcp_max_tw_buckets = 1440000 | |
| # Increase TCP buffer sizes | |
| net.core.rmem_default = 8388608 | |
| net.core.rmem_max = 16777216 | |
| net.core.wmem_max = 16777216 | |
| net.ipv4.tcp_rmem = 4096 87380 16777216 | |
| net.ipv4.tcp_wmem = 4096 65536 16777216 | |
| net.netfilter.nf_conntrack_max = 1048576 | |
| net.netfilter.nf_conntrack_generic_timeout = 300 | |
| net.netfilter.nf_conntrack_tcp_timeout_syn_sent = 60 | |
| net.netfilter.nf_conntrack_tcp_timeout_syn_recv = 60 | |
| net.netfilter.nf_conntrack_tcp_timeout_established = 600 | |
| net.netfilter.nf_conntrack_tcp_timeout_fin_wait = 5 | |
| net.netfilter.nf_conntrack_tcp_timeout_close_wait = 5 | |
| net.netfilter.nf_conntrack_tcp_timeout_last_ack = 30 | |
| net.netfilter.nf_conntrack_tcp_timeout_time_wait = 5 | |
| net.netfilter.nf_conntrack_tcp_timeout_close = 5 | |
| net.netfilter.nf_conntrack_tcp_timeout_max_retrans = 60 | |
| net.netfilter.nf_conntrack_tcp_timeout_unacknowledged = 60 | |
| net.netfilter.nf_conntrack_udp_timeout = 300 | |
| net.netfilter.nf_conntrack_udp_timeout_stream = 300 | |
| net.netfilter.nf_conntrack_icmp_timeout = 30 | |
| net.netfilter.nf_conntrack_events_retry_timeout = 15 | |
| # Disable IPv6 | |
| net.ipv6.conf.all.disable_ipv6 = 1 | |
| net.ipv6.conf.default.disable_ipv6 = 1 | |
| net.ipv6.conf.lo.disable_ipv6 = 1 | |
| net.ipv4.neigh.default.gc_thresh1 = 512 | |
| net.ipv4.neigh.default.gc_thresh2 = 1024 | |
| net.ipv4.neigh.default.gc_thresh3 = 2048 | |
| END | |
| fi | |
| cd /var/www/webpagetest/wptagent | |
| sudo sed -i.bak ' | |
| s/setup_7/setup_10/ | |
| /npm update/d | |
| /google\.com/d | |
| s/python-software-properties// | |
| s/-yq/-y/ | |
| s/sudo sysctl -p$/sudo sysctl -p || true/ | |
| ' ./ubuntu_install.sh | |
| sudo bash ./ubuntu_install.sh | |
| echo 'wptagent installation finished' | |
| cd - | |
| # see https://github.com/WPO-Foundation/wptagent/blob/master/docs/install.md | |
| currentUser=$USER | |
| sudo touch /etc/systemd/system/wptagent.service | |
| sudo tee /etc/systemd/system/wptagent.service <<- EOF | |
| [Unit] | |
| Description=wptagent | |
| After=nginx.service | |
| [Service] | |
| ExecStart=/usr/bin/python /var/www/webpagetest/wptagent/wptagent.py --server http://localhost/work/ --location Test | |
| Restart=always | |
| # here we use the current user for the service, because we install the pip packages for current user | |
| User=$currentUser | |
| TimeoutStopSec=300 | |
| [Install] | |
| WantedBy=default.target | |
| EOF | |
| echo 'starting wptagent service' | |
| sudo systemctl enable wptagent | |
| sudo systemctl start wptagent |