安装Apache,MariaDB,PHP(灯)堆栈上的Arch Linux
正如我们所知,灯是Linux,Apache,MySQL/Mariadb,PHP/Perl/Pyhton的首字母缩略词。
本教程通过安装和配置Apache,MySQL,PHP(灯)堆栈在Arch Linux上进行。
出于本文的目的,我将使用以下测试机器。
- 操作系统:Arch Linux 64位版
- IP地址:192.168.1.102/24
- 主机名:服务器
1.更新ARCH系统
以root用户身份运行以下命令以更新Arch Linux:
pacman -Syu
2.安装apache.
更新系统后,使用命令安装Apache Web Server:
pacman -S apache
编辑/etc/httpd/conf/httpd.conf文件,
nano /etc/httpd/conf/httpd.conf
如果尚未搜索并注释出以下行:
[...] #LoadModule unique_id_module modules/mod_unique_id.so [...]
保存关闭文件。
启用Apache服务以启动启动并使用命令重新启动Apache服务:
systemctl enable httpd systemctl restart httpd
我们可以使用命令验证Apache是否正在运行:
systemctl status httpd
示例输出:
● httpd.service - Apache Web Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2015-02-16 13:00:18 IST; 7s ago Main PID: 1067 (httpd) Tasks: 82 (limit: 512) CGroup: /system.slice/httpd.service ├─1067 /usr/bin/httpd -k start -DFOREGROUND ├─1070 /usr/bin/httpd -k start -DFOREGROUND ├─1071 /usr/bin/httpd -k start -DFOREGROUND └─1072 /usr/bin/httpd -k start -DFOREGROUND Nov 16 13:00:18 server systemd[1]: Started Apache Web Server. Nov 16 13:00:18 server httpd[1067]: AH00558: httpd: Could not reliably dete...ge Hint: Some lines were ellipsized, use -l to show in full.
Apache服务器已准备好使用。
测试apache.
让我们在Apache根目录中创建一个示例页面,例如:/srv/http。
nano /srv/http/index.html
添加以下行:
<html> <title>Welcome</title> <body> <h2>Welcome to theitroad test page</h2> </body> </html>
现在,打开Web浏览器并导航到http://localhost或者http://IP地址。
我们对Apache Server测试页面很满意。
3.安装MariaDB.
运行以下命令以安装MariaDB:
pacman -S mysql
正如我们所知道的,MariaDB自2013年以来,MariaDB正在正式官方地执行arch Linux中MySQL的默认实现。
因此,我们将被问到是否安装MariaDB或者Percona服务器,只需点击Enter,然后键入"Y",然后再次按Enter键。
默认选择:例如:MariaDB将安装在Arch Linux上。
resolving dependencies... looking for conflicting packages... Packages (7) boost-libs-1.60.0-2 icu-56.1-2 jemalloc-4.0.4-1 libmariadbclient-10.1.11-1 libxml2-2.9.3-1 mariadb-clients-10.1.11-1 mariadb-10.1.11-1 Total Download Size: 30.68 MiB Total Installed Size: 218.10 MiB :: Proceed with installation? [Y/n] n [Hyman@theitroad ~]# pacman -S mysql :: There are 2 providers available for mysql: :: Repository extra 1) mariadb :: Repository community 2) percona-server Enter a number (default=1): ## Press Enter resolving dependencies... looking for conflicting packages... Packages (7) boost-libs-1.60.0-2 icu-56.1-2 jemalloc-4.0.4-1 libmariadbclient-10.1.11-1 libxml2-2.9.3-1 mariadb-clients-10.1.11-1 mariadb-10.1.11-1 Total Download Size: 30.68 MiB Total Installed Size: 218.10 MiB :: Proceed with installation? [Y/n] y
我们需要在开始服务之前初始化MariaDB数据目录。
为此,运行:
mysql_install_db --user=mysql --basedir=/usr --datadir=/var/lib/mysql
然后发出以下命令以启用和启动MariaDB服务。
systemctl enable mysqld systemctl start mysqld
我们可以验证MariaDB是否正在运行或者不使用命令:
systemctl status mysqld
示例输出:
● mysqld.service - MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2015-02-16 13:19:50 IST; 44s ago Process: 1406 ExecStartPost=/usr/bin/mysqld-post (code=exited, status=0/SUCCESS) Main PID: 1405 (mysqld) Tasks: 26 (limit: 512) CGroup: /system.slice/mysqld.service └─1405 /usr/bin/mysqld --pid-file=/run/mysqld/mysqld.pid Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...a. Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...e. Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...rt Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...19 Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930516817664 [N...ed Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...d. Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...'. Nov 16 13:19:49 server mysqld[1405]: 2015-02-16 13:19:49 139930931222400 [N...s. Nov 16 13:19:49 server mysqld[1405]: Version: '10.1.11-MariaDB-log' socket...er Nov 16 13:19:50 server systemd[1]: Started MariaDB database server. Hint: Some lines were ellipsized, use -l to show in full.
设置mysql/mariadb root用户密码
我们可能知道,建议为数据库root用户设置密码。
运行以下命令以设置MariaDB root用户密码:
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!
MariaDB已安装并准备使用。
4.安装PHP.
要在Arch Linux中安装PHP,请运行:
pacman -S php php-apache
安装PHP后,我们需要配置Apache PHP模块。
为此,请编辑/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 php7_module modules/libphp7.so AddHandler php7-script php Include conf/extra/php7_module.conf
保存并关闭文件。
测试PHP.
现在在Apache根目录中创建一个test.php文件。
nano /srv/http/test.php
添加以下行:
<?php phpinfo(); ?>
重新启动httpd服务。
systemctl restart httpd
打开Web浏览器并导航到http://ip-address/test.php。
我们应该如下屏幕。
5.安装phpmyadmin
phpmyadmin是一个图形MySQL/Mariadb管理工具,可用于创建,编辑和删除数据库。
要安装它,请运行:
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。
我们应该看到以下类似屏幕。
输入mysql/mariadb根用户名及其密码。
其中我的phpmyadmin web控制台看起来像。
我们可能会看到一个错误,说明"配置文件现在需要PHPMyAdmin仪表板底部的秘密密码(Blowfish_secret)"。
要摆脱此错误,请编辑/etc/webapps/phpmyadmin/config.inc.php文件,
nano /etc/webapps/phpmyadmin/config.inc.php
找到以下行并指定Bluefish密码密码短语:
$cfg['blowfish_secret'] = 'Welc0me1'; /* YOU MUST FILL IN THIS FOR COOKIE AUTH!$
/**
这里welc0me1是我的秘密密码。
保存并关闭文件。
重新启动Apache服务。
systemctl restart httpd
错误现在将消失。