1. 程式人生 > >CentOS 7 一步一步搭建LAMP

CentOS 7 一步一步搭建LAMP

centos7 lamp

一、準備環境

1、系統版本

[[email protected] ~]# cat /proc/version

Linux version 3.10.0-514.16.1.el7.x86_64

2、關防火墻

[[email protected] ~]# systemctl disable firewalld

3、準備yum源

[[email protected] ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

[[email protected]
*/ ~]# rpm -ivh http://mirrors.aliyun.com/epel/epel-release-latest-7.noarch.rpm

4、安裝基礎工具

[[email protected] ~]# yum install -y net-tools vim lrzsz tree screen lsof tcpdump nc nmap

5、關掉SELINUX

[[email protected] ~]# vim /etc/sysconfig/selinux 
SELINUX=disabled

6、更新並重啟

[[email protected] ~]# yum update -y && reboot

二、開始安裝LAMP組建


LAMP至少需要以下組建:

  • httpd (提供 Apache 主程序)

  • mysql (MySQL 客戶端程序)

  • mysql-server (MySQL 服務器程序)

  • php (PHP 主程序含給 apache 使用的模塊)

  • php-devel (PHP 的開發工具,這個與PHP 外掛的加速軟件有關)

  • php-mysql (提供給PHP 程序讀取 MySQL 資料庫的模塊)

可以用以下命令一次安裝;

[[email protected] ~]# yum install httpd mysql mysql-server php php-mysql

為了看的更詳細,我們一個一個安裝

1、利用yum命令安裝Apache

[[email protected] ~]# yum -y install httpd

啟動httpd並且設置為開機啟動

[[email protected] ~]# systemctl start httpd.service
[[email protected] ~]# systemctl enable httpd.service

輸入網址,查看測試頁


技術分享


2、安裝Mariadb

利用yum命令進行安裝,並且配置開機啟動同樣還是利用yum命令進行安裝,並且配置開機啟動

[[email protected] ~]# yum -y install mariadb-server mariadb
[[email protected] ~]# systemctl start mariadb.service
[[email protected] ~]# systemctl enable mariadb.service

配置root密碼

[[email protected] ~]# mysql_secure_installation
安裝過程中會有幾個選項,大家根據自己的需要進行配置就好了
Enter current password for root (enter for none):(輸入原始root密碼,若無enter)
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] (是否設置root密碼)
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
Remove anonymous users? [Y/n] (是否移除匿名用戶)
 ... Success!
Disallow root login remotely? [Y/n] (是否禁止遠程root登陸)
 ... skipping.
Remove test database and access to it? [Y/n] (是否刪除測試數據庫)
Reload privilege tables now? [Y/n] (重新載入)
 ... 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!

登錄數據庫測試一下

[[email protected] ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.52-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)]> exit
Bye

3、安裝PHP

[[email protected] ~]# yum -y install php

安裝所需組件

[[email protected] ~]# yum -y install php-mysql php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel

啟動服務並設置開機自動啟動

[[email protected] ~]# systemctl start httpd.service
[[email protected] ~]# systemctl enable httpd.service

查看80端口和3306端口是否處於監聽狀態:

[[email protected] ~]# netstat -ntlp


測試php是否正常工作

編輯/etc/httpd/conf/httpd.conf文件,在DirectoryIndex後面填寫index.php,定義默認主頁為index.php

[[email protected] ~]# vim /etc/httpd/conf/httpd.conf

技術分享

重載httpd配置文件

[[email protected] ~]# systemctl reload httpd.service
[[email protected] ~]# vim /var/www/html/index.php

制作默認主頁/var/www/html/index.php,編寫如下內容

<h1>This is new Web !</h1>
       <?php
              phpinfo();
       ?>

重啟httpd服務

[[email protected] ~]# systemctl restart httpd.service

好了,該驗證最後是否成功了

打開網址 http://x.x.x.x/info.php 進行查看

技術分享



看到這個頁面,我們就可以收工了,LAMP環境搭建結束!



本文出自 “樂成的技術筆記” 博客,請務必保留此出處http://yueyuanyuan.blog.51cto.com/1342062/1928357

CentOS 7 一步一步搭建LAMP