title: 安裝lamp
id: 9
categories:
- linux的學習記錄
date: 2015-08-19 10:03:30
tags:
使用下面的命令安裝MySQL:
yum install mysql mysql-server
為MySQL創建啟動連接 (這樣 MySQL 將隨系統自動啟動)并啟動 MySQL服務:
systemctl enable mysqld.service
注意:如果您收到這樣的錯誤
Failed to issue method call: No such file or directory
使用下面的命令
systemctl enable mariadb.service
進一步啟動mysql的服務
systemctl start mysqld.service
運行
mysql_secure_installation
設置root用戶密碼(否則任何人都可以訪問你MySQL數據庫!):
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client: command not found
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.
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 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] <– (直接回車)
… 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] <– (直接回車)
… 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] <– (直接回車)
- 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] <– (直接回車)
… 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!
[root@server1 ~]#
3 安裝Apache2服務器
運行下面的命令:
yum install httpd
現在配置您的系統在開機時啟動Apache…
systemctl enable httpd.service
并且啟動Apache:
systemctl start httpd.service
在瀏覽器輸入地址訪問 http://192.168.0.100,如果看到下面的頁面,說明安裝成功!
4 安裝 PHP5
我們需要安裝 PHP5 和 Apache PHP5 模塊,運行命令:
yum install php
重啟 Apache :
systemctl restart httpd.service
5 測試PHP5/獲取關于PHP5安裝詳細信息
在默認根目錄下創建一個探針文件:
vi /var/www/html/info.php
正如你看到的,PHP5正在運行,再向下滾動,你會看到PHP5中已經啟用了所有模塊。 MySQL是沒有被列入其中,這意味著現在還不支持MySQL。
6 讓PHP5支持MySQL
我們需要安裝一個模塊使得php5支持mysql,先查詢一下安裝包
yum search php
使用下面的命令進行安裝:
yum install php-mysqlnd php-mssql php-opcache
在重啟Apache2:
systemctl restart httpd.service
現在刷新 http://192.168.0.100/info.php模塊是否安裝成功,看PHP5是否已經支持Mysql
7 安裝phpMyAdmin來管理Mysql
phpmyadmin是一款基于php語言編寫的管理 MySQL數據庫的圖形化軟件。
使用下面的命令安裝phpMyAdmin:
yum install phpmyadmin
現在配置 phpMyAdmin。我們需要改變 Apache 配置來讓 phpMyAdmin 支持 localhost 連接(去掉/usr/share/phpMyAdmin/ 前面的注釋,這樣就準許訪問)
vi /etc/httpd/conf.d/phpMyAdmin.conf
重啟Apache:
systemctl restart httpd.service
訪問phpMyAdmin輸入地址 http://192.168.0.100/phpmyadmin/: