Fedora 23 如何安裝 LAMP 服務器

jopen 9年前發布 | 7K 次閱讀 Fedora 23

LAMP 是開源系統上 Web 服務器的夢幻組合。 LAMP 是 Linux、 Apache HTTP 服務、 MySQL/MariaDB 數據庫PHP、 Perl 或 Python 的簡稱。

下面教你如何在 Fedora 23 服務器上安裝 LAMP 組合。

下面的教程默認使用 192.168.1.102/24 實例,請按照你的服務器做修改。

安裝 Apache

Apache 是一款開源的 web 服務框架。完全支持 CGI, SSL。

切換到 root 賬戶:

su

Fedora 23/22 輸入以下命令來安裝Apache:

dnf install httpd -y

Fedora 21 及更早的版本:

yum install httpd -y

啟動httpd服務,以在每次系統啟動服務:

systemctl enable httpd

使用以下命令來啟動httpd服務:

systemctl start httpd

如果您遇到以下錯誤:

Job for httpd.service failed. See ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.

刪除所有內容在/etc/hostname,并加上“localhost”。同時,在/etc/httpd/conf/httpd.conf文件中的“Servername”的值設定為“localhost”,并再次嘗試啟動httpd服務。
并調整防火墻以允許httpd服務,從遠程客戶端訪問。

firewall-cmd --permanent --add-service=http

firewall-cmd --permanent --add-service=https

重新啟動firewalld服務:

firewall-cmd --reload

打開瀏覽器,輸入服務器IP訪問:

Fedora 23 如何安裝 LAMP 服務器

安裝 MariaDB

Fedora 23/22 用戶安裝命令:

dnf install mariadb mariadb-server -y

Fedora 21 及早前版本命令:

yum install mariadb mariadb-server -y

隨系統自動啟動命令:

systemctl enable mariadb

啟動數據庫服務器:

systemctl start mariadb

設置 MariaDB root 賬戶密碼,默認情況下MySQL root用戶的密碼為空。因此,以防止未經授權的訪問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 current
password for the root user. If you’ve just installed MariaDB, and
you 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):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
You already have a root password set, so you can safely answer ‘n’.
Change the root password? [Y/n] y ## Enter ‘y’ and press enter ##
New password: ## Enter password ##
Re-enter new password: ## Re-enter 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] ## Press Enter ##
… 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] ## Press Enter ##
… 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] ## Press Enter ##
– Dropping test database…
ERROR 1008 (HY000) at line 1: Can’t drop database ‘test’; database doesn’t exist
… Failed! Not critical, keep moving…
– 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] ## Press Enter ##
… 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!

安裝 PHP

Fedora 23/22 用戶命令:

dnf install php -y

Fedora 21 及早期版本:

yum install php -y

測試PHP是否運行:

vi /var/www/html/testphp.php

輸入以下內容:

<?phpphpinfo();
?>

重啟 Http 服務:

systemctl restart httpd

瀏覽器輸入看看:

Fedora 23 如何安裝 LAMP 服務器

安裝PHP模塊

搜索模塊并安裝:

Fedora 23/22 用戶:
dnf search php

Fedora 22及早期版本:
yum search php

現在安裝你所選擇所需模塊,例如php-mysql,使用以下命令:

Fedora 23/22 用戶:

dnf install php-mysql -y

Fedora 22及早期版本:

yum install php-mysql -y

重啟 HTTP 服務:

systemctl restart httpd

瀏覽器查看模塊安裝是否成功:

Fedora 23 如何安裝 LAMP 服務器

安裝 phpMyAdmin

phpmyadmin 用于管理數據庫
Fedora 23/22 用戶:

dnf install phpmyadmin -y

Fedora 22及早期版本:

yum install phpmyadmin -y

缺省情況下,phpMyAdmin 只能從本地主機進行訪問。若要從遠程系統訪問您的網絡中,請執行下列操作步驟。

vi /etc/httpd/conf.d/phpMyAdmin.conf

查找并注釋掉127.0.0.1 和請求 ip ::1 lines。然后添加一個額外的行要求所有授予略低于為注釋行。

這是我的更改后的 phpMyAdmin.conf 文件。這些變化以粗體標記。

[...]
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
     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
        Require all granted
     </RequireAny>
   </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/setup/>
   <IfModule mod_authz_core.c>
     # Apache 2.4
     <RequireAny>
#       Require ip 127.0.0.1
#       Require ip ::1
        Require all granted
     </RequireAny>
   </IfModule>
   <IfModule !mod_authz_core.c>
[...]

重要提示:不過讓localhost以外的人訪問數據庫,應視為危險,除非通過SSL適當保護。做到這一點需要您自擔風險。

保存并關閉文件。重新啟動httpd服務。
systemctl restart httpd

OK,打開 phpmyadmin 測試一下:

Fedora 23 如何安裝 LAMP 服務器

好了,安裝完畢!

轉自于 IMCN

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!