Build LAMP on CentOS 7.4 (CentOS 7.4, httpd-2.4.6, MariaDB 5.5.56, PHP 5.4.16)

Install Apache, PHP and MariaDB on CentOS 7.4 (LAMP)

In this tutorial, I use the host with IP address 192.168.10.10

These settings may vary, so you must replace them where appropriate.

Imprint

  • Linux:CentOS 7.4
  • Apache:httpd-2.4.6
  • MariaDB:MariaDB 5.5.56
  • PHP:PHP 5.4.16

Configure SELinux and Firewalld Services

In this tutorial we turn off the SELinux service, so we can do this:

[root@kangvcar1 ~]# vim /etc/selinux/config
SELINUX=disabled	# 修改SELinux配置文件的SELINUX参数为disabled,重启后生效
[root@kangvcar1 ~]# setenforce 0	# 此命令可以让SELinux临时关闭并立即生效

In the tutorial we don't turn off the Firewalld service, because in production we should turn it on to work more securely, and we configure open http and https services to provide access to hosts on the Internet. So we can do this:

[root@kangvcar1 ~]# systemctl start firewalld
[root@kangvcar1 ~]# firewall-cmd --permanent --zone=public --add-service=http	# 放行 http 服务
[root@kangvcar1 ~]# firewall-cmd --permanent --zone=public --add-service=https	# 放行 https 服务
[root@kangvcar1 ~]# firewall-cmd --reload

If the site is not accessible from the Internet, you may have to go to the server provider's console to release the appropriate port

install httpd 2.4.6

CentOS 7 ships with Apache 2.4. So we can install it like this:

[root@kangvcar1 ~]# yum -y install httpd	# 安装httpd-2.4
## 为httpd创建系统启动链接(以便httpd在系统引导时自动启动)并启动httpd服务器:
[root@kangvcar1 ~]# systemctl start httpd
[root@kangvcar1 ~]# systemctl enable httpd

Install MariaDB 5.5.56

MariaDB is a MySQL fork. MariaDB is compatible with MySQL, I choose to use MariaDB instead of MySQL here because CentOS7.4 provides MariaDB rpm package by default. Run the following command to install MariaDB with yum:

[root@kangvcar1 ~]# yum -y install mariadb-server mariadb
## 为MariaDB创建系统启动链接(以便MariaDB在系统引导时自动启动)并启动MariaDB服务器:
[root@kangvcar1 ~]# systemctl start mariadb
[root@kangvcar1 ~]# systemctl enable mariadb

Execute the MariaDB initialization script and set a password for the root user:

[root@kangvcar1 ~]# mysql_secure_installation

NOTE: For all MariaDB servers used in production, it is recommended to run all parts of this script! Please read each step carefully!

Install PHP 5.4.16

The latest version of PHP has reached 7.1. The installation method is similar, here we install PHP 5.4.16 provided by default by CentOS7.4. Run the following command to install PHP with yum:

[root@kangvcar1 ~]# yum -y install php

After installing PHP we have to restart Apache:

[root@kangvcar1 ~]# systemctl restart httpd

Test if PHP5 is linked with Apache and get details about your PHP5 installation. We now create a small PHP file (index.php) and call it in the browser. This file will display a lot of useful information about our PHP installation:

[root@kangvcar1 ~]# vim /var/www/html/index.php
<?php
    phpinfo();
?>

Open http://192.168.10.10 in your browser to see the PHP information, as you can see, PHP5 is running and it is working through the Apache 2.0 Handler as shown in the Server API line. If you scroll down you will see all the modules that have been enabled in PHP5. MySQL is not listed there, which means we don't have MySQL support in PHP5 yet. To get MySQL support in PHP, we can install php-mysqlpackages. It's a good idea to install some other PHP5 modules, as well as you might need them for your application. You can search for available PHP5 modules like this:

[root@kangvcar1 ~]# yum search php	# 搜索可用的php模块
## 选择你需要的,并像这样安装它们:
[root@kangvcar1 ~]# yum -y install php-mysql
在下一步中,我将安装一些CMS系统需要的常见PHP模块,如Wordpress,Joomla和Drupal:
[root@kangvcar1 ~]# yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

After the installation is complete, restart the httpd service, and then open http://192.168.10.10 again to see more extension information for PHP:

[root@kangvcar1 ~]# systemctl restart httpd

Install phpMyAdmin-4.4.15.10

I will add the EPEL repo here to install the latest phpMyAdmin as follows:

[root@kangvcar1 ~]# yum -y install epel-release
[root@kangvcar1 ~]# yum -y install phpmyadmin

Then modify the configuration file to allow other hosts to access (by default only local 127.0.0.1 access is allowed), <Directory /usr/share/phpMyAdmin/>comment the <RequireAny>configuration in the <Directory /usr/share/phpMyAdmin/>container, and then add the Require all grantedconfiguration in the container:

[root@kangvcar1 ~]# vim /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
   AddDefaultCharset UTF-8

   <IfModule mod_authz_core.c>
     # Apache 2.4
#     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
#     </RequireAny>
        Require all granted		#添加此行
   </IfModule>
   <IfModule !mod_authz_core.c>
     # Apache 2.2
     Order Deny,Allow
     Deny from All
     Allow from 127.0.0.1
     Allow from ::1
   </IfModule>
   Options none
   AllowOverride Limit
   Require all granted
</Directory>

Restart the httpd service and open http://192.168.10.10/phpmyadmin in the browser .

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325423408&siteId=291194637