美文网首页
centos7.3配置LAMP BY yum

centos7.3配置LAMP BY yum

作者: hello大象 | 来源:发表于2017-12-04 19:09 被阅读0次

    实验环境:

    [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


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


    查看服务状态
    防火墙设置开启80端口

    确认80端口监听中、查服务器IP

    浏览器登陆

    2、安装mysql
    yum install mariadb mariadb-server mariadb-libs mariadb-devel

    开启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
    

    数据库安全设置,(数据库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!
    

    登陆数据库测试:


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

    image.png

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


    安装常用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:


    image.png

    重启apache服务器

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

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


    完毕!
    //配置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  
    

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

    <VirtualHost 192.168.0.250:80>  
    #绑定的主域  
    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  
    </VirtualHost>  
    #网站的配置  
    <Directory "/var/www/www.bookstore.com/">  
        Options FollowSymLinks  
        AllowOverride All  
        Require all granted  
    </Directory>  
    
    <VirtualHost *:80>  
    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   
    </VirtualHost>  
    <Directory "/var/www/shop1024/shop">  
        Options FollowSymLinks  
        AllowOverride All  
        Require all granted  
    </Directory>  
    

    可添加多个:


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


    以上两步完成配置。

    相关文章

      网友评论

          本文标题:centos7.3配置LAMP BY yum

          本文链接:https://www.haomeiwen.com/subject/eqtfixtx.html