lamp配置python_LAMP搭建笔记
LAMP簡介
LAMP指的Linux(操作系統(tǒng))、ApacheHTTP 服務(wù)器,MySQL(有時(shí)也指MariaDB,數(shù)據(jù)庫軟件) 和PHP(有時(shí)也是指Perl或Python) 的第一個(gè)字母。LAMP便成了一組常用來搭建動(dòng)態(tài)網(wǎng)站或者服務(wù)器的開源軟件,本身都是各自獨(dú)立的程序,但是因?yàn)槌1环旁谝黄鹗褂?#xff0c;擁有了越來越高的兼容度,共同組成了一個(gè)強(qiáng)大的Web應(yīng)用程序平臺(tái)。
安裝步驟:
安裝服務(wù)
配置服務(wù)
啟動(dòng)服務(wù)
測試服務(wù)
安裝服務(wù)
CentOS 6:
yum install httpd php mysql-server php-mysql
CentOS 7:
yum install httpd php php-mysql mariadb-server mariadb
(php-mysql用于支持php連接mysql的組件)
配置服務(wù)
配置httpd
Apache的主配置文件:/etc/httpd/conf/httpd.conf
主配置文件一般不去修改,其中有幾個(gè)選項(xiàng)可以自定義修改。
DocumentRoot /var/www/html/ //指定默認(rèn)主頁路徑
Listen 80 //httpd的監(jiān)聽端口,可以設(shè)置為監(jiān)聽指定網(wǎng)卡"Listen [IP:]PORT",如果需要修改端口,還要同時(shí)修改防火墻和selinux的策略
DirectoryIndex index.html
DirecotryIndex index.html //默認(rèn)主頁,如果有多個(gè),優(yōu)先級為由左至右
默認(rèn)站點(diǎn)主目錄:/var/www/html/
啟動(dòng)Apache服務(wù)后,Apache服務(wù)會(huì)到默認(rèn)主目錄查找默認(rèn)主頁文件
配置mysql
mysql和mariadb數(shù)據(jù)庫服務(wù)軟件默認(rèn)提供一個(gè)安全腳本,執(zhí)行這個(gè)腳本,可以對mysql進(jìn)行基本的安全配置,比如設(shè)置密碼、刪除匿名用戶等
mysql_secure_installation //執(zhí)行MYSQL數(shù)據(jù)庫安全腳本
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):
//驗(yàn)證輸入數(shù)據(jù)庫管理用戶ROOT的密碼,默認(rèn)為空,回車即可
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
//是否更改數(shù)據(jù)庫管理員ROOT用戶的密碼,如果選Y則需要重復(fù)輸入兩遍新口令,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] y
//是否移除匿名用戶,即不輸入用戶名和密碼即可訪問,建議移除(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] n
//是否禁用root用戶遠(yuǎn)程登錄(Y禁止,N允許)
... skipping.
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] n
//是否刪除數(shù)據(jù)庫軟件自動(dòng)生成的測試數(shù)據(jù)庫(Y刪除,N不刪除)
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
//是否立即重載權(quán)限表(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!
啟動(dòng)服務(wù)
CentOS 6:
service httpd start //啟動(dòng)httpd服務(wù)
service mysqld start //啟動(dòng)mysql數(shù)據(jù)庫服務(wù)
CentOS 7:
systemctl start httpd //啟動(dòng)httpd服務(wù)
systemctl start mariadb //啟動(dòng)mariadb數(shù)據(jù)庫服務(wù)
測試服務(wù)
測試WEB運(yùn)行環(huán)境
echo "WEB服務(wù)器運(yùn)行環(huán)境良好" >> /var/www/html/index.html
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/index.html,如果頁面顯示php環(huán)境運(yùn)行良好,即PHP運(yùn)行環(huán)境可以正常使用,否則不能正常使用。
測試php運(yùn)行環(huán)境
echo "<?php echo "PHP環(huán)境運(yùn)行良好"; ?>" >> /var/www/html/index.php
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/index.php,如果頁面顯示php環(huán)境運(yùn)行良好,即PHP運(yùn)行環(huán)境可以正常使用,否則不能正常使用。
測試運(yùn)行連通性
cat << EOF >/var/www/html/mysql.php
$mysqli=new mysqli("localhost","root","00000000");
if(mysqli_connect_errno()){
echo " 連接數(shù)據(jù)庫失敗:";
$mysqli=null;
exit;
}
echo " 連接數(shù)據(jù)庫成功!";
$mysqli->close();
?>
EOF
//$mysqli=new mysqli("localhost","root","00000000");
//localhost為服務(wù)器地址,root為mysql用戶,00000000為mysql用戶的密碼。
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/mysql.php,如果頁面顯示連接數(shù)據(jù)庫成功!即PHP運(yùn)行環(huán)境可以正常使用且數(shù)據(jù)庫也可以正常訪問,否則不能正常使用。
最后編輯httpd文件讓httpd服務(wù)識別.php和.phps文件
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
至此LAMP環(huán)境搭建完成!
總結(jié)
以上是生活随笔為你收集整理的lamp配置python_LAMP搭建笔记的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 查看表是否存在_MySQL优
- 下一篇: python矩阵中找满足条件的元素_Py