加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Yum安装LAMP(Centos7.2+Apache2.4+Mariadb5.5.56+PHP7.0.24)

发布时间:2020-12-15 09:23:05 所属栏目:安全 来源:网络整理
导读:一、简介 最近客户提出需要使用PHP7的需求,第一次是给客户安装的是LNMP-full的集成环境,但是后面不便于添加扩展模块,以及本人对Nginx不是很了解,经协商后改用LAMP,以下内容为真实环境搭建完成后为了方便记忆在虚拟环境中的配置,和真是环境基本一样 二

一、简介

最近客户提出需要使用PHP7的需求,第一次是给客户安装的是LNMP-full的集成环境,但是后面不便于添加扩展模块,以及本人对Nginx不是很了解,经协商后改用LAMP,以下内容为真实环境搭建完成后为了方便记忆在虚拟环境中的配置,和真是环境基本一样


二、准备环境

操作系统 IP地址 相关软件包
Centos7.2 10.0.0.11 php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel

三、实施步骤


1、使用yum安装Apache、Mariadb、PHP等软件包以及相关软件包,我们的Yum使用系统默认Yum源。


yum install httpd httpd-devel mariadb mariadb-server mariadb-libs mariadb-devel -y


2、启动服务并设置开机自启以及查看服务状态

systemctl enable httpd mariadb

systemctl start httpd mariadb


[root@localhost ~]# systemctl status httpd mariadb

● httpd.service - The Apache HTTP Server

Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)

Active: active (running) since 五 2017-10-20 04:29:17 CST; 6s ago

Docs: man:httpd(8)

man:apachectl(8)

Main PID: 12304 (httpd)

Status: "Processing requests..."

CGroup: /system.slice/httpd.service

├─12304 /usr/sbin/httpd -DFOREGROUND

├─12306 /usr/sbin/httpd -DFOREGROUND

├─12307 /usr/sbin/httpd -DFOREGROUND

├─12308 /usr/sbin/httpd -DFOREGROUND

├─12309 /usr/sbin/httpd -DFOREGROUND

└─12310 /usr/sbin/httpd -DFOREGROUND


10月 20 04:29:17 localhost systemd[1]: Starting The Apache HT...

10月 20 04:29:17 localhost httpd[12304]: AH00558: httpd: Coul...

10月 20 04:29:17 localhost systemd[1]: Started The Apache HTT...


● mariadb.service - MariaDB database server

Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)

Drop-In: /etc/systemd/system/mariadb.service.d

└─migrated-from-my.cnf-settings.conf

Active: active (running) since 五 2017-10-20 04:29:18 CST; 5s ago

Process: 12354 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited,status=0/SUCCESS)

Process: 12313 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-environment _WSREP_START_POSITION=$VAR || exit 1 (code=exited,status=0/SUCCESS)

Process: 12305 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited,status=0/SUCCESS)

Main PID: 12327 (mysqld)

Status: "Taking your SQL requests now..."

CGroup: /system.slice/mariadb.service

└─12327 /usr/sbin/mysqld


10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: 2017-10-20 4:29:18...

10月 20 04:29:18 localhost mysqld[12327]: Version: '10.1.19-M...

10月 20 04:29:18 localhost systemd[1]: Started MariaDB databa...

Hint: Some lines were ellipsized,use -l to show in full.


3、防火墙允许80端口通过

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=http

success

[root@localhost ~]# firewall-cmd --permanent --zone=public --add-service=https

success

[root@localhost ~]# firewall-cmd --reload

success


4、检查80端口是否被监听

[root@localhost ~]# netstat -tulp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name

tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1061/sshd

tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN 1813/master

tcp6 0 0 [::]:mysql [::]:* LISTEN 12327/mysqld

tcp6 0 0 [::]:http [::]:* LISTEN 12304/httpd

tcp6 0 0 [::]:ssh [::]:* LISTEN 1061/sshd

tcp6 0 0 localhost:smtp [::]:* LISTEN 1813/master


5、使用浏览器测试是否能够访问到Apache服务

浏览器中输入IP地址即可:http://10.0.0.11/

044102275281e3383f85ee5ce362c45c.png

返回以上内容证明Apache已经搭建成功


6、初始化数据库

[root@localhost ~]# mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!


In order to log into MariaDB to secure it,we'll need the current

password for the root user. If you've just installed MariaDB,and

you haven't set the root password yet,the password will be blank,

so you should just press enter here.


Enter current password for root (enter for none):

OK,successfully used password,moving on...


Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.


Set root password? [Y/n] y

New password:

Re-enter new password:

Password updated successfully!

Reloading privilege tables..

... Success!



By default,a MariaDB installation has an anonymous user,allowing anyone

to log into MariaDB without having to have a user account created for

them. This is intended only for testing,and to make the installation

go a bit smoother. You should remove them before moving into a

production environment.


Remove anonymous users? [Y/n] y

... Success!


Normally,root should only be allowed to connect from 'localhost'. This

ensures that someone cannot guess at the root password from the network.


Disallow root login remotely? [Y/n] y

... Success!


By default,MariaDB comes with a database named 'test' that anyone can

access. This is also intended only for testing,and should be removed

before moving into a production environment.


Remove test database and access to it? [Y/n] y

- Dropping test database...

... Success!

- Removing privileges on test database...

