摘自:https://help.aliyun.com/document_detail/50774.html?spm=5176.doc44620.6.623.HqVrszphp
更新時間:2017-03-14 11:22:11html
LAMP指Linux+Apache+Mysql/MariaDB+Perl/PHP/Python是一組經常使用來搭建動態網站或者服務器的開源軟件,自己都是各自獨立的程序,可是由於常被放在一塊兒使用,擁有了愈來愈高的兼容度,共同組成了一個強大的Web應用程序平臺。node
系統平臺:CentOS 7.2mysql
Apache版本:2.4.23linux
Mysql 版本:5.7.17sql
Php版本:7.0.12數據庫
CentOS 7.2系統默認開啓了防火牆,需關閉後外部纔可訪問本機的80、21等端口。apache
關閉防火牆:vim
systemctl stop firewalld.service
瀏覽器
關閉防火牆開機自啓動:
systemctl disable firewalld.service
安裝vim及unzip:
yum install -y vim unzip
編譯安裝apache前須要安裝apr、apr-util和pcre軟件包和相關依賴包。
安裝編譯環境
yum install -y gcc gcc-c++ autoconf libtool
cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-1.5.0.tar.gz
tar zxvf apr-1.5.0.tar.gz
cd apr-1.5.0
./configure --prefix=/usr/local/apr #安裝目錄
make && make install
cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/apache/apr-util-1.5.3.tar.gz
tar zxvf apr-util-1.5.3.tar.gz
cd apr-util-1.5.3
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr #安裝目錄 及apr安裝路徑
make && make install
cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/pcre/pcre-8.38.tar.gz
tar zxvf pcre-8.38.tar.gz
cd pcre-8.38
./configure --prefix=/usr/local/pcre #安裝目錄
make && make install
cd /usr/local/src/
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/apache/httpd-2.4.23.tar.gz
tar zxvf httpd-2.4.23.tar.gz
cd httpd-2.4.23
./configure \
--prefix=/usr/local/apache --sysconfdir=/etc/httpd \ #安裝目錄及配置文件所在目錄
--enable-so --enable-cgi --enable-rewrite \
--with-zlib --with-pcre=/usr/local/pcre \ #pcre所在目錄
--with-apr=/usr/local/apr \ #apr所在目錄
--with-apr-util=/usr/local/apr-util \ #apr-util所在目錄
--enable-mods-shared=most --enable-mpms-shared=all \
--with-mpm=event
make && make install
cd /etc/httpd/
vim httpd.conf
1.找到Directory參數,註釋掉Require all denied添加Require all granted。
2.找到ServerName參數,添加ServerName localhost:80 而後,按Esc鍵後輸入:wq保存退出。
vim /etc/httpd/httpd.conf
在配置文件最後添加如下內容:
PidFile "/var/run/httpd.pid"
cd /usr/local/apache/bin/
./apachectl start
netstat -tnlp #查看服務是否開啓
在本地瀏覽器中輸入雲服務器的公網IP地址驗證,出現下圖表示安裝成功。
在rc.local文件中添加/usr/local/apache/bin/apachectl start,而後輸入:wq保存退出。
vim /etc/rc.d/rc.local
vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加參數爲:
PATH=$PATH:$HOME/bin:/usr/local/apache/bin
而後輸入:wq保存退出,執行:
source /root/.bash_profile
首先檢查系統中是否存在使用rpm安裝的mysql或者mariadb,若是有須要先刪除後再編譯安裝。
rpm -qa | grep mysql #由下至上依次卸載
rpm -qa | grep mariadb
rpm -e xxx #通常使用此命令便可卸載成功
rpm -e --nodeps xxx #卸載不成功時使用此命令強制卸載
卸載完之後用 rpm -qa|grep mariadb 或者 rpm -qa|grep mysql 查看結果。
yum install -y libaio-* #安裝依賴
mkdir -p /usr/local/mysql
cd /usr/local/src
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/mysql/mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
tar -xzvf mysql-5.7.17-linux-glibc2.5-x86_64.tar.gz
mv mysql-5.7.17-linux-glibc2.5-x86_64/* /usr/local/mysql/
groupadd mysql
useradd -g mysql -s /sbin/nologin mysql
/usr/local/mysql/bin/mysqld --initialize-insecure --datadir=/usr/local/mysql/data/ --user=mysql
chown -R mysql:mysql /usr/local/mysql
chown -R mysql:mysql /usr/local/mysql/data/
chown -R mysql:mysql /usr/local/mysql
cd /usr/local/mysql/support-files/
cp mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld # 添加執行權限
vim /etc/rc.d/rc.local
添加/etc/init.d/mysqld start到rc.local文件中,而後輸入:wq保存退出。
vi /root/.bash_profile
在PATH=$PATH:$HOME/bin添加參數爲:
PATH=$PATH:$HOME/bin:/usr/local/mysql/bin:/usr/local/mysql/lib
而後輸入:wq保存退出,輸入:
source /root/.bash_profile
/etc/init.d/mysqld start
初始化後mysql爲空密碼可直接登陸,爲了保證安全性須要修改mysql的root用戶密碼。
mysqladmin -u root password 'xxxx'
mysql -uroot -p密碼 #-p和密碼之間無空格
依賴安裝:
yum install php-mcrypt libmcrypt libmcrypt-devel libxml2-devel openssl-devel libcurl-devel libjpeg.x86_64 libpng.x86_64 freetype.x86_64 libjpeg-devel.x86_64 libpng-devel.x86_64 freetype-devel.x86_64 libjpeg-turbo-devel libmcrypt-devel mysql-devel -y
wget http://zy-res.oss-cn-hangzhou.aliyuncs.com/php/php-7.0.12.tar.gz
tar zxvf php-7.0.12.tar.gz
cd php-7.0.12
./configure \
--prefix=/usr/local/php \
--with-mysql=mysqlnd --with-openssl \
--with-mysqli=mysqlnd \
--enable-mbstring \
--with-freetype-dir \
--with-jpeg-dir \
--with-png-dir \
--with-zlib --with-libxml-dir=/usr \
--enable-xml --enable-sockets \
--with-apxs2=/usr/local/apache/bin/apxs \
--with-mcrypt --with-config-file-path=/etc \
--with-config-file-scan-dir=/etc/php.d \
--enable-maintainer-zts \
--disable-fileinfo
make && make install
cd php-7.0.12
cp php.ini-production /etc/php.ini
vim /etc/httpd/httpd.conf
在配置文件最後添加以下二行:
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
定位到 DirectoryIndex index.html
修改成:
DirectoryIndex index.php index.html
/usr/local/apache/bin/apachectl restart
cd /usr/local/apache/htdocs/
vim index.php #添加以下內容
<?php
phpinfo();
?>
訪問雲服務器的公網IP/index.php,出現以下頁面表示解析成功。
mkdir -p /usr/local/apache/htdocs/phpmyadmin
cd /usr/local/src/
wget http://oss.aliyuncs.com/aliyunecs/onekey/phpMyAdmin-4.1.8-all-languages.zip
unzip phpMyAdmin-4.1.8-all-languages.zip
mv phpMyAdmin-4.1.8-all-languages/* /usr/local/apache/htdocs/phpmyadmin
訪問ip/phpmyadmin便可訪問到phpmyadmin登陸頁面,輸入mysql的用戶名以及密碼便可登陸。