Project httpsrv 2.0 – Script to compile, install and manage on DEB/RPM based Linux


Httpsrv 2.0 is my attempt to make it easier to compile your own LAMP STACK on Linux
The tutorial expects your selinux to be runing in permissive-mode and firewalls are turned off
This tutorial is writen for CentOS6/7 and Ubuntu Linux. It will probably work on RedHat, fedora
Security holes, vulnerabilities and bugs in the software shall be reported to each individual project
This Script is only tested with sourcearchives and softwareversions found in httpsrv.sh
I take no responsibility for this script, use at your own risk

Video: Click here to watch on YouTube

1 Install dependencies and other software

Ubuntu
Copy and paste one line at a time

apt-get install libpcre3-dev libbz2-dev libfreetype6-dev libicu-dev g++ libxslt-dev -y
apt-get install gcc make nano libjpeg-dev libpng-dev libxml2-dev libcurl4-openssl-dev -y
apt-get install libssl-dev libmcrypt-dev libreadline-dev pkg-config unzip wget -y

CentOS
Copy and paste one line at a time

yum install gcc make openssl-devel nano epel-release libjpeg-devel libpng-devel lynx -y
yum install libxml2-devel libcurl-devel libmcrypt-devel readline-devel freetype-devel -y
yum install bzip2-devel libicu-devel pcre-devel gcc-c++ libxslt-devel unzip wget -y

2 Download and install MySQL

Ubuntu
Copy and paste one line at a time

cd /tmp && wget -O mysql-apt.deb https://repo.mysql.com/mysql-apt-config_0.8.6-1_all.deb && dpkg -i mysql-apt.deb
apt-get update && apt-get install mysql-client mysql-server -y

CentOS6
Copy and paste one line at a time

cd /tmp && wget -O mysql-el6.rpm https://repo.mysql.com/mysql57-community-release-el6-10.noarch.rpm && rpm -Uvh mysql-el6.rpm
yum install mysql-community-server -y && service mysqld start && cat /var/log/mysqld.log | grep "temporary password"
mysql_secure_installation

CentOS7
Copy and paste one line at a time

cd /tmp && wget -O mysql-el7.rpm https://repo.mysql.com/mysql57-community-release-el7-10.noarch.rpm && rpm -Uvh mysql-el7.rpm
yum install mysql-community-server -y && service mysqld start && cat /var/log/mysqld.log | grep "temporary password"
mysql_secure_installation

Only for CentOS and other yum installs

You can configure the Password Validation Plugin in MySQL
Se Options and Variables and add them to /etc/my.cnf
validate_password_special_char_count=0
validate_password_mixed_case_count=0
validate_password_check_user_name=0
validate_password_number_count=0
validate_password_policy=LOW
validate_password_length=4
validate-password=ON
Don´t forget to restart the service after editing /etc/my.cnf
systemctl restart mysqld.service or service mysqld restart
Link: mysql.com/validate-password-options-variables.html

MySQL Yum Repository RPM for Fedora Linux:
https://dev.mysql.com/downloads/repo/yum
MySQL Zypper Repository RPM for SUSE Linux:
https://dev.mysql.com/downloads/repo/suse

3 Download httpsrv using wget
Copy and paste one line at a time

cd /tmp && wget http://leemann.se/fredrik/file_downloads/httpsrv_linux-server_2.0.zip
cd /tmp && unzip httpsrv_linux-server_2.0.zip -d /srv

4 Edit and configure variables in /srv/httpsrv/tmp/httpsrv.sh
Uncomment the ‘sock_file’-variable depending on system in use…
Ubuntu: #sock_file=/run/mysqld/mysqld.sock => sock_file=/run/mysqld/mysqld.sock
CentOS: #sock_file=/var/lib/mysql/mysql.sock => sock_file=/var/lib/mysql/mysql.sock

Commands:

cd /srv && chmod -R 777 /srv/httpsrv
nano /srv/httpsrv/tmp/httpsrv.sh

5 Configure and build httpsrv, httpd (Apache) + PHP and phpMyAdmin
Copy and paste one line at a time

/srv/httpsrv/tmp/httpsrv.sh web_conf
/srv/httpsrv/tmp/httpsrv.sh web_make
/srv/httpsrv/tmp/httpsrv.sh php_conf
/srv/httpsrv/tmp/httpsrv.sh php_make
/srv/httpsrv/tmp/httpsrv.sh finalize
mysql -u root -p < /srv/httpsrv/phpmyadmin/sql/create_tables.sql

6 Edit: /srv/httpsrv/conf/httpd.conf
Ex: nano /srv/httpsrv/conf/httpd.conf
Define a new variable called ‘root_path’ on the row below the ”ServerRoot” directive:

Define root_path /srv/httpsrv

7 Edit, add and change below in httpd.conf
Ex: nano /srv/httpsrv/conf/httpd.conf