... Success!


Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.


Reload privilege tables now? [Y/n] y

... Success!


Cleaning up...


All done! If you've completed all of the above steps,your MariaDB

installation should now be secure.


Thanks for using MariaDB!

注:这里设置的数据库密码是devops


进入数据库并查看

[root@localhost ~]# mysql -u root -p

Enter password:

Welcome to the MariaDB monitor. Commands end with ; or g.

Your MariaDB connection id is 10

Server version: 10.1.19-MariaDB MariaDB Server


Copyright (c) 2000,2016,Oracle,MariaDB Corporation Ab and others.


Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.


MariaDB [(none)]> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

+--------------------+

3 rows in set (0.00 sec)


MariaDB [(none)]> use mysql;

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A


Database changed

MariaDB [mysql]> show tables;

+---------------------------+

| Tables_in_mysql |

+---------------------------+

| column_stats |

| columns_priv |

| db |

| event |

| func |

| general_log |

| gtid_slave_pos |

| help_category |

| help_keyword |

| help_relation |

| help_topic |

| host |

| index_stats |

| innodb_index_stats |

| innodb_table_stats |

| plugin |

| proc |

| procs_priv |

| proxies_priv |

| roles_mapping |

| servers |

| slow_log |

| table_stats |

| tables_priv |

| time_zone |

| time_zone_leap_second |

| time_zone_name |

| time_zone_transition |

| time_zone_transition_type |

| user |

+---------------------------+

30 rows in set (0.01 sec)


exit;退出数据库



7、更新Yum源并安装PHP7.0.24

rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


使用Yum安装PHP7.0.24

yum install php70w php70w-common php70w-fpm php70w-opcache php70w-gd php70w-mysqlnd php70w-mbstring php70w-pecl-redis php70w-pecl-memcached php70w-devel -y


就这一条命令,就可以安装了下面的拓展了!

php-api,php-bz2,php-calendar,php-ctype,php-curl,php-date,php-exif,php-fileinfo,php-filter,php-ftp,php-gettext,php-gmp,php-hash,php-iconv,php-json,php-libxml,php-openssl,php-pcre,php-pecl-Fileinfo,php-pecl-phar,php-pecl-zip,php-reflection,php-session,php-shmop,php-simplexml,php-sockets,php-spl,php-tokenizer,php-zend-abi,php-zip,php-zlib

激动吧?别急,还有更牛的!使用Yum即可安装需要的扩展

安装包 提供的拓展

php70w mod_php,php70w-zts

php70w-bcmath

php70w-cli php-cgi,php-pcntl,php-readline

php70w-common php-api,php-zlib

php70w-dba

php70w-devel

php70w-embedded php-embedded-devel

php70w-enchant

php70w-fpm

php70w-gd

php70w-imap

php70w-interbase php_database,php-firebird

php70w-intl

php70w-ldap

php70w-mbstring

php70w-mcrypt

php70w-mysql php-mysqli,php_database

php70w-mysqlnd php-mysqli,php_database

php70w-odbc php-pdo_odbc,php_database

php70w-opcache php70w-pecl-zendopcache

php70w-pdo php70w-pdo_sqlite,php70w-sqlite3

php70w-pdo_dblib php70w-mssql

php70w-pear

php70w-pecl-apcu

php70w-pecl-imagick

php70w-pecl-memcached

php70w-pecl-mongodb

php70w-pecl-redis

php70w-pecl-xdebug

php70w-pgsql php-pdo_pgsql,php_database

php70w-phpdbg

php70w-process php-posix,php-sysvmsg,php-sysvsem,php-sysvshm

php70w-pspell

php70w-recode

php70w-snmp

php70w-soap

php70w-tidy

php70w-xml php-dom,php-domxml,php-wddx,php-xsl

php70w-xmlrpc


例如需要安装xml扩展

yum install php70w-xml


8、检验

检验PHP版本

[root@localhost ~]# php -v

PHP 7.0.24 (cli) (built: Sep 30 2017 10:10:28) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0,Copyright (c) 1998-2017 Zend Technologies

with Zend OPcache v7.0.24,Copyright (c) 1999-2017,by Zend Technologies


检验PHP扩展

[root@localhost ~]# php -m

[PHP Modules]

bz2

calendar

Core

ctype

curl

date

dom

exif

fileinfo

filter

ftp

gd

gettext

gmp

hash

iconv

igbinary

json

libxml

mbstring

memcached

mysqli

mysqlnd

openssl

pcntl

pcre

PDO

pdo_mysql

pdo_sqlite

Phar

posix

readline

redis

Reflection

session

shmop

SimpleXML

sockets

SPL

sqlite3

standard

sysvmsg

sysvsem

sysvshm

tokenizer

wddx

xml

xmlreader

xmlwriter

xsl

Zend OPcache

zip

zlib


[Zend Modules]

Zend OPcache



9、重启Apache并测试

在/var/www/html/创建index.php文件

[root@localhost ~]# cat /var/www/html/index.php

phpinfo();

?>


浏览器中输入http://10.0.0.11/

25bd091bf367590e1086e9711fb2ef46.png

搭建成功!!


参考文档:

http://blog.csdn.net/zhezhebie/article/details/73325663

http://www.cnblogs.com/me80/p/7218883.html


小弟入行不久,有不对的地方还请大家指出

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读