Ubuntu上搭建LAMP

一,搭建LAMP環境

1,Apache2 web服務器的安裝

apt install apache2  安裝Apache

systemctl status apache2 檢查是否開啓apache,一般安裝完畢後會默認開啓

systemctl start apache2  開啓apache服務器

systemctl stop apache2   關閉apache服務器

systemctl restart apache2  重啓apache服務器

使用瀏覽器訪問IP地址,出現如下頁面說明apache服務器安裝成功

2,MySql數據庫的安裝

apt install -y mysql-server 安裝MySQL數據庫

netstat -tap | grep mysql 檢查MySQL是否安裝成功

爲了讓數據庫更安全和正常運轉,進行初始化操作

root@VM-0-6-ubuntu:/# mysql_secure_installation 

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: N #需要安裝密碼插件嗎?
Please set the password for root here.

New password:   輸入新的root用戶密碼

Re-enter new password: 再次輸入
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL 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? (Press y|Y for Yes, any other key for No) : y 是否刪除匿名賬戶
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? (Press y|Y for Yes, any other key for No) :  是否禁止遠程登陸

 ... skipping.
By default, MySQL 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? (Press y|Y for Yes, any other key for No) : y 刪除test數據並取消對它的訪問權限
 - 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? (Press y|Y for Yes, any other key for No) : y
Success.  刷新授權表,讓初始化後的設定立即生效。

All done! 
root@VM-0-6-ubuntu:/#

sysytemctl status mysql 檢查MySQL服務是否正常運行

3,安裝PHP

apt  -y install php 安裝PHP 

訴Apache首先提供PHP頁面。

打開/etc/apache2/mods-enabled/dir.conf文件並將其更改爲首先列出index.php。

<IfModule mod_dir.c>
        DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
</IfModule>

 vim /etc/apache2/mods-enabled//dir.conf 

systemctl restart apache2 重啓apache web 服務器

測試PHP

在/var/www/html中新建一個phpinfo.php文件  vim phpinfo

在裏面寫入<?php phpinfo();?>

然後再瀏覽器當中輸入http://{ip}/phpinfo.php進行訪問,出現如下頁面,表示PHP正常

爲了安全,在測試完PHP正常之後刪除該文件

rm /var/www/html/phpinfo.php

安裝PHP模塊

最有可能的是,當您安裝基於PHP的應用程序時,它將具有PHP模塊依賴性。

一個常見的PHP模塊是php-curl模塊。

我們可以用apt來安裝這些。 只需在您需要安裝的模塊前面添加“php-”。

apt install php-curl

如果您在查找所需的模塊時遇到問題,只需輸入“apt install php”(模塊的第一個字母),然後點擊TAB鍵。

Ubuntu將爲您列出所有匹配的包。

# apt install php-c
php-cache-integration-tests  php-cgi                      php-common                  php-console-table
php-cache-lite              php-cli                      php-composer-ca-bundle      php-constant-time
php-cache-tag-interop        php-cli-prompt              php-composer-semver          php-curl
php-cas                      php-codecoverage            php-composer-spdx-licenses   
php-cassandra                php-codesniffer              php-console-commandline

綜上,LAMP現在已經搭建好了,接下來就可以搭建網站了。

二,搭建網站

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章