How to install AMP on CentOS 7 linux
In this article we have decided to talk about how to install AMP on CentOS 7 linux.
AMP is synonym for Apache, Mysql or Mariadb and PHP.
lots of applications and CMSs like WordPress and Joomla heavily rely on AMP for their operations.
Here is our environment:
OS: CentOS 7 linux on VMware
Firewall: firewalld
SElinux: enforcing
Apache version: 2.4
Mariadb version: 10.5
PHP version: 7.2
IP address: 192.168.147.128
1- Install Apache
First we install apache and related packages and then do some configuration on it:
# yum install httpd
apache configuration file is located in /etc/httpd/conf/httpd.conf. if you want to do some optimization on default apache configuration, refer to apache documentation.
Now we enable apache service and start it:
# systemctl enable httpd # systemctl start httpd # systemctl status httpd
then point to server IP address in a browser like Firefox to be sure apache service is working properly:
# http://192.168.147.128
2-Install MariaDB
Mariadb is a fork of Mysql that has been developed by former Mysql team and have innovation and better features than Mysql.
So here we prefer Mariadb. first we add Mariadb repository and then install it:
# vim /etc/yum.repos.d/mariadb.repo
then put these content in it:
[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.5/centos7-amd64/ gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1
save file and issue the following command:
# yum install mariadb-server
then enable mariadb service and start it:
# systemctl enable mariadb # systemctl start mariadb
now run the following command for initial Mariadb configuration:
# mysql_secure_installation
and continue like below:
Enter current password for root (enter for none): press enter
Switch to unix_socket authentication [Y/n] n
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Remove anonymous users? [Y/n] Y
Disallow root login remotely? [Y/n] Y
Remove test database and access to it? [Y/n] Y
Reload privilege tables now? [Y/n] Y
2- Install PHP
Now we install PHP and PHP-FPM from remi repository:
# yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm # yum install php72 php72-php-fpm
then enable and start php-fpm service:
# systemctl enable php72-php-fpm # systemctl start php72-php-fpm
now we need to make script wrapper to call php72-cgi:
# cat > /var/www/cgi-bin/php72.fcgi << EOF # #!/bin/bash # exec /bin/php72-cgi # EOF
then we set executable bit on script:
# sudo chmod 755 /var/www/cgi-bin/php72.fcgi
Now we put php configuration in apache conf directory:
# cat > /etc/httpd/conf.d/php.conf << EOF # ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" # AddHandler php72-fcgi .php # Action php72-fcgi /cgi-bin/php72.fcgi
then put a test script in apache root document:
# echo "<?php phpinfo(); ?>" > /var/www/html/index.php
finally restart apache service:
# systemctl restart httpd
In a browser like firefox, point to below address to see php info:
http://192.168.147.128/index.php
Note: replace above IP address with your own
Now we have done all steps to install AMP and our OS is ready to host applications and CMSs.