您的位置 首页 php

没有我教不会的学生,centos7用yum搭建LAMP教程

实验环境:

[ root @ localhost ~]# cat /etc/redhat-release

CentOS Linux release 7.5.1804 (Core)

[root@localhost ~]# uname -a

Linux localhost.localdomain 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

1、安装 apache

1.1安装apache

[root@localhost ~]# yum install httpd httpd-devel

1.2启动apache服务

[root@localhost ~]# systemctl start httpd

1.3设置httpd服务开机启动

[root@localhost ~]# systemctl enable httpd

1.4查看服务状态

[root@localhost ~]# systemctl status httpd

● httpd. service – The Apache HTTP Server

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

Active : active (running) since 五 2018-07-13 10:02:03 CST; 2min 37s ago

Docs: man:httpd(8)

man:apachectl(8)

Main PID: 2159 (httpd)

Status: “Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec”

CGroup: /system.slice/httpd.service

├─2159 /usr/sbin/httpd -DFOREGROUND

├─2161 /usr/sbin/httpd -DFOREGROUND

├─2162 /usr/sbin/httpd -DFOREGROUND

├─2163 /usr/sbin/httpd -DFOREGROUND

├─2164 /usr/sbin/httpd -DFOREGROUND

└─2165 /usr/sbin/httpd -DFOREGROUND

7月 13 10:02:03 localhost.localdomain systemd[1]: Starting The Apache HTTP Server…

7月 13 10:02:03 localhost.localdomain httpd[2159]: AH00558: httpd: Could not reliably d…ge

7月 13 10:02:03 localhost.localdomain systemd[1]: Started The Apache HTTP Server.

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

[root@localhost ~]#

1.5防火墙开启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

1.6确认80端口监听中

[root@localhost ~]# netstat -tulp

[root@localhost ~]# yum -y install net-tools

