{"id":421,"date":"2023-02-16T18:36:44","date_gmt":"2023-02-16T18:36:44","guid":{"rendered":"http:\/\/joonim.ca\/?p=421"},"modified":"2023-02-16T18:36:44","modified_gmt":"2023-02-16T18:36:44","slug":"ubuntu-how-to-build-lamp-server-2-of-3-apache","status":"publish","type":"post","link":"https:\/\/waterloobae.com\/blog\/2023\/02\/16\/ubuntu-how-to-build-lamp-server-2-of-3-apache\/","title":{"rendered":"[Ubuntu] How to build LAMP server 2 of 3 &#8211; Apache"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apache configuration files for HTTP(Port 80) and HTTPS(Port 443) can be found as below.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo vi \/etc\/apache2\/sites-available\/ 000-default.conf\n$sudo vi \/etc\/apache2\/sites-available\/ default-ssl.conf<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">SSL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Secured site can be configured by enabling ssl module and you will need to get SSL certificate in advance. Self-Signed SSL did not work for me. You can get free SSL certificates from <a href=\"https:\/\/letsencrypt.org\/\" target=\"_blank\" rel=\"noreferrer noopener\">Let&#8217;s Encrypt<\/a>.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod ssl\n$sudo a2ensite default-ssl\n$sudo vi \/etc\/apache2\/sites-available\/default-ssl.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">SSLCertificateFile    \/etc\/ssl\/certs\/server.crt\n#SSLCertificateKeyFile \/etc\/ssl\/private\/server.key\nSSLCertificateKeyFile \/etc\/ssl\/certs\/server.key\nSSLCertificateChainFile \/etc\/ssl\/certs\/server-ca.crt\n\n &lt;\/VirtualHost>\n# intermediate configuration, tweak to your needs\n# SSLProtocol             all -SSLv2 -SSLv3\n# SSLProtocol +TLSV1.2 +TLSv1.3\nSSLProtocol -all +TLSv1.2\nSSLCipherSuite          ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA256:DHE-RSA-AES256-SHA:ECDHE-ECDSA-DES-CBC3-SHA:ECDHE-RSA-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:AES128-SHA256:AES256-SHA256:AES128-SHA:AES256-SHA:DES-CBC3-SHA:!DSS\nSSLHonorCipherOrder     on\n&lt;\/IfModule><\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo \/etc\/init.d\/apache2 restart<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">No Browsing and .htaccess<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">It can be changed from \/etc\/apache2\/apache2.conf and do not forget restarting apache server after changing.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;Directory \/var\/www\/>\n                Options -Indexes +FollowSymLinks +MultiViews\n                AllowOverride All\n                Require all granted\n&lt;\/Directory><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">SSI and Rewrite<\/h2>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod include\n$sudo vi \/etc\/apache2\/apache2.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;Directory \/var\/www\/>\n                Options -Indexes +FollowSymLinks +MultiViews +Includes\n                AllowOverride All\n                Require all granted\n&lt;\/Directory><\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo vi \/etc\/apache2\/mods-availble\/dir.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;IfModule mod_dir.c>\n          DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm index.shtml\n&lt;\/IfModule><\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod rewrite\n$sudo \/etc\/init.d\/apache2 restart<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Virtual Host<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Each virtual host has its own configuration file. It can be started by copying the default configuration file.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo cp \/etc\/apache2\/sites-available\/default \/etc\/apache2\/sites-available\/test\n$sudo a2ensite test\n$sudo vi \/etc\/apache2\/sites-available\/test<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;VirtualHost *:80>\n\tServerAdmin webmaster@localhost\n\tServerName www.test.org\n\tServerAlias test.org\n\tDocumentRoot \/var\/www\/test<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo vi \/etc\/apache2\/ports.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">Listen 80\nListen 8080\n\n&lt;IfModule ssl_module>\n\tListen 443\n&lt;\/IfModule>\n\n&lt;IfModule mod_gnutls.c>\n\tListen 443\n&lt;\/IfModule><\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo service apache2 restart <\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">php.ini<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Some of values in php.ini need changes according to the requirements<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo vi \/etc\/php\/8.1\/apache2\/php.ini<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">; UNIX: \"\/path1:\/path2\"\ninclude_path = \".:\/usr\/share\/php\"\n\n; Maximum amount of memory a script may consume (128MB)\n; http:\/\/php.net\/memory-limit\nmemory_limit = 8096M\n\n; Maximum execution time of each script, in seconds\n; http:\/\/php.net\/max-execution-time\n; Note: This directive is hardcoded to 0 for the CLI SAPI\nmax_execution_time = 7200\n\n; Maximum size of POST data that PHP will accept.\n; http:\/\/php.net\/post-max-size\npost_max_size = 512M\n\n; Maximum number of files that can be uploaded via a single request\nmax_file_uploads = 5000\n\n; Maximum allowed size for uploaded files.\n; http:\/\/php.net\/upload-max-filesize\nupload_max_filesize = 512M\n\nsession.save_path = \"\/var\/lib\/php\/sessions\"\n\n[browscap]\n; http:\/\/php.net\/browscap\nbrowscap = \/var\/www\/full_php_browscap.ini\n\n; http:\/\/php.net\/session.gc-maxlifetime\nsession.gc_maxlifetime = 86400\n\n; PHP's default character set is set to UTF-8.\n; http:\/\/php.net\/default-charset\n; default_charset = \"UTF-8\"\ndefault_charset = \"ISO-8859-1\"\n\n; &lt;? and ?> tags as PHP source which should be processed as such.\nshort_open_tag = On\n\n[Phar]\n; http:\/\/php.net\/phar.readonly\nphar.readonly = 0<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">ADFS<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">When your organization supports ADFS, SSO is can be configured with <a rel=\"noreferrer noopener\" href=\"https:\/\/simplesamlphp.org\/docs\/stable\/simplesamlphp-sp\" target=\"_blank\">SimpleSAMLphp<\/a>. First, download and install SimpleSAMLphp.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo apt-get install php-curl\n$tar xzf .\/simplesamlphp-1.18.4.tar.gz\n$sudo mv .\/simplesamlphp-1.18.4 \/var\/simplesamlphp<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Then, configure apache to use this directory.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo vi \/etc\/apache2\/sites-available\/000-default.conf\n$sudo vi \/etc\/apache2\/sites-available\/default-ssl.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">        SetEnv SIMPLESAMLPHP_CONFIG_DIR \/var\/simplesamlphp\/config\n        Alias \/simplesaml \/var\/simplesamlphp\/www\n\n        &lt;Directory \/var\/simplesamlphp\/www>\n              Require all granted\n        &lt;\/Directory><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Configuration can be changed from \/config\/config.php. Generate a random salt for &#8216;secretsalt&#8217; =&gt; &#8216;randombytesinsertedhere&#8217;.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\t 'baseurlpath' => 'https:\/\/your.server.ca\/\/simplesaml\/',\n\t'auth.adminpassword' => 'setnewpasswordhere',\n\t'secretsalt' => 'randombytesinsertedhere',\n\t'technicalcontact_name' => 'John Smith',\n   \t'technicalcontact_email' => 'john.smith@example.com',\n\t'language.default' => 'en',\n\t'timezone' => 'America\/Toronto',\n\t'trusted.url.domains' => ['your.server.ca'],<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Enable the certificate for your service provider.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$cd \/var\/simplesamlphp\/cert\n$openssl req -newkey rsa:3072 -new -x509 -days 3652 -nodes -out saml.crt -keyout saml.pem\n$sudo chmod 664 .\/saml.pem\n $vi .\/config\/authsources.php<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">\t'default-sp' => [\n    \t'saml:SP',\n\t\t'sign.logout' => TRUE,\n    \t'privatekey' => 'saml.pem',\n   \t \t'certificate' => 'saml.crt',\n\t\t'NameIDPolicy' => 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',\n\t],<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">After these settings, navigate to the Federation tab, look for Tools and then click XML to simpleSAMLphp meta converter. Copy the contents of the saml20-idp-remote field. Open the <strong><em>metadata\/saml20-idp-remote.php<\/em><\/strong> file and paste the contents. Consider update \/config\/authsources.php for entityID and idp. Ask your ADFS service provider to add NameID with &#8220;Transient&#8221; format.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Imagick and PHP GD<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to use PDF libraries like FPDF and FPDI, some of image packages are required and can be install be as below.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo apt-get install imagemagick\n$sudo apt-get install php-imagick\n$sudo vi \/etc\/Imagemagick-6\/policy.xml\n     &lt;!-- &lt;policy domain=\"coder\" rights=\"none\" pattern=\"MVG\" \/> -->\n     &lt;policy domain=\"coder\" rights=\"read|write\" pattern=\"PDF\" \/>\n$sudo apt-get install inkscape\n$sudo apt-get install php8.0-gd\n$sudo service apache2 restart<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Forcing Users to HTTPS (rewrite\/redirect)<\/h2>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod rewrite\n$sudo a2enmod ssl\n$sudo vi \/etc\/apache2\/sites-available\/000-default.conf<\/pre>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">&lt;VirtualHost *:80>\n    RewriteEngine On\n    RewriteCond %{HTTPS} off\n    RewriteRule (.*) https:\/\/%{HTTP_HOST}%{REQUEST_URI}\n&lt;\/VirtualHost><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Redirect to One URL<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">If you prefer your web site to be without &#8220;www&#8221; even www.yoursite.com and yoursite.com are all configured. You can redirect visitors to one URL you like.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">- $sudo vi \/etc\/apache2\/sites-available\/000-default.conf\n- $sudo vi \/etc\/apache2\/sites-available\/default-ssl.conf\n       &lt;If \"%{HTTP_HOST} != 'yoursite.com'\">\n          \tRedirect \"\/\" \"https:\/\/yoursite.com\/\"\n       &lt;\/If>\t<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Rewrite<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Old URL can be directed to new URL with rewrite module.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod rewrite\n$sudo vi \/etc\/apache2\/sites-available\/000-default.conf\n$sudo vi \/etc\/apache2\/sites-available\/default-ssl.conf\n        RewriteEngine On\n        RewriteRule \"^\/virtualconference\" \"\/events\/virtual-teachers-conference.html\" [NC]<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Subversion<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">As one of Apache modules, <a href=\"https:\/\/help.ubuntu.com\/community\/Subversion\" target=\"_blank\" rel=\"noreferrer noopener\">Subversion<\/a> can be installed on Ubuntu.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt-get install libapache2-mod-svn \n$ sudo a2enmod dav_svn \n$ sudo vi \/etc\/apache2\/mods-available\/dav_svn.conf\n&lt;Location \/svn>\n     DAV svn\n     SVNPath \/svn\/repos\/bcc\n     AuthType Basic\n     AuthName \"BCC subversion repository\"\n     AuthUserFile \/etc\/subversion\/passwd\n     Require valid-user\n&lt;\/Location>\n\n$ sudo mkdir \/etc\/subversion\n$ sudo htpasswd -c \/etc\/subversion\/passwd user_name \n(Caution: This create and overwrite existing passwd file)\n\n$ sudo htpasswd \/etc\/subversion\/passwd next_user_names\n\n$ sudo chown -R www-data:www-data \/svn\/*\n$sudo chmod -R g+rws \/svn\/*<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Pandoc<\/h2>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo apt-get install pandoc<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It can be installed as easy as above. Meanwhile, it becomes complicated if you need the latest version.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$ sudo pandoc --version\n$ sudo apt purge pandoc\n\nGet the latest .deb at https:\/\/github.com\/jgm\/pandoc\/releases\n$ sudo wget https:\/\/github.com\/jgm\/pandoc\/releases\/download\/2.19.2\/pandoc-2.19.2-1-amd64.deb \n$ sudo dpkg -i pandoc-2.19.2-1-amd64.deb<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>X-XSS-Protection (UTF-7 Variants) &amp; Protect Cookies<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo a2enmod headers\n$sudo vi \/etc\/apache2\/apache2.conf\n&lt;Directory \/var\/www\/>\n        Options -Indexes +FollowSymLinks +MultiViews +Includes\n        AllowOverride All\n        Require all granted\n        Header set X-XSS-Protection \"1; mode=block\"\n        Header edit Set-Cookie ^(.*)$ $1;HttpOnly;Secure\n&lt;\/Directory>\n\n$ sudo service apache2 restart<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">CSV -> XLSZ<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Length of sheet name should be smaller than 31.<\/p>\n\n\n\n<pre class=\"wp-block-syntaxhighlighter-code\">$sudo apt install unoconv\n$unoconv --show\n$unoconv --format xlsx example.csv<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apache configuration files for HTTP(Port 80) and HTTPS(Port 443) can be found as below. SSL Secured site can be configured by enabling ssl module and you will need to get SSL certificate in advance. Self-Signed SSL did not work for me. You can get free SSL certificates from Let&#8217;s Encrypt. No Browsing and .htaccess It [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-421","post","type-post","status-publish","format-standard","hentry","category-it-tips"],"_links":{"self":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/421","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/comments?post=421"}],"version-history":[{"count":0,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/posts\/421\/revisions"}],"wp:attachment":[{"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/media?parent=421"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/categories?post=421"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/waterloobae.com\/blog\/wp-json\/wp\/v2\/tags?post=421"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}