LAMP環境如何搭建?LAMP環境搭建的詳細過程

來源:互聯網
上載者:User
這篇文章給大家介紹的內容是關於LAMP環境搭建的詳細過程,有一定的參考價值,有需要的朋友可以參考一下,希望對你有所協助。

最開始迷你安裝好CentOS 7之後,直接輸入 ifconfig 命令,提示 "ifconfig command not found" ,說明迷你安裝沒有安裝相關軟體,我們可以用 ip addr 代替 ifconfig 來查看網卡詳情,或者我們可以通過 yum install net-tools 來安裝回 ifconfig 命令,在安裝過程中輸入兩次y,即可完成安裝。

一、Apache

yum install httpd //安裝Apache

Total download size: 3.0 MInstalled size: 10 MIs this ok [y/d/N]:  //輸入y,確認安裝
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7Importing GPG key 0xF4A80EB5: Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 Package    : centos-release-7-5.1804.el7.centos.x86_64 (@anaconda) From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7Is this ok [y/N]:  //驗證GPG密鑰是否正確,輸入y
Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : apr-1.4.8-3.el7_4.1.x86_64                                                            1/5   Installing : apr-util-1.5.2-6.el7.x86_64                                                           2/5   Installing : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                              3/5   Installing : mailcap-2.1.41-2.el7.noarch                                                           4/5   Installing : httpd-2.4.6-80.el7.centos.1.x86_64                                                    5/5   Verifying  : mailcap-2.1.41-2.el7.noarch                                                           1/5   Verifying  : httpd-tools-2.4.6-80.el7.centos.1.x86_64                                              2/5   Verifying  : apr-util-1.5.2-6.el7.x86_64                                                           3/5   Verifying  : apr-1.4.8-3.el7_4.1.x86_64                                                            4/5   Verifying  : httpd-2.4.6-80.el7.centos.1.x86_64                                                    5/5 Installed:  httpd.x86_64 0:2.4.6-80.el7.centos.1                                                                   Dependency Installed:  apr.x86_64 0:1.4.8-3.el7_4.1  apr-util.x86_64 0:1.5.2-6.el7 httpd-tools.x86_64 0:2.4.6-80.el7.centos.1  mailcap.noarch 0:2.1.41-2.el7Complete!

開啟Apache服務,並設定系統啟動時服務自動啟動:
systemctl start httpd.service
systemctl enable httpd.service

為了能夠從外部存取Web伺服器,必須在防火牆中開啟HTTP(80)和HTTPS(443)連接埠。CentOS上的預設防火牆是firewalld,可以使用firewalld-cmd命令進行配置。
firewall-cmd --permanent --zone = public --add-service = http
firewall-cmd --permanent --zone = public --add-service = https
firewall-cmd --reload //重啟firewalld

檢測Apache服務是否開啟:
systemctl status httpd.service

● httpd.service - The Apache HTTP Server   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)   Active: active (running) since Mon 2018-08-06 20:14:21 CST; 9s ago     Docs: man:httpd(8)           man:apachectl(8) Main PID: 1498 (httpd)   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"   CGroup: /system.slice/httpd.service           ├─1498 /usr/sbin/httpd -DFOREGROUND           ├─1499 /usr/sbin/httpd -DFOREGROUND           ├─1500 /usr/sbin/httpd -DFOREGROUND           ├─1501 /usr/sbin/httpd -DFOREGROUND           ├─1502 /usr/sbin/httpd -DFOREGROUND           └─1503 /usr/sbin/httpd -DFOREGROUNDAug 06 20:14:21 localhost systemd[1]: Starting The Apache HTTP Server...Aug 06 20:14:21 localhost httpd[1498]: AH00558: httpd: Could not reliably determine the server's f...sageAug 06 20:14:21 localhost systemd[1]: Started The Apache HTTP Server.Hint: Some lines were ellipsized, use -l to show in full.

再用瀏覽器輸入伺服器的IP地址:


看到介面表示安裝成功。

二、MySQL/MariaDB

MariaDB資料庫管理系統是MySQL的一個分支,主要由開源社區在維護,採用GPL授權許可。

開發這個分支的原因之一是:甲骨文公司收購了MySQL後,有將MySQL閉源的潛在風險,因此社區採用分支的方式來避開這個風險。

MariaDB的目的是完全相容MySQL,包括API和命令列,是目前最受關注的MySQL資料庫衍生版,也被視為開來源資料庫MySQL的替代品。

這裡我們用MariaDB代替MySQL,MySQL安裝及操作方法大體類似。
安裝時,把mariadb換成mysql;
啟動、停止服務、查看狀態,把mariadb.service換成mysql.service。

yum -y install mariadb-server mariadb //安裝MariaDB

