1. 程式人生 > >Yum安裝LAMP(Centos7.2+Apache2.4+Mariadb5.5.56+PHP7.0.24)

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

apache php

一、簡介

最近客戶提出需要使用PHP7的需求,第一次是給客戶安裝的是LNMP-full的集成環境,但是後面不便於添加擴展模塊,以及本人對Nginx不是很了解,經協商後改用LAMP,以下內容為真實環境搭建完成後為了方便記憶在虛擬環境中的配置,和真是環境基本一樣


二、準備環境

操作系統IP地址相關軟件包
Centos7.210.0.0.11php70w-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/

技術分享

返回以上內容證明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-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

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

<?php

phpinfo();

?>


瀏覽器中輸入http://10.0.0.11/

技術分享

搭建成功!!


參考文檔:

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

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


小弟入行不久,有不對的地方還請大家指出

本文出自 “linux” 博客,請務必保留此出處http://bella41981.blog.51cto.com/10603572/1974427

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