lamp 是开源系统上 web 的梦幻组合。 lamp 是 linux、 apache http 服务、 mysql/mariadb 数据库和 php、 perl 或 python 的简称。
下面教你如何在 fedora 23 服务器上安装 lamp 组合。
下面的教程默认使用 192.168.1.102/24 实例,请按照你的服务器做修改。
安装 apache
apache 是一款开源的 web 服务框架。完全支持 cgi, ssl。
切换到 root 账户:
su
fedora 23/22 输入以下命令来安装apache:
dnf install httpd -y
fedora 21 及更早的版本:
yum install httpd -y
启动httpd服务,以在每次系统启动服务:
systemctl enable httpd
使用以下命令来启动httpd服务:
systemctl start httpd
如果您遇到以下错误:
job for httpd.service failed. see ‘systemctl status httpd.service’ and ‘journalctl -xn’ for details.
删除所有内容在/etc/hostname,并加上“localhost”。同时,在/etc/httpd/conf/httpd.conf文件中的“servername”的值设定为“localhost”,并再次尝试启动httpd服务。
并调整防火墙以允许httpd服务,从远程客户端访问。
firewall-cmd --permanent --add-service=http firewall-cmd --permanent --add-service=https
重新启动firewalld服务:
firewall-cmd --reload
打开浏览器,输入服务器ip访问:
安装mariadb
fedora 23/22 用户安装命令:
dnf install mariadb mariadb-server -y
fedora 21 及早前版本命令:
yum install mariadb mariadb-server -y
随系统自动启动命令:
systemctl enable mariadb
启动数据库服务器:
systemctl start mariadb
设置 mariadb root 账户密码,默认情况下mysql root用户的密码为空。因此,以防止未经授权的访问mysql数据库,我们设置需要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): 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 ## enter ‘y’ and 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… error 1008 (hy000) at line 1: can’t drop database ‘test’; database doesn’t exist … failed! not critical, keep moving… – 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!
安装php
fedora 23/22 用户命令:
dnf install php -y
fedora 21 及早期版本:
yum install php -y
测试php是否运行:
vi /var/www/html/testphp.php
输入以下内容:
重启 http 服务:
systemctl restart httpd
浏览器输入看看:
安装php模块
搜索模块并安装:
fedora 23/22 用户:
dnf search php
fedora 22及早期版本:
yum search php
现在安装你所选择所需模块,例如php-mysql,使用以下命令:
fedora 23/22 用户:
dnf install php-mysql -y
fedora 22及早期版本:
yum install php-mysql -y
重启 http 服务:
systemctl restart httpd
浏览器查看模块安装是否成功:
安装phpmyadmin
phpmyadmin 用于管理数据库:
fedora 23/22 用户:
dnf install phpmyadmin -y
fedora 22及早期版本:
yum install phpmyadmin -y
缺省情况下,phpmyadmin 只能从本地进行访问。若要从远程系统访问您的网络中,请执行下列操作步骤。
vi /etc/httpd/conf.d/phpmyadmin.conf
查找并注释掉127.0.0.1 和请求 ip ::1 lines。然后添加一个额外的行要求所有授予略低于为注释行。
这是我的更改后的 phpmyadmin.conf 文件。这些变化以粗体标记。
[...] alias /phpmyadmin /usr/share/phpmyadmin alias /phpmyadmin /usr/share/phpmyadminadddefaultcharset utf-8 # apache 2.4 # require ip 127.0.0.1# require ip ::1 require all granted # apache 2.2 order deny,allow deny from all allow from 127.0.0.1 allow from ::1 # apache 2.4 # require ip 127.0.0.1# require ip ::1 require all granted [...]
重要提示:不过让localhost以外的人访问数据库,应视为危险,除非通过ssl适当保护。做到这一点需要您自担风险。
保存并关闭文件。重新启动httpd服务。
systemctl restart httpd
ok,打开 phpmyadmin 测试一下:
好了,安装完毕!