centos7下搭建LAMP
一 配置Apache
-
配置apache
yum install httpd httpd-devel
-
启动apache
systemctl start httpd
-
设置开机启动
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service. -
检查启动
[root@localhost ~]# service httpd status
Redirecting to /bin/systemctl status httpd.service
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
Active: active (running) since 二 2019-03-12 21:29:11 CST; 4s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 1752 (httpd)
Status: “Processing requests…”
Tasks: 6
CGroup: /system.slice/httpd.service
├─1752 /usr/sbin/httpd -DFOREGROUND
├─1755 /usr/sbin/httpd -DFOREGROUND
├─1756 /usr/sbin/httpd -DFOREGROUND
├─1757 /usr/sbin/httpd -DFOREGROUND
├─1758 /usr/sbin/httpd -DFOREGROUND
└─1759 /usr/sbin/httpd -DFOREGROUND
3月 12 21:29:11 localhost.localdomain systemd[1]: Starting The Apache HTTP Server…
3月 12 21:29:11 localhost.localdomain httpd[1752]: AH00558: httpd: Could not reliably determine the server’s fully qualifie…essage
3月 12 21:29:11 localhost.localdomain systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full. -
web访问
因为已经关闭了防火墙,所以可以直接web访问了,在浏览器中输入本机ip,出现下图,则成功。
二 安装mysql
-
安装mysql
(因为MySQL 被Oracle收购了,MySQL具有被闭源的风险,于是MySQL开发者基于MySQL分支新建了mariadb,现在新的开源Linux 用的基本上都是mariadb。两者使用方法相同)[root@localhost ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel
-
开启mysql
[root@localhost ~]# service mariadb start
Redirecting to /bin/systemctl start mariadb.service -
开机启动
[root@localhost ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service. -
检查服务
[root@localhost ~]# service mariadb status
Redirecting to /bin/systemctl status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 二 2019-03-12 22:00:33 CST; 2min 57s ago
Main PID: 2397 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─2397 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─2559 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/va…
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: MySQL manual for more instructions.
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: Please report any problems at http://mariadb.org/jira
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: The latest information about MariaDB is available at http…rg/.
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: You can find additional information about the MySQL part at:
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: http://dev.mysql.com
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: Consider joining MariaDB’s strong and vibrant community:
3月 12 22:00:31 localhost.localdomain mariadb-prepare-db-dir[2318]: https://mariadb.org/get-involved/
3月 12 22:00:31 localhost.localdomain mysqld_safe[2397]: 190312 22:00:31 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log’.
3月 12 22:00:31 localhost.localdomain mysqld_safe[2397]: 190312 22:00:31 mysqld_safe Starting mysqld daemon with databases f…mysql
3月 12 22:00:33 localhost.localdomain systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.[root@localhost ~]# netstat -tulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 2559/mysqld -
mysql设置
中间会设置密码[root@localhost ~]# 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.
Set root password? [Y/n] y
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
… 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] y
… 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] y
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] y
… 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! -
登录mysql
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.60-MariaDB MariaDB Serve
Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
MariaDB [(none)]> show databases;
±-------------------+
| Database |
±-------------------+
| information_schema |
| mysql |
| performance_schema |
±-------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye
-
三 安装php
-
安装php
[root@localhost ~]# yum -y install php
-
将php和mysql关联起来
[root@localhost ~]# yum install php-mysqll
-
安装php常用模块
[root@localhost ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath
-
测试php
按下输出,在指定位置创建文件info.php[root@localhost html]# pwd
/var/www/html
[root@localhost html]# ls
info.php
[root@localhost html]# cat info.php
<?php
phpinfo();
?>
[root@localhost html]#重启服务
[root@localhost html]# service httpd restart
Redirecting to /bin/systemctl restart httpd.service浏览器测试,输入http://192.168.11.12/info.php(替换成本机ip),出现下图则成功。