LAMP網(wǎng)站架構(gòu)是目前國際流行的 Web 框架,該框架包括:Linux 操作系統(tǒng),Apache 網(wǎng)絡服務器,MySQL 數(shù)據(jù)庫,所有組成產(chǎn)品均是開源軟件,是國際上成熟的架構(gòu)框架。
最近我在百度智能云上購買了一個服務器,需要搭建PHP網(wǎng)站運行環(huán)境(LAMP——Linux、Apache、MySQL、PHP)?,F(xiàn)在,將搭建過程和遇到的問題記錄一下,方便以后查看。本次搭建使用的是Linux系統(tǒng)的CentOS6版本和CentOS7版本,兩個版本有什么不同將在安裝各個軟件詳細說明。


1、概述
服務器配置和操作系統(tǒng):
服務器配置:1核CPU1G內(nèi)存1Mbps帶寬40G系統(tǒng)盤
操作系統(tǒng):CentOS / 7.2 x86_64 (64bit)
這次搭建所使用的系統(tǒng)是Linux系統(tǒng),安裝的軟件版本如下:
Apache: 2.4.6-88.el7.centos
MySQL:5.6.43 MySQL Community Server (GPL)
PHP:PHP 5.6.40 (cli)
2、安裝Apache
為了方便起見,Linux系統(tǒng)中有默認的Apache版本,就不需要進行安裝,只要啟動Apache服務即可。
CentOS6版本默認的Apache版本:Apache2.2
CentOS7版本默認的Apache版本:Apache2.4
CentOS6下Apache啟動、停止、重啟
啟動服務:service httpd start
停止服務:service httpd stop
重新啟動:service httpd restart
CentOS7下Apache啟動、停止、重啟
啟動服務:/bin/systemctl start httpd.service
停止服務:/bin/systemctl stop httpd.service
重新啟動:/bin/systemctl restart httpd.service
設為開機啟動
chkconfig httpd on
檢查是否安裝Apache
rpm -qa | grep httpd
3、安裝Mysql
安裝版本:5.6.43 MySQL Community Server (GPL)
(1)、檢查系統(tǒng)是否已安裝
yum list installed | grep mysql
(2)、如果發(fā)現(xiàn)有系統(tǒng)已安裝,使用如下命令進行刪除
yum -y remove 安裝包名
(3)、下載mysql-community-release-el6-5.noarch.rpm包
wget http://repo.mysql.com/mysql-community-release-el6-5.noarch.rpm
(4)、執(zhí)行mysql-community-release-el6-5.noarch.rpm包,獲取mysql-community-source.repo和mysql-community.repo
rpm -ivh mysql-community-release-el6-5.noarch.rpm
(5)、用yum repolist mysql這個命令查看一下是否已經(jīng)有mysql可安裝文件
yum repolist all | grep mysql
(6)、安裝mysql 服務器命令(一路yes)
yum install mysql-community-server
(7)、設置密碼
mysql -u root
use mysql;
update user set password=PASSWORD("這里輸入root用戶密碼") where User='root';
flush privileges;
(8)、設置開機啟動
chkconfig --list | grep mysqld
chkconfig mysqld on
4、安裝PHP
(1)、配置yum源
CentOS 6.5的epel及remi源:
rpm -Uvh http://ftp.iij.ad.jp/pub/linux/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
CentOS 7的epel及remi源:
yum install epel-release
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
使用yum list命令查看可安裝的包(Packege)
yum list --enablerepo=remi --enablerepo=remi-php56 | grep php
(2)、安裝PHP5.6
yum源配置好了,下一步就安裝PHP5.6,執(zhí)行下面命令一路yes即可。
yum install --enablerepo=remi --enablerepo=remi-php56 php php-opcache php-devel php-mbstring php-mcrypt php-mysqlnd php-phpunit-PHPUnit php-pecl-xdebug php-pecl-xhprof
查看PHP版本
php --version