centos7.3配置LAMP BY yum

实验环境:

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.3.1611 (Core) 
yum install httpd httpd-devel
[root@localhost ~]# systemctl start httpd
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
[root@localhost ~]# systemctl status httpd


1、安装apache


centos7.3配置LAMP BY yum_第1张图片

启动apache服务、设置httpd服务开机启动、


查看服务状态
centos7.3配置LAMP BY yum_第2张图片

防火墙设置开启80端口
centos7.3配置LAMP BY yum_第3张图片

确认80端口监听中、查服务器IP
centos7.3配置LAMP BY yum_第4张图片

浏览器登陆
centos7.3配置LAMP BY yum_第5张图片

2、安装mysql
yum install mariadb mariadb-server mariadb-libs mariadb-devel
centos7.3配置LAMP BY yum_第6张图片

开启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
centos7.3配置LAMP BY yum_第7张图片

centos7.3配置LAMP BY yum_第8张图片

数据库安全设置,(数据库root初始密码为空)

[root@VM_82_192_centos ~]#  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): 
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!

登陆数据库测试:


centos7.3配置LAMP BY yum_第9张图片

3、安装PHP
[root@VM_82_192_centos ~]# yum -y install php

centos7.3配置LAMP BY yum_第10张图片
image.png

将php与mysql关联起来
[root@VM_82_192_centos ~]# yum install php-mysql -y

centos7.3配置LAMP BY yum_第11张图片

安装常用PHP模块

[root@VM_82_192_centos ~]# 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

测试PHP:


centos7.3配置LAMP BY yum_第12张图片
image.png

重启apache服务器

[root@VM_82_192_centos html]# systemctl restart httpd.service 

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

centos7.3配置LAMP BY yum_第13张图片

完毕! 源

//配置Apache的虚拟主机  
#vim /etc/httpd/conf/httpd.conf  
//找到index.html,在index.html后面加上index.php(注意空格隔开)  
  
//在/etc/httpd/conf.d/目录下新建一个conf文件,用该文件来配置虚拟主机  
#vim /etc/httpd/conf.d/vhost.conf  

//内容如下:
#虚拟主机配置文件

  
#绑定的主域  
ServerName bookstore.com  

#绑定的子域名  
ServerAlias www.bookstore.com  

#网站主目录  
DocumentRoot /var/www/www.bookstore.com/  

#日志路径配置(如果没有,请记得创建)  
ErrorLog /var/www/web_log/error_bookstore.com.log  
CustomLog /var/www/web_log/custom_bookstore.com.log common  

#ServerSignature Off  
  
#网站的配置  
  
    Options FollowSymLinks  
    AllowOverride All  
    Require all granted  
  
  
ServerName shop1024.vipelephant.cn  
DocumentRoot /var/www/shop1024/shop
ErrorLog /var/www/error_shop1024.vipelephant.cn.log  
CustomLog /var/www/custom_shop1024.vipelephant.cn.log common   
  
  
    Options FollowSymLinks  
    AllowOverride All  
    Require all granted  
  

可添加多个:


centos7.3配置LAMP BY yum_第14张图片

若以上不成功,再修改:hosts文件,注意备份。
[root@VM_82_192_centos shop]# vi /etc/hosts


以上两步完成配置。

你可能感兴趣的:(centos7.3配置LAMP BY yum)