Enable sudo for the specified user
Method 1
Run the command visudo
and open /etc/sudoers
,
1 |
visudo |
If the following line is commented out, uncomment it and do the same as below.
1 2 |
## Allows people in group wheel to run all commands %wheel ALL=(ALL) ALL |
Add the target user to the ‘wheel’ group.
1 |
usermod -aG wheel [UserName] |
Method 2
Run the command visudo
and open /etc/sudoers
,
1 |
visudo |
Add to the following line in the root configuration.
1 2 3 |
## Allow root to run any commands anywhere root ALL=(ALL) ALL [UserName] ALL=(ALL) ALL |
Enabling sudo in WinSCP
If you are using WinSCP and want to enable file editing on the remote server with root privileges, configure as follows.
1 2 3 |
sudo vi /etc/sudoers.d/[UserName] [UserName] ALL=NOPASSWD: /usr/libexec/openssh/sftp-server |
WinSCP
Environment, SFTP, Protocol Options, SFTP Server (V), sudo /usr/libexec/openssh/sftp-server
.
Installing Apache2
Install Apache. Also install the ssl module to enable SSL.
1 |
sudo dnf install httpd httpd-devel mod_ssl |
Configure Apache to start automatically at system start-up.
1 |
sudo systemctl enable httpd |
Allow http in firewalls
1 2 3 |
sudo firewall-cmd --add-service=http --zone=public --permanent sudo firewall-cmd --add-service=https --zone=public --permanent sudo firewall-cmd --reload |
Installing MariaDB
1 |
sudo dnf install mariadb-server mariadb |
initialisation
1 |
sudo mysql_secure_installation |
To configure the service to start automatically, use the following command.
1 |
sudo systemctl enable mariadb |
Installing PHP
To install PHP, which comes as standard, use the following command:
1 |
sudo dnf install php php-cli php-fpm php-devel php-curl php-mysqlnd php-gd php-zip php-intl php-common php-imagick php-xmlrpc php-mbstring php-xml |
*Since CentOS 8, when PHP-FPM is installed, the CGI version is invoked by Apache, not the modular version.
When using a version other than the standard installed version
Adding a repository.
If PHP 5.6 is used, use the Raven repository.
1 2 |
sudo dnf install https://pkgs.dyn.su/el9/base/x86_64/raven-release.el9.noarch.rpm sudo dnf install --enablerepo=raven-modular php56-php php56-php-fpm … |
If PHP 7.4 or later is used, use the Remi repository.
1 |
sudo dnf install https://rpms.remirepo.net/enterprise/remi-release-9.rpm |
Install PHP 7.4
1 2 3 4 5 |
sudo dnf module reset php && sudo dnf module enable php:remi-7.4 sudo dnf install php php-cli php-fpm php-devel php-curl php-mysqlnd php-gd php-zip php-intl php-common php-imagick php-xmlrpc php-mbstring php-xml # To install different versions of PHP at the same time sudo dnf install php74-php php74-php-cli php74-php-fpm php74-php-devel php74-php-curl php74-php-mysqlnd php74-php-gd php74-php-zip php74-php-intl php74-php-common php74-php-imagick php74-php-xmlrpc php74-php-mbstring php74-php-xml sudo dnf install php81-php php81-php-cli php81-php-fpm php81-php-devel php81-php-curl php81-php-mysqlnd php81-php-gd php81-php-zip php81-php-intl php81-php-common php81-php-imagick php81-php-xmlrpc php81-php-mbstring php81-php-xml |
To install other versions such as PHP 8.1:
1 2 |
sudo dnf module reset php && sudo dnf module enable php:remi-[PHPversion] sudo dnf install php … |
Switch between multiple versions of PHP per virtual host
Edit /etc/opt/remi/php[version]/php-fpm.d/www.conf
if you installed by version with Remi.
Configuration of PHP 7.4
1 2 3 4 5 6 |
[www] user = apache group = apache listen = /run/php-fpm/php74-fpm.sock listen.owner = apache listen.group = apache |
Configure virtual host settings in /etc/httpd/conf.d/vhost.conf
etc.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<VirtualHost *:80> ServerName php74.example.com DocumentRoot /var/www/html/php74 <Directory /var/www/html/php74> AllowOverride All Require all granted </Directory> # Specify PHP-FPM sockets in PHP 7.4 <FilesMatch \.php$> SetHandler "proxy:unix:/run/php-fpm/php74-fpm.sock|fcgi://localhost" </FilesMatch> ErrorLog /var/log/httpd/php74-error.log CustomLog /var/log/httpd/php74-access.log combined </VirtualHost> |
Restart php-fpm
and the Apache service for the configuration to take effect.
1 2 3 |
sudo systemctl restart php74-php-fpm sudo systemctl restart php81-php-fpm sudo systemctl restart httpd |
Running PHP as different users
Copy /etc/opt/remi/php[version]/php-fpm.d/www.conf
and create user1.conf using the following command.
*If you have installed multiple versions of PHP with Remi.
1 |
sudo cp /etc/opt/remi/php[version]/php-fpm.d/www.conf /etc/opt/remi/php[version]/php-fpm.d/user1.conf |
Rewrite the following parts of the file.
1 2 3 4 5 6 |
[user1] user = user1 group = user1 listen = /run/php-fpm/php7.4-fpm-user1.sock listen.owner = user1 listen.group = user1 |
Restart PHP-FPM.
A socket file php7.4-fpm-user1.sock
will be created in /run/php-fpm/
.
Add the following to the Apache configuration file.
1 2 3 |
<FilesMatch \.php$> SetHandler "proxy:unix:/run/php-fpm/php7.4-fpm-user1.sock|fcgi://localhost" </FilesMatch> |
Restart Apache
1 |
sudo dnf restart hpptd |
phpMyAdmin installation
Enabling the EPEL repository
1 |
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm |
Install phpMyAdmin
1 |
sudo dnf install phpMyAdmin |
Restart Apache
1 |
sudo systemctl restart httpd |
By default, only connections from the local host are allowed to the area where phpMyAdmin is installed, and not remotely. phpMyAdmin configuration file /etc/httpd/conf.d/phpMyAdmin.conf
, open it and configure Apache.
1 2 3 4 5 6 7 8 9 10 11 12 |
<Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 Require local </Directory> ↓ <Directory /usr/share/phpMyAdmin/> AddDefaultCharset UTF-8 # Require local Require all granted </Directory> |
Restart Apache
1 |
sudo systemctl restart httpd |
コメント