lamp配置python_LAMP搭建笔记
LAMP簡介
LAMP指的Linux(操作系統)、ApacheHTTP 服務器,MySQL(有時也指MariaDB,數據庫軟件) 和PHP(有時也是指Perl或Python) 的第一個字母。LAMP便成了一組常用來搭建動態網站或者服務器的開源軟件,本身都是各自獨立的程序,但是因為常被放在一起使用,擁有了越來越高的兼容度,共同組成了一個強大的Web應用程序平臺。
安裝步驟:
安裝服務
配置服務
啟動服務
測試服務
安裝服務
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的組件)
配置服務
配置httpd
Apache的主配置文件:/etc/httpd/conf/httpd.conf
主配置文件一般不去修改,其中有幾個選項可以自定義修改。
DocumentRoot /var/www/html/ //指定默認主頁路徑
Listen 80 //httpd的監聽端口,可以設置為監聽指定網卡"Listen [IP:]PORT",如果需要修改端口,還要同時修改防火墻和selinux的策略
DirectoryIndex index.html
DirecotryIndex index.html //默認主頁,如果有多個,優先級為由左至右
默認站點主目錄:/var/www/html/
啟動Apache服務后,Apache服務會到默認主目錄查找默認主頁文件
配置mysql
mysql和mariadb數據庫服務軟件默認提供一個安全腳本,執行這個腳本,可以對mysql進行基本的安全配置,比如設置密碼、刪除匿名用戶等
mysql_secure_installation //執行MYSQL數據庫安全腳本
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):
//驗證輸入數據庫管理用戶ROOT的密碼,默認為空,回車即可
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
//是否更改數據庫管理員ROOT用戶的密碼,如果選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] 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用戶遠程登錄(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
//是否刪除數據庫軟件自動生成的測試數據庫(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
//是否立即重載權限表(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!
啟動服務
CentOS 6:
service httpd start //啟動httpd服務
service mysqld start //啟動mysql數據庫服務
CentOS 7:
systemctl start httpd //啟動httpd服務
systemctl start mariadb //啟動mariadb數據庫服務
測試服務
測試WEB運行環境
echo "WEB服務器運行環境良好" >> /var/www/html/index.html
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/index.html,如果頁面顯示php環境運行良好,即PHP運行環境可以正常使用,否則不能正常使用。
測試php運行環境
echo "<?php echo "PHP環境運行良好"; ?>" >> /var/www/html/index.php
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/index.php,如果頁面顯示php環境運行良好,即PHP運行環境可以正常使用,否則不能正常使用。
測試運行連通性
cat << EOF >/var/www/html/mysql.php
$mysqli=new mysqli("localhost","root","00000000");
if(mysqli_connect_errno()){
echo " 連接數據庫失敗:";
$mysqli=null;
exit;
}
echo " 連接數據庫成功!";
$mysqli->close();
?>
EOF
//$mysqli=new mysqli("localhost","root","00000000");
//localhost為服務器地址,root為mysql用戶,00000000為mysql用戶的密碼。
使用瀏覽器或者curl、link等軟件訪問http://127.0.0.1/mysql.php,如果頁面顯示連接數據庫成功!即PHP運行環境可以正常使用且數據庫也可以正常訪問,否則不能正常使用。
最后編輯httpd文件讓httpd服務識別.php和.phps文件
AddType application/x-httpd-php .php
AddType application/x-httpd-php-source .phps
DirectoryIndex index.php index.html
至此LAMP環境搭建完成!
總結
以上是生活随笔為你收集整理的lamp配置python_LAMP搭建笔记的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 查看表是否存在_MySQL优
- 下一篇: python矩阵中找满足条件的元素_Py