[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 999/sshd

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

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

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

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

udp 0 0 localhost:323 0.0.0.0:* 631/chronyd

udp 0 0 0.0.0.0:bootpc 0.0.0.0:* 800/dhclient

udp6 0 0 localhost:323 [::]:* 631/chronyd

1.8 查服务器IP

[root@localhost ~]# ip addr

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000

link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00

inet 127.0.0.1/8 scope host lo

valid_lft forever preferred_lft forever

inet6 ::1/128 scope host

valid_lft forever preferred_lft forever

2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

link/ether 00:0c:29:41:80:73 brd ff:ff:ff:ff:ff:ff

inet 192.168.85.139/24 brd 192.168.85.255 scope global noprefixroute dynamic ens33

valid_lft 1632sec preferred_lft 1632sec

inet6 fe80::55c:5495:cdff:d09d/64 scope link noprefixroute

valid_lft forever preferred_lft forever

1.9 浏览器登陆,输入ip

apache

2、安装mysql

2.1安装mysql

[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel

已加载插件:fastestmirror, priorities

Loading mirror speeds from cached hostfile

* base: mirrors.cn99.com

* extras: mirrors.cn99.com

* updates: mirrors.huaweicloud.com

软件包 1: mariadb -5.5.56-2.el7.x86_64 已安装并且是最新版本

软件包 1:mariadb-server-5.5.56-2.el7.x86_64 已安装并且是最新版本

软件包 1:mariadb-libs-5.5.56-2.el7.x86_64 已安装并且是最新版本

软件包 1:mariadb-devel-5.5.56-2.el7.x86_64 已安装并且是最新版本

无须任何处理

[root@localhost ~]# rpm -qa |grep maria

mariadb-server-5.5.56-2.el7.x86_64

mariadb-5.5.56-2.el7.x86_64

mariadb-devel-5.5.56-2.el7.x86_64

mariadb-libs-5.5.56-2.el7.x86_64

2.2 开启mysql服务,并设置开机启动,检查mysql状态

[root@localhost ~]# systemctl start mariadb

[root@localhost ~]# systemctl enable mariadb

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

[root@localhost ~]# systemctl status mariadb

● mariadb.service – MariaDB database server

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

Active: active (running) since 五 2018-07-13 09:49:49 CST; 12s ago

Main PID: 1684 (mysqld_safe)

CGroup: /system.slice/mariadb.service

├─1684 /bin/sh /usr/bin/mysqld_safe –basedir=/usr

└─1846 /usr/libexec/mysqld –basedir=/usr –datadir=/ var /lib/mysql –plugin-dir…

7月 13 09:49:45 localhost.localdomain mariadb-prepare-db-dir[1606]: MySQL manual for more…

7月 13 09:49:45 localhost.localdomain mariadb-prepare-db-dir[1606]: Please report any pro…

7月 13 09:49:45 localhost.localdomain mariadb-prepare-db-dir[1606]: The latest informatio…

7月 13 09:49:46 localhost.localdomain mariadb-prepare-db-dir[1606]: You can find addition…

7月 13 09:49:46 localhost.localdomain mariadb-prepare-db-dir[1606]:

7月 13 09:49:46 localhost.localdomain mariadb-prepare-db-dir[1606]: Consider jo ini ng Mari…

7月 13 09:49:46 localhost.localdomain mariadb-prepare-db-dir[1606]:

7月 13 09:49:46 localhost.localdomain mysqld_safe[1684]: 180713 09:49:46 mysqld_safe Log….

7月 13 09:49:46 localhost.localdomain mysqld_safe[1684]: 180713 09:49:46 mysqld_safe Sta…l

7月 13 09:49:49 localhost.localdomain systemd[1]: Started MariaDB database server.

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

[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:mysql 0.0.0.0:* LISTEN 1846/mysqld

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

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

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

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

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

udp 0 0 localhost:323 0.0.0.0:* 631/chronyd

udp 0 0 0.0.0.0:bootpc 0.0.0.0:* 800/dhclient

udp6 0 0 localhost:323 [::]:* 631/chronyd

2.3 数据库安全设置

[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): *直接回车

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

Enter current password for root (enter for none):

ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

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] n

… skipping.

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!

2.4 登陆数据库测试

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

Enter password: #输入刚刚设置的密码

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

Your MariaDB connection id is 11

Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, 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)]> exit;

Bye

3、安装PHP

3.1 安装php

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

[root@localhost ~]# rpm -ql php

/etc/httpd/conf.d/php.conf

/etc/httpd/conf. modules .d/10-php.conf

/usr/lib64/httpd/modules/libphp5.so

/usr/share/httpd/icons/php.gif

/var/lib/php/session

3.2 将php与mysql关联起来

[root@localhost ~]# yum install php-mysql

[root@localhost ~]# rpm -ql php-mysql

/etc/php.d/mysql.ini

/etc/php.d/ mysqli .ini

/etc/php.d/pdo_mysql.ini

/usr/lib64/php/modules/mysql.so

/usr/lib64/php/modules/mysqli.so

/usr/lib64/php/modules/pdo_mysql.so

3.3 安装常用PHP模块

[root@localhost ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

3.4 测试PHP

[root@localhost ~]# cd /var/www/html/

[root@localhost html]# ls

[root@localhost html]# pwd

/var/www/html

[root@localhost html]# vi info.php

<?php

phpinfo();

?>

~

~

~

~

~

~

~

~

:wq

3.5重启apache服务器

[root@localhost html]# systemctl restart httpd

3.6测试PHP

在自己电脑浏览器输入 ip/info.php ,你可以看到已经安装的模块

info.php

3.7编写一个网页脚本,打开网页

[root@localhost html]# vi index.php

[root@localhost html]# cat index.php

<html><body><h1>League of Legends</h1></body></html>

index.php

文章来源:智云一二三科技

文章标题:没有我教不会的学生,centos7用yum搭建LAMP教程

文章地址:https://www.zhihuclub.com/152559.shtml

关于作者: 智云科技

热门文章

网站地图