Difference between revisions of "Appendices:ApachePHP"
(Created page with "Work In Progress") |
Dtavernier (talk | contribs) (→Changes for /usr/lib/systemd/system/php-fpm.service) |
||
(14 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
Work In Progress | Work In Progress | ||
+ | |||
+ | The easiest way is to install the standard packages from your OS distribution, but this requires connecting to a repo.<br> | ||
+ | The httpd daemon can also be started with a user other than root, provided you don't use port 80 for the site.<br> | ||
+ | This example is an installation of Apache and PHP 8.2.18 on Rocky Linux 9.<br> | ||
+ | <br> | ||
+ | ==Installing packages== | ||
+ | |||
+ | Installing Apache Web Server with dnf : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] dnf -y update | ||
+ | [root@vmsqwarebox ~] dnf install httpd mod_ssl -y | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | Start and enable Apache : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | systemctl start httpd | ||
+ | systemctl enable httpd | ||
+ | systemctl status httpd | ||
+ | |||
+ | ## If firewall is active : | ||
+ | firewall-cmd --zone=public --permanent --add-service=http | ||
+ | firewall-cmd --zone=public --permanent --add-service=https | ||
+ | firewall-cmd --reload | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | Test to see if your site is responding : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | http://192.168.231.28/ | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | Repo activation and installing PHP 8.2.18 : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | #To add EPEL and REMI Repository. | ||
+ | dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm | ||
+ | dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm | ||
+ | |||
+ | #To install yum utilities. | ||
+ | dnf -y install yum-utils | ||
+ | |||
+ | #To enable php 8.2 Remi repository. | ||
+ | dnf module reset php | ||
+ | dnf module install php:remi-8.2 | ||
+ | |||
+ | # To list the available PHP version: | ||
+ | dnf module list php | ||
+ | |||
+ | Last metadata expiration check: 0:01:14 ago on Mon 15 Apr 2024 10:10:57 AM EDT. | ||
+ | Rocky Linux 9 - AppStream | ||
+ | Name Stream Profiles Summary | ||
+ | php 8.1 common [d], devel, minimal PHP scripting language | ||
+ | php 8.2 common [d], devel, minimal PHP scripting language | ||
+ | |||
+ | Remi's Modular repository for Enterprise Linux 9 - x86_64 | ||
+ | Name Stream Profiles Summary | ||
+ | php remi-7.4 common [d], devel, minimal PHP scripting language | ||
+ | php remi-8.0 common [d], devel, minimal PHP scripting language | ||
+ | php remi-8.1 common [d], devel, minimal PHP scripting language | ||
+ | php remi-8.2 [e] common [d] [i], devel, minimal PHP scripting language | ||
+ | php remi-8.3 common [d], devel, minimal PHP scripting language | ||
+ | |||
+ | Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled | ||
+ | |||
+ | # Installing PHP | ||
+ | dnf install -y php php-pdo php-mysqlnd php-ldap php-zip php-gmp | ||
+ | |||
+ | root@vmsqwarebox:/root # php -v | ||
+ | PHP 8.2.18 (cli) (built: Apr 9 2024 18:46:23) (NTS gcc x86_64) | ||
+ | Copyright (c) The PHP Group | ||
+ | Zend Engine v4.2.18, Copyright (c) Zend Technologies | ||
+ | with Zend OPcache v8.2.18, Copyright (c), by Zend Technologies | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | Test to see if your site is responding and is setup with PHP 8.2 : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | systemctl restart httpd | ||
+ | |||
+ | cat <<EOFCAT >/var/www/html/phpinfo.php | ||
+ | <?php | ||
+ | |||
+ | phpinfo(); | ||
+ | |||
+ | ?> | ||
+ | EOFCAT | ||
+ | |||
+ | http://192.168.230.22/phpinfo.php | ||
+ | |||
+ | => PHP Version 8.2.18 | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | ==Changes php.ini + php.conf== | ||
+ | |||
+ | Change the file /etc/php.ini | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] cp -p /etc/php.ini /etc/php.ini.org | ||
+ | [root@vmsqwarebox ~] vi /etc/php.ini | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | In principle, the only changes to be made are the following : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | ;session.save_path = "/tmp" | ||
+ | memory_limit = 512M | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | Change the file /etc/httpd/conf.d/php.conf | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] cp -p /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.org | ||
+ | [root@vmsqwarebox ~] vi /etc/httpd/conf.d/php.conf | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | In principle, the only changes to be made are the following : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | #php_value session.save_path "/var/lib/php/session" | ||
+ | php_value session.save_path "/var/tmp" | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | ==Changes httpd.conf== | ||
+ | |||
+ | Change the file /etc/httpd/conf/httpd.conf | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org | ||
+ | [root@vmsqwarebox ~] vi /etc/httpd/conf/httpd.conf | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | In principle, the only changes to be made are the following : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | User dbsqware | ||
+ | Group dba | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | ==Changes for /etc/php-fpm.d/www.conf== | ||
+ | |||
+ | Change the file /etc/php-fpm.d/www.conf | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org | ||
+ | [root@vmsqwarebox ~] vi /etc/php-fpm.d/www.conf | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | In principle, the only changes to be made are the following : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | user = dbsqware | ||
+ | group = dba | ||
+ | ;listen.acl_users = apache,nginx | ||
+ | ;listen.acl_groups = | ||
+ | listen.owner = dbsqware | ||
+ | listen.group = dba | ||
+ | listen.mode = 0660 | ||
+ | listen.allowed_clients = | ||
+ | php_value[session.save_path] = /var/tmp | ||
+ | php_admin_value[memory_limit] = 512M | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | ==Changes for /usr/lib/systemd/system/php-fpm.service== | ||
+ | Change the file /usr/lib/systemd/system/php-fpm.service | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [root@vmsqwarebox ~] cp -p /usr/lib/systemd/system/php-fpm.service /usr/lib/systemd/system/php-fpm.service.org | ||
+ | [root@vmsqwarebox ~] vi /usr/lib/systemd/system/php-fpm.service | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | In principle, the only changes to be made are the following : | ||
+ | <syntaxhighlight lang="sh" line> | ||
+ | [Service] | ||
+ | User=dbsqware | ||
+ | Group=dba | ||
+ | </syntaxhighlight> | ||
+ | <br> | ||
+ | |||
+ | ==Reload== | ||
+ | |||
+ | <syntaxhighlight lang="sh" line> | ||
+ | systemctl daemon-reload | ||
+ | |||
+ | chown -R dbsqware:dba /var/log/php-fpm /var/log/httpd | ||
+ | chmod -R g+rw /var/log/php-fpm /var/log/httpd | ||
+ | chmod -R g+s /var/log/php-fpm /var/log/httpd | ||
+ | |||
+ | systemctl is-enabled php-fpm | ||
+ | |||
+ | systemctl enable --now php-fpm | ||
+ | |||
+ | systemctl start php-fpm | ||
+ | systemctl start httpd | ||
+ | </syntaxhighlight> | ||
+ | <br> |
Latest revision as of 10:00, 28 April 2025
Work In Progress
The easiest way is to install the standard packages from your OS distribution, but this requires connecting to a repo.
The httpd daemon can also be started with a user other than root, provided you don't use port 80 for the site.
This example is an installation of Apache and PHP 8.2.18 on Rocky Linux 9.
Contents
Installing packages
Installing Apache Web Server with dnf :
1 [root@vmsqwarebox ~] dnf -y update
2 [root@vmsqwarebox ~] dnf install httpd mod_ssl -y
Start and enable Apache :
1 systemctl start httpd
2 systemctl enable httpd
3 systemctl status httpd
4
5 ## If firewall is active :
6 firewall-cmd --zone=public --permanent --add-service=http
7 firewall-cmd --zone=public --permanent --add-service=https
8 firewall-cmd --reload
Test to see if your site is responding :
1 http://192.168.231.28/
Repo activation and installing PHP 8.2.18 :
1 #To add EPEL and REMI Repository.
2 dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
3 dnf -y install https://rpms.remirepo.net/enterprise/remi-release-9.rpm
4
5 #To install yum utilities.
6 dnf -y install yum-utils
7
8 #To enable php 8.2 Remi repository.
9 dnf module reset php
10 dnf module install php:remi-8.2
11
12 # To list the available PHP version:
13 dnf module list php
14
15 Last metadata expiration check: 0:01:14 ago on Mon 15 Apr 2024 10:10:57 AM EDT.
16 Rocky Linux 9 - AppStream
17 Name Stream Profiles Summary
18 php 8.1 common [d], devel, minimal PHP scripting language
19 php 8.2 common [d], devel, minimal PHP scripting language
20
21 Remi's Modular repository for Enterprise Linux 9 - x86_64
22 Name Stream Profiles Summary
23 php remi-7.4 common [d], devel, minimal PHP scripting language
24 php remi-8.0 common [d], devel, minimal PHP scripting language
25 php remi-8.1 common [d], devel, minimal PHP scripting language
26 php remi-8.2 [e] common [d] [i], devel, minimal PHP scripting language
27 php remi-8.3 common [d], devel, minimal PHP scripting language
28
29 Hint: [d]efault, [e]nabled, [x]disabled, [i]nstalled
30
31 # Installing PHP
32 dnf install -y php php-pdo php-mysqlnd php-ldap php-zip php-gmp
33
34 root@vmsqwarebox:/root # php -v
35 PHP 8.2.18 (cli) (built: Apr 9 2024 18:46:23) (NTS gcc x86_64)
36 Copyright (c) The PHP Group
37 Zend Engine v4.2.18, Copyright (c) Zend Technologies
38 with Zend OPcache v8.2.18, Copyright (c), by Zend Technologies
Test to see if your site is responding and is setup with PHP 8.2 :
1 systemctl restart httpd
2
3 cat <<EOFCAT >/var/www/html/phpinfo.php
4 <?php
5
6 phpinfo();
7
8 ?>
9 EOFCAT
10
11 http://192.168.230.22/phpinfo.php
12
13 => PHP Version 8.2.18
Changes php.ini + php.conf
Change the file /etc/php.ini
1 [root@vmsqwarebox ~] cp -p /etc/php.ini /etc/php.ini.org
2 [root@vmsqwarebox ~] vi /etc/php.ini
In principle, the only changes to be made are the following :
1 ;session.save_path = "/tmp"
2 memory_limit = 512M
Change the file /etc/httpd/conf.d/php.conf
1 [root@vmsqwarebox ~] cp -p /etc/httpd/conf.d/php.conf /etc/httpd/conf.d/php.conf.org
2 [root@vmsqwarebox ~] vi /etc/httpd/conf.d/php.conf
In principle, the only changes to be made are the following :
1 #php_value session.save_path "/var/lib/php/session"
2 php_value session.save_path "/var/tmp"
Changes httpd.conf
Change the file /etc/httpd/conf/httpd.conf
1 [root@vmsqwarebox ~] cp -p /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.org
2 [root@vmsqwarebox ~] vi /etc/httpd/conf/httpd.conf
In principle, the only changes to be made are the following :
1 User dbsqware
2 Group dba
Changes for /etc/php-fpm.d/www.conf
Change the file /etc/php-fpm.d/www.conf
1 [root@vmsqwarebox ~] cp -p /etc/php-fpm.d/www.conf /etc/php-fpm.d/www.conf.org
2 [root@vmsqwarebox ~] vi /etc/php-fpm.d/www.conf
In principle, the only changes to be made are the following :
1 user = dbsqware
2 group = dba
3 ;listen.acl_users = apache,nginx
4 ;listen.acl_groups =
5 listen.owner = dbsqware
6 listen.group = dba
7 listen.mode = 0660
8 listen.allowed_clients =
9 php_value[session.save_path] = /var/tmp
10 php_admin_value[memory_limit] = 512M
Changes for /usr/lib/systemd/system/php-fpm.service
Change the file /usr/lib/systemd/system/php-fpm.service
1 [root@vmsqwarebox ~] cp -p /usr/lib/systemd/system/php-fpm.service /usr/lib/systemd/system/php-fpm.service.org
2 [root@vmsqwarebox ~] vi /usr/lib/systemd/system/php-fpm.service
In principle, the only changes to be made are the following :
1 [Service]
2 User=dbsqware
3 Group=dba
Reload
1 systemctl daemon-reload
2
3 chown -R dbsqware:dba /var/log/php-fpm /var/log/httpd
4 chmod -R g+rw /var/log/php-fpm /var/log/httpd
5 chmod -R g+s /var/log/php-fpm /var/log/httpd
6
7 systemctl is-enabled php-fpm
8
9 systemctl enable --now php-fpm
10
11 systemctl start php-fpm
12 systemctl start httpd