manjaro linux 安裝 Apache,MariaDB,PHP(LAMP)
root 身份執行下面的命令
1. 升級系統
pacman -Syu
2. 安裝 Apache
升級完后,安裝Apache
pacman -S apache
編輯 /etc/httpd/conf/httpd.conf file
nano /etc/httpd/conf/httpd.conf
# 我這里用的nano,你可用其它的編輯器只要能編輯文本就行
找到LoadModule unique_id_module modules/mod_unique_id.so 注釋了
[...]
#LoadModule unique_id_module modules/mod_unique_id.so
[...]
保存退出
讓Apache 開機啟動 然后重啟 Apache 服務
systemctl enable httpd
systemctl restart httpd
然后看看 Apache 服務是否啟動成功
systemctl status httpd
Active: active (running) 有這個就意思成功運行
測試一下Apache
創建一個簡單的頁面
nano /srv/http/index.html
加入下列內容
<html>
<title>Welcome</title>
<body>
<h2> test page</h2>
</body>
</html>
3. 安裝MariaDB
執行下列命令來安裝
pacman -S mysql
然后執行下面的命令
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
systemctl enable mysqld
systemctl start mysqld
systemctl status mysqld
設置MySQL/MariaDB root user的密碼
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): ## Press Enter
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]## 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...
... 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]## 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!
4. 安裝 PHP
執行安裝命令
pacman -S php php-apache
安裝完后來編輯/etc/httpd/conf/httpd.conf文件
nano /etc/httpd/conf/httpd.conf
找到下面的行取消注釋
[...]
#LoadModule mpm_event_module modules/mod_mpm_event.so
[...]
然后找到LoadModule mpm_prefork_module modules/mod_mpm_prefork.so 一般在剛剛注釋的那行下買 沒有就在下面加上 有的話就取消注釋
LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
然后在最后加上下面的幾行
LoadModule php7_module modules/libphp7.so
AddHandler php7-script php
Include conf/extra/php7_module.conf
保存退出
測試php
創建test.php
nano /srv/http/test.php
加上下面幾行
<?php
phpinfo();
?>
重啟httpd service
systemctl restart httpd
然后打開http://ip-address/test.php
如果看到php的頁面就成功
5 安裝 phpMyAdmin
執行命令
pacman -S phpmyadmin php-mcrypt
安裝完成后編輯php.ini
nano /etc/php/php.ini
取消下列行的注釋
[...]
extension=bz2.so
extension=mcrypt.so
extension=mysqli.so
[...]
保存退出
編輯phpMyAdmin的配置文件
nano /etc/httpd/conf/extra/phpmyadmin.conf
加入下列內容
Alias /phpmyadmin "/usr/share/webapps/phpMyAdmin"
<Directory "/usr/share/webapps/phpMyAdmin">
DirectoryIndex index.php
AllowOverride All
Options FollowSymlinks
Require all granted
</Directory>
編輯 Apache的配置文件
nano /etc/httpd/conf/httpd.conf
在最后加入
Include conf/extra/phpmyadmin.conf
保存,退出,重啟httpd服務
systemctl restart httpd
測試phpMyAdmin
打開http://IP-Address/phpmyadmin
phpmyadmin測試
