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

前端之家收集整理的这篇文章主要介绍了Yum安装LAMP(Centos7.2+Apache2.4+Mariadb5.5.56+PHP7.0.24)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

一、简介

最近客户提出需要使用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


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

猜你在找的Bash相关文章