Difference between revisions of "Lamp Server - Almalinux"

From LinuxAdmin Wiki
Jump to navigation Jump to search
 
(4 intermediate revisions by the same user not shown)
Line 2: Line 2:
 
[[Category:Linux]]
 
[[Category:Linux]]
  
===== Notes:=====
+
===== Notes=====
  
 
*Make sure almalinux is updated to latest version
 
*Make sure almalinux is updated to latest version
Line 10: Line 10:
 
<code>dnf install httpd</code>
 
<code>dnf install httpd</code>
  
====== enable it so it will automatically start after restart and start it ======
+
====== Enable and start it ======
<code>systemctl enable httpd && systemctl start httpd<br /></code>
+
<code>systemctl enable httpd && systemctl start httpd</code>
 +
====== Make sure it up (optional) ======
 +
<code>systemctl status httpd</code>
 +
 
 +
===2) Mariadb Installation:===
 +
Right now, mariadb 10.6 is the latest version, but the default install gives you 10.3, so install the latest like this:
 +
 
 +
====== create repo for mariadb 10.6 ======
 +
<code>vim /etc/yum.repos.d/mariadb.repo </code>
 +
 
 +
<syntaxhighlight lang="bash">
 +
[mariadb]
 +
name = MariaDB
 +
baseurl = http://yum.mariadb.org/10.6/rhel8-amd64
 +
module_hotfixes=1
 +
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
 +
gpgcheck=1
 +
</syntaxhighlight>
 +
 
 +
======Run dnf update to make sure the os sees the repo======
 +
<code>dnf update</code>
 +
 
 +
======Install MariaDb======
 +
 
 +
<code> dnf install mariadb-server mariadb </code>
 +
 
 +
======Start and Enable it======
 +
<code>systemctl enable mariadb && systemctl start mariadb </code>
 +
 
 +
======Secure the installation======
 +
run <code>mariadb-secure-installation</code> and follow the on-screen instructions
 +
 
 +
=== 3) PHP Installation ===
 +
====== Install REMI repo ======
 +
 
 +
<code>dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm</code>
 +
 
 +
====== List the available versions: ======
 +
<code>dnf module list php</code>
 +
 
 +
====== Reset the default(which is 7.2)======
 +
<code>dnf module reset php</code>
 +
 
 +
====== Select the php version you need (7.4 here)======
 +
<code>dnf module enable php:remi-7.4 </code>
 +
 
 +
====== Install the php ======
 +
<code>dnf install php74 php74-php-fpm -y</code>
 +
 
 +
 
 +
====== Enable and start the FPM service ======  
 +
<code>systemctl start php74-php-fpm && systemctl enable php74-php-fpm</code>
 +
 
 +
=== 4) Virtualhost Config ===
 +
====== Create relevant directories ======
 +
<syntaxhighlight lang="bash">
 +
mkdir -p /var/www/vhosts/DOMAIN_NAME/httpdocs
 +
mkdir -p /var/www/vhosts/DOMAIN_NAME/logs
 +
 
 +
cd /var/www/vhosts/DOMAIN_NAME/logs
 +
touch error.log access.log
 +
 
 +
cd /etc/httpd/conf.d/
 +
mkdir php_conf && cd php_conf
 +
</syntaxhighlight>
 +
 
 +
====== Create php config ======
 +
<code>vim php74.conf</code>
 +
 
 +
<syntaxhighlight lang="bash">
 +
<IfModule !mod_php7.c>
 +
<FilesMatch \.(php|phar)$>
 +
SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost"
 +
</FilesMatch>
 +
</IfModule>
 +
</syntaxhighlight>
 +
 
 +
====== Create the VirtualHost and Copy the content ======
 +
<code>vim DOMAIN_NAME.conf</code>
 +
<syntaxhighlight lang="bash">
 +
<VirtualHost *:80>
 +
    ServerAdmin hpc@tau.ac.il
 +
    ServerName hpc-zabbix.tau.ac.il
 +
 
 +
    DocumentRoot /var/www/vhosts/hpc-zabbix.tau.ac.il/httpdocs
 +
    ### php conf start ###
 +
    Include /etc/httpd/conf.d/php_conf/php74.conf
 +
    ### php conf end ###
 +
 
 +
      <Directory /var/www/vhosts/hpc-zabbix.tau.ac.il/httpdocs/>
 +
                Require all granted
 +
 
 +
        </Directory>
 +
 
 +
    ErrorLog /var/www/vhosts/hpc-zabbix.tau.ac.il/logs/error.log
 +
    CustomLog /var/www/vhosts/hpc-zabbix.tau.ac.il/logs/access.log combined
 +
</VirtualHost>
 +
</syntaxhighlight>
 +
 
 +
=== 5) Make sure php error get written to custom log===
 +
<code>cd /etc/opt/remi/php74/
 +
vim php.ini
 +
</code>
 +
<syntaxhighlight lang="bash">
 +
#If you want to set error log by host
 +
[HOST=www.example.com]
 +
error_log=/var/www/myapplication/path/to/my/error.log
 +
 
 +
[HOST=sub.example.com]
 +
error_log=/var/www/mysubapplication/path/to/my/error.log
 +
#If you want to set error log by path (handy if you're working on a server with an IP address but no domain)
 +
[PATH=/var/www/myapplication]
 +