LoadModule rewrite_module modules/mod_rewrite.so
User httpsrv
Group httpsrv
ServerName httpsrv:80
# AllowOverride controls what directives may be placed in .htaccess files.
# This directive is for the directory: /srv/httpsrv/htdocs
AllowOverride All
DirectoryIndex index.html index.htm index.php
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
# Add this line to the bottom of your configuration.
# Configurationfile for phpmyadmin, aliases and permissions:
Include conf/extra/phpmyadmin.conf

8 Restart httpsrv and configure autostart

Ubuntu

update-rc.d init-httpsrv defaults && httpsrv restart

CentOS

chkconfig --add init-httpsrv && chkconfig init-httpsrv on && httpsrv restart

You can now test your installation
Open a web browser and navigate to:
http://localhost/test/phpinfo.php
http://localhost/phpmyadmin
http://localhost

Read this post to enhance security on SFTP and httpsrv 2.0:
Project httpsrv v2.0 – Increase security with chrooted user using SSH (SFTP) Linux

More actions in this script

Start the webserver
httpsrv start

Stop the webserver
httpsrv stop

Restart the webserver
httpsrv restart

Display active processes
httpsrv stats

Display executabes and there versions
httpsrv info

Display were configurationfiles are:
httpsrv conf

Change permissions, owner and group on /srv/httpsrv/htdocs
httpsrv perm

Change permissions, owner and group on /srv/httpsrv
httpsrv perm_all

Validate configurationfile for Apache2 (httpd)
httpsrv conftest

Create a new empty directory in /srv
cd /srv && httpsrv update_all

Uninstall and remove /srv/httpsrv
cd /srv && httpsrv remove_all

Configurations and variables

Variables in httpsrv/tmp/httpsrv.sh

Warning!
This hasn’t been tested and shall be considered experimental
You will have to change those before you compile and install

root_user=root
root_group=root
User and Group used when changing perrmisions on files and folders
OBS: httpsrv/chroot will always be owned by the root user and group

root_folder=/srv/httpsrv
The path were httpsrv will be installed

service_user=httpsrv
service_group=httpsrv
User and Group used when changing perrmisions on files and folders for the service
OBS: httpsrv/chroot/htdocs will always be owned by the httpsrv user and group

apr1_src=http://archive.apache.org/dist/apr/apr-1.5.2.tar.gz
apr2_src=http://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz
web_src=https://archive.apache.org/dist/httpd/httpd-2.4.26.tar.gz
php_src=http://us.php.net/get/php-7.1.6.tar.gz/from/this/mirror
Variables to hold links that will be used in the script to download sourcefiles
Httpsrv is tested with the versions on those links but you are free to experiment

Download new apr1_src: http://archive.apache.org/dist/apr
Download new apr2_src: http://archive.apache.org/dist/apr
Download new web_src: https://archive.apache.org/dist/httpd
Download new php_src: https://www.howtogeek.com/php-wget

#sock_file=/run/mysqld/mysqld.sock
#sock_file=/var/lib/mysql/mysql.sock
Uncomment one of those variable depending on system in use
This variable enabled php to connect to MySQL via the local Unix-Socket

Configurationfiles for httpsrv

httpsrv/conf/httpd.conf
Main configurationfile for Apache

httpsrv/etc/php.ini
Main configurationfile for php

httpsrv/phpmyadmin/config.inc.php
Main configurationfile for phpMyAdmin
Use this file to change your blowfish_secret

/etc/mysql/my.cnf
Main configurationfile for MySQL

Executables and script

Some files are linked to /usr/local/sbin and will be accessible through the whole system

 

/usr/local/sbin/php = Call this with help to find out more info
/usr/local/sbin/phpize = Can be used when compiling PECL extensions
/usr/local/sbin/htpasswd = Used with flat-files for basic authentication in httpd
/usr/local/sbin/htdigest = Used with flat-files for digest authentication in httpd
/usr/local/sbin/htcacheclean = Used to clean up disk cache in httpd (apache)
/usr/local/sbin/httpsrv = Main script to manage httpsrv (apache and php)
/etc/init.d/init-httpsrv = Initscript to enable autostart of httpsrv

Usefull links for more reading:
http://php.net/manual/en/install.pecl.phpize.php
http://httpd.apache.org/docs/current/programs/htdigest.html
https://httpd.apache.org/docs/2.4/programs/htcacheclean.html
https://httpd.apache.org/docs/current/programs/htpasswd.html
http://php.net/manual/en/features.commandline.interactive.php
https://www.question-defense.com/tools/phpmyadmin-blowfish-secret-generator

DONATE
Donation are not required but very much appreciated.
Click the below link to donate with PayPal (PayPal.Me)
Link: https://www.paypal.me/freddan88

GitHub
Link: https://github.com/freddan88/httpsrv-linux