Installed:  mariadb.x86_64 1:5.5.56-2.el7                   mariadb-server.x86_64 1:5.5.56-2.el7                  Dependency Installed:  perl.x86_64 4:5.16.3-292.el7                        perl-Carp.noarch 0:1.26-244.el7                     perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7        perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7         perl-DBD-MySQL.x86_64 0:4.023-6.el7                 perl-DBI.x86_64 0:1.627-4.el7                       perl-Data-Dumper.x86_64 0:2.145-3.el7               perl-Encode.x86_64 0:2.51-7.el7                     perl-Exporter.noarch 0:5.68-3.el7                   perl-File-Path.noarch 0:2.09-2.el7                  perl-File-Temp.noarch 0:0.23.01-3.el7               perl-Filter.x86_64 0:1.49-3.el7                     perl-Getopt-Long.noarch 0:2.40-3.el7                perl-HTTP-Tiny.noarch 0:0.033-3.el7                 perl-IO-Compress.noarch 0:2.061-2.el7               perl-Net-Daemon.noarch 0:0.48-5.el7                 perl-PathTools.x86_64 0:3.40-5.el7                  perl-PlRPC.noarch 0:0.2020-14.el7                   perl-Pod-Escapes.noarch 1:1.04-292.el7              perl-Pod-Perldoc.noarch 0:3.20-4.el7                perl-Pod-Simple.noarch 1:3.28-4.el7                 perl-Pod-Usage.noarch 0:1.63-3.el7                  perl-Scalar-List-Utils.x86_64 0:1.27-248.el7        perl-Socket.x86_64 0:2.010-4.el7                    perl-Storable.x86_64 0:2.45-3.el7                   perl-Text-ParseWords.noarch 0:3.29-4.el7            perl-Time-HiRes.x86_64 4:1.9725-3.el7               perl-Time-Local.noarch 0:1.2300-2.el7               perl-constant.noarch 0:1.27-2.el7                   perl-libs.x86_64 4:5.16.3-292.el7                   perl-macros.x86_64 4:5.16.3-292.el7                 perl-parent.noarch 1:0.225-244.el7                  perl-podlators.noarch 0:2.5.1-3.el7                 perl-threads.x86_64 0:1.87-4.el7                    perl-threads-shared.x86_64 0:1.43-6.el7            Complete!

開啟MariaDB服務,並設定系統啟動時服務自動啟動:
systemctl start mariadb.service
systemctl enable mariadb.service

設定MySQL root帳戶的密碼:
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, we'll need the currentpassword for the root user.  If you've just installed MariaDB, andyou haven't 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):  //輸入當前root使用者密碼,直接斷行符號OK, successfully used password, moving on...Setting the root password ensures that nobody can log into the MariaDBroot user without the proper authorisation.Set root password? [Y/n] New password:   //輸入密碼Re-enter new password:   //確認密碼Password updated successfully!Reloading privilege tables.. ... Success!By default, a MariaDB installation has an anonymous user, allowing anyoneto log into MariaDB without having to have a user account created forthem.  This is intended only for testing, and to make the installationgo a bit smoother.  You should remove them before moving into aproduction environment.Remove anonymous users? [Y/n]   //刪除匿名使用者,斷行符號 ... Success!Normally, root should only be allowed to connect from 'localhost'.  Thisensures that someone cannot guess at the root password from the network.Disallow root login remotely? [Y/n]   //不允許root使用者遠程登入,斷行符號 ... Success!By default, MariaDB comes with a database named 'test' that anyone canaccess.  This is also intended only for testing, and should be removedbefore moving into a production environment.Remove test database and access to it? [Y/n]   //刪除測試資料庫並訪問它,斷行符號 - Dropping test database... ... Success! - Removing privileges on test database... ... Success!Reloading the privilege tables will ensure that all changes made so farwill take effect immediately.Reload privilege tables now? [Y/n]   //重新載入許可權表,斷行符號 ... Success!Cleaning up...All done!  If you've completed all of the above steps, your MariaDBinstallation should now be secure.Thanks for using MariaDB!

三、PHP

yum install php //安裝php

Total download size: 4.7 MInstalled size: 17 MIs this ok [y/d/N]:   //允許安裝,輸入yDownloading packages:(1/4): libzip-0.10.1-8.el7.x86_64.rpm                                             |  48 kB  00:00:00     (2/4): php-5.4.16-45.el7.x86_64.rpm                                               | 1.4 MB  00:00:01     (3/4): php-common-5.4.16-45.el7.x86_64.rpm                                        | 565 kB  00:00:01     (4/4): php-cli-5.4.16-45.el7.x86_64.rpm                                           | 2.7 MB  00:00:02     ---------------------------------------------------------------------------------------------------------Total                                                                    2.1 MB/s | 4.7 MB  00:00:02     Running transaction checkRunning transaction testTransaction test succeededRunning transaction  Installing : libzip-0.10.1-8.el7.x86_64                                                            1/4   Installing : php-common-5.4.16-45.el7.x86_64                                                       2/4   Installing : php-cli-5.4.16-45.el7.x86_64                                                          3/4   Installing : php-5.4.16-45.el7.x86_64                                                              4/4   Verifying  : php-5.4.16-45.el7.x86_64                                                              1/4   Verifying  : php-cli-5.4.16-45.el7.x86_64                                                          2/4   Verifying  : libzip-0.10.1-8.el7.x86_64                                                            3/4   Verifying  : php-common-5.4.16-45.el7.x86_64                                                       4/4 Installed:  php.x86_64 0:5.4.16-45.el7                                                                             Dependency Installed:  libzip.x86_64 0:0.10.1-8.el7    php-cli.x86_64 0:5.4.16-45.el7    php-common.x86_64 0:5.4.16-45.el7   Complete!

為了使資料庫和php關聯,我們還需要安裝php-mysql:
yum install php-mysql //安裝過程輸入y,即可安裝完成

systemctl restart httpd.service //安裝好php後,要重啟Apache服務

測試php有沒有安裝好:
vi /var/www/html/index.php //建立一個php檔案,填入下面的內容

<?phpphpinfo();?>

在之前URL後加上/info.php,看到以下介面,就說明安裝成功了。

相關文章推薦:

Nginx設定檔nginx.conf的操作步驟

Linux系統下修改phpstudyIntegration Environment中的MySQL連接埠號碼的步驟

thinkPHP架構中視圖的講解(附代碼)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.