error_log=/var/www/myapplication/path/to/my/error.log
 +
 
 +
[PATH=/var/www/mysubapplication]
 +
error_log=/var/www/mysubapplication/path/to/my/error.log
 +
</syntaxhighlight>
 +
 
 +
Now go to:<br>
 +
 
 +
<code>cd /etc/opt/remi/php74/php-fpm.d/</code>
 +
 
 +
 
 +
In that directory, edit the file <code>www.conf</code>. Note the values for user and group in that file, whose out-of-the-box setting is www-data for both. Look for the term <code>catch_workers_output</code> and make sure it is uncommented and set to yes, like so:
 +
<code>catch_workers_output = yes</code>
 +
 
 +
<code>systemctl restart php74-php-fpm</code>
  
 
===Sources:===
 
===Sources:===
<blockquote>https://vitux.com/how-to-install-lamp-stack-on-almalinux-8/
+
<blockquote>
 +
*https://vitux.com/how-to-install-lamp-stack-on-almalinux-8/
  
https://www.linuxcapable.com/how-to-install-mariadb-10-6-on-almalinux-8/
+
*https://www.linuxcapable.com/how-to-install-mariadb-10-6-on-almalinux-8/
  
https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-centos-8
+
*https://www.digitalocean.com/community/tutorials/how-to-run-multiple-php-versions-on-one-server-using-apache-and-php-fpm-on-centos-8
  
https://stackoverflow.com/questions/44558380/how-do-you-set-the-php-error-log-location-in-the-apache-configuration-file</blockquote>
+
*https://stackoverflow.com/questions/44558380/how-do-you-set-the-php-error-log-location-in-the-apache-configuration-file</blockquote>

Latest revision as of 18:20, 17 April 2022


Notes
  • Make sure almalinux is updated to latest version
  • Either disable selinux now or suffer... (you can also learn how to live with it)

1) HTTPD Installation:

dnf install httpd

Enable and start it

systemctl enable httpd && systemctl start httpd

Make sure it up (optional)

systemctl status httpd

2) Mariadb Installation:

Right now, mariadb 10.6 is the latest version, but the default install gives you 10.3, so install the latest like this:

create repo for mariadb 10.6

vim /etc/yum.repos.d/mariadb.repo

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.6/rhel8-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Run dnf update to make sure the os sees the repo

dnf update

Install MariaDb

dnf install mariadb-server mariadb

Start and Enable it

systemctl enable mariadb && systemctl start mariadb

Secure the installation

run mariadb-secure-installation and follow the on-screen instructions

3) PHP Installation

Install REMI repo

dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

List the available versions:

dnf module list php

Reset the default(which is 7.2)

dnf module reset php

Select the php version you need (7.4 here)

dnf module enable php:remi-7.4

Install the php

dnf install php74 php74-php-fpm -y


Enable and start the FPM service

systemctl start php74-php-fpm && systemctl enable php74-php-fpm

4) Virtualhost Config

Create relevant directories
mkdir -p /var/www/vhosts/DOMAIN_NAME/httpdocs
mkdir -p /var/www/vhosts/DOMAIN_NAME/logs

cd /var/www/vhosts/DOMAIN_NAME/logs
touch error.log access.log

cd /etc/httpd/conf.d/
mkdir php_conf && cd php_conf
Create php config

vim php74.conf

<IfModule !mod_php7.c>
<FilesMatch \.(php|phar)$>
SetHandler "proxy:unix:/var/opt/remi/php74/run/php-fpm/www.sock|fcgi://localhost"
</FilesMatch>
</IfModule>
Create the VirtualHost and Copy the content

vim DOMAIN_NAME.conf

<VirtualHost *:80>
     ServerAdmin hpc@tau.ac.il
     ServerName hpc-zabbix.tau.ac.il

     DocumentRoot /var/www/vhosts/hpc-zabbix.tau.ac.il/httpdocs
     ### php conf start ###
     Include /etc/httpd/conf.d/php_conf/php74.conf
     ### php conf end ###

       <Directory /var/www/vhosts/hpc-zabbix.tau.ac.il/httpdocs/>
                Require all granted

        </Directory>

     ErrorLog /var/www/vhosts/hpc-zabbix.tau.ac.il/logs/error.log
     CustomLog /var/www/vhosts/hpc-zabbix.tau.ac.il/logs/access.log combined
</VirtualHost>

5) Make sure php error get written to custom log

cd /etc/opt/remi/php74/ vim php.ini

#If you want to set error log by host
[HOST=www.example.com]
error_log=/var/www/myapplication/path/to/my/error.log

[HOST=sub.example.com]
error_log=/var/www/mysubapplication/path/to/my/error.log
#If you want to set error log by path (handy if you're working on a server with an IP address but no domain)
[PATH=/var/www/myapplication]
error_log=/var/www/myapplication/path/to/my/error.log

[PATH=/var/www/mysubapplication]
error_log=/var/www/mysubapplication/path/to/my/error.log

Now go to:

cd /etc/opt/remi/php74/php-fpm.d/


In that directory, edit the file www.conf. Note the values for user and group in that file, whose out-of-the-box setting is www-data for both. Look for the term catch_workers_output and make sure it is uncommented and set to yes, like so: catch_workers_output = yes

systemctl restart php74-php-fpm

Sources: