在CentOS 7.x(Apache,PHP 7.x,SQL MariaDB 10.x,phpMyAdmin)2017上安裝LAMP
本指南介紹如何在CentOS 7系統上安裝LAMP(Linux,Apache,MySQL,PHP)堆棧。在本教程中,我將向您展示如何安裝最新版本的php(PHP 7.1),MySQL(MariaDB 10.1),phpMyAdmin(4.6.6)和Apache。本安裝指南僅適用於CentOS 7.x。
LAMP是Web服務堆棧的原型模型,被稱為原始四個開源組件的名稱的縮寫:Linux操作系統,Apache HTTP Server,MySQL關係數據庫管理系統(RDBMS)和PHP編程語言。LAMP組件在很大程度上是可互換的,不限於原始選擇。作為解決方案堆棧,LAMP適用於構建動態網站和Web應用程序。
服務器更新
1.1更新服務器
yum -y update
1.2安裝EPEL存儲庫
yum -y install epel-release
1.3。安裝REMI存儲庫
wget http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
rpm -Uvh remi-release-7*.rpm
1.4。驗證EPEL Repo
yum repolist
安裝MySQL(MariaDB)服務器
2.1創建MariaDB repo
vi /etc/yum.repos.d/MariaDB.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
2.3。啟用REMI存儲庫(更改enabled = 0 啟用= 1)
vi /etc/yum.repos.d/remi.repo
樣品輸出
[remi]
name=Remis RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/remi/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/remi/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/remi/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
2.4。安裝MySQL(MariaDB)
yum -y install mariadb-server mariadb
2.5。啟動MySQL(MariaDB)
systemctl start mariadb.service
2.6。創建MySQL(MariaDB)的系統啟動鏈接,以在系統啟動時自動啟動MySQL(MariaDB)
systemctl enable mariadb.service
2.7設置MySQL(MariaDB)root帳戶的密碼:
mysql_secure_installation
樣品輸出
# 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, well need the current
password for the root user. If youve just installed MariaDB, and
you havent 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): (just press enter here)
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] (just press enter here)
New password: (enter new root SQL password)
Re-enter new password: (re-enter new root SQL 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] (just press enter here)
... 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] (just press enter here)
... Success!
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] (just press enter here)
- 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] (just press enter here)
... Success!
Cleaning up...
All done! If youve completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
安裝Apache Web服務器
3.1安裝Apache
yum -y install httpd
3.2啟動Apache Web服務器
systemctl start httpd.service
3.3。創建httpd的系統啟動鏈接,在系統啟動時自動啟動httpd
systemctl enable httpd.service
3.4。CentOS 7.X使用防火牆CMD,因此您必須對其進行自定義,以允許外部訪問端口80(http)和443(https)。如果你想留在IP表上,這個步驟。
systemctl start firewalld
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
3.5確保Apache服務器正在運行:http://your.server.ip.adders/
PHP 7.1安裝
4.1。確保remi-php71.repo在那裡
ls /etc/yum.repos.d
smple輸出
CentOS-Base.repo CentOS-Vault.repo remi-php54.repo
CentOS-CR.repo CentOS-fasttrack.repo remi-php70.repo
CentOS-Debuginfo.repo MariaDB.repo remi-php71.repo
CentOS-Media.repo epel-testing.repo remi-safe.repo
CentOS-Sources.repo epel.repo remi.repo
4.2啟用php7.1的REMI存儲庫(更改enabled = 0 啟用= 1)
vi /etc/yum.repos.d/remi-php71.repo
樣品輸出
[remi-php71]
name=Remis PHP 7.1 RPM repository for Enterprise Linux 7 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/7/php71/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/7/php71/httpsmirror
mirrorlist=http://rpms.remirepo.net/enterprise/7/php71/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi
4.3。安裝PHP
yum -y install php
4.4。為PHP7安裝MySQL支持
yum -y install php-mysql
4.5您可以安裝CMS系統(如WordPress,Joomla和Drupal)所需的常見PHP模塊
yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
4.6。重新啟動Apache:
systemctl restart httpd.service
4.7。我們來測試一下:創建php信息文件
vi /var/www/html/info.php
添加以下行到info.php
<?php
phpinfo();
phpinfo(INFO_MODULES);
?>
確保PHP工作,php模塊在那裡http://your.server.ip.address/info.php
phpMyAdmin安裝
5.1。安裝phpMyAdmin。phpMyAdmin是一個Web界面,您可以通過它來管理MySQL數據庫。
yum install phpMyAdmin
5.2我們更改Apache配置,以便phpMyAdmin不僅允許從localhost進行連接。
vi /etc/httpd/conf.d/phpMyAdmin.conf
添加以下行:
<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
樣品輸出
# phpMyAdmin - Web based MySQL browser written in php
#
# Allows only localhost by default
#
# But allowing phpMyAdmin to anyone other than localhost should be considered
# dangerous unless properly secured by SSL
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
Require local
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
</Directory>
<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>
5.3將phpMyAdmin config.inc.php中的身份驗證從cookie更改為http:
vi /etc/phpMyAdmin/config.inc.php
smple輸出
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'http';
/* Server parameters */
[...]
5.4重新啟動Apache:
systemctl restart httpd.service
5.5確保phpMyAdmin工作。轉到http://your.server.ip.address/phpmyadmin/
登錄名:root,密碼在步驟2.7中添加的內容
登錄名:root,密碼在步驟2.7中添加的內容
恭喜,你完成了!🙂
使用的來源:
https : //www.apache.org/
http://php.net/
https://www.phpmyadmin.net/
https://mariadb.org/
https : //www.apache.org/
http://php.net/
https://www.phpmyadmin.net/
https://mariadb.org/
沒有留言:
張貼留言
注意:只有此網誌的成員可以留言。