Centos7搭建LAMP環境

準備php

    1. 關閉SELinuxmysql

臨時:切換到root用戶,並執行命令:linux

setenforce 0    # 0表示關閉,1表示開啓

永久:經過修改配置文件
sql

    vi /etc/selinux/config
    #SELINUX=enforcing #註釋掉
    #SELINUXTYPE=targeted #註釋掉
    SELINUX=disabled #增長
    :wq!#保存退出
    shutdown -r now#重啓系統shell


    2.  Apache安裝c#

yum install httpd # 可添加參數-y,表示贊成安裝

經過命令來啓動/關閉/重啓等服務:工具

service httpd start|stop|restart 或
systemctl start httpd #Centos7特有

經過以下命令查看版本:post

httpd -v

經過以下命令設爲開機啓動:rest

systemctl enable httpd.service    #設置開機啓動
systemctl is-enabled httpd.service  #查看是否開機啓動
systemctl disable httpd.service  #取消開機啓動

    操做後,需重啓服務code

    3. Mysql安裝

因爲Centos7默認支持Mariadb(Mysql分支,其餘操做或配置相同),因此安裝命令參考:

yum  install mariadb* # 安裝Mariadb服務及其相關

 經過以下命令開機啓動:

#參考Apache
systemctl enable mariadb.service    #設置開機啓動

啓動/中止/重啓服務:

service mariadb start|stop|restart 或
systemctl start mariadb #Centos7特有

設置root用戶密碼:Mysql版本5.5.47

mysql_secure_installation

根據提示操做便可。其餘版本,請另行參考。

最後重啓服務。

    3. PHP安裝

    經過yum命令直接安裝

yum install php  #直接添加-y參數,或根據提示輸入Y直到安裝完成

    安裝php擴展

yum install php-mysql php-gd libjpeg* php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
php-mbstring php-mcrypt php-bcmath php-mhash libmcrypt 
#這裏選擇以上安裝包進行安裝,根據提示輸入Y回車

安裝結束後,重啓Apache和Mariadb服務。

systemctl restart httpd 
systemctl restart mariadb

 

補充:

CentOS使用systemd服務管理程序來管理服務一、systemd的服務管理程序介紹:systemctl是主要的工具,它融合以前service和chkconfig的功能於一體。能夠使用它永久性或只在當前會話中啓用/禁用服務。systemctl能夠列出正在運行的服務狀態:systemd-cgls以樹形列出正在運行的進程,它能夠遞歸顯示控制組內容。二、啓動/關閉、啓用/禁用服務啓動一個服務:systemctl start postfix.service關閉一個服務:systemctl stop postfix.service重啓一個服務:systemctl restart postfix.service顯示一個服務的狀態:systemctl status postfix.service在開機時啓用一個服務:systemctl enable postfix.service在開機時禁用一個服務:systemctl disable postfix.service查看服務是否開機啓動:systemctl is-enabled postfix.service;echo $?查看已啓動的服務列表:systemctl list-unit-files|grep enabled

相關文章
相關標籤/搜索