Hướng dẫn cài đặt LAMP trên CentOS 7

Trong hướng dẫn này mình sẽ hướng dẫn cách cài đặt máy chủ web Apache2 trên CentOS 7 với PHP5 và MySQL. LAMP - viết tắt của Linux, Apache, MySQL, PHP
1. Cài đặt MySQL / MariaDB
MariaDB là một nhánh của MySQL( một trong những CSDL phổ biến trên thế giới ), là máy chủ cơ sở dữ liệu cung cấp các chức năng thay thế cho MySQL. MariaDB được xây dựng bởi một số tác giả sáng lập ra MySQL được sự hỗ trợ của đông đảo cộng đồng các nhà phát triển phần mềm mã nguồn mở. Ngoài việc kế thừa các chức năng cốt lõi của MySQL, MariaDB cung cấp thêm nhiều tính năng cải tiến về cơ chế lưu trữ, tối ưu máy chủ. Để cài đặt MariaDB ta chạy lệnh sau
yum -y install mariadb-server mariadb
Để MariaDB khởi động cùng hệ thống ta chạy lệnh sau:
systemctl start mariadb.service
systemctl enable mariadb.service
Đặt mật khẩu cho tài khoản root của MySQL:
mysql_secure_installation
[root@server1 ~]# mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client:
command not found

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): <--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]
New password: <--yourmariadbpassword
Re-enter new password: <--yourmariadbpassword
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] <--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] <--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] <--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] <--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!
[root@server1 ~]#
2. Cài đặt Apache2
Để cài đặt Apache2 ta chạy lệnh sau:
yum -y install httpd
[root@server1 ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: ftp.plusline.de
* extras: mirror.23media.de
* updates: mirror.23media.de
Package httpd-2.4.6-17.el7.centos.1.x86_64 already installed and latest version
Nothing to do
[root@server1 ~]#
Khởi động Apache2
systemctl start httpd.service
systemctl enable httpd.service
CentOS 7.0 sử dụng Firewall-cmd, do đó ta sẽ cấu hình nó để cho phép truy từ bên ngoài đến cổng 80(http) và 443(https).
firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload

apache.png
3. Cài đặt PHP5
Để cài đặt PHP5 ta chạy lệnh sau:
yum -y install php
Sau khi cài đặt xong php, ta khởi động lại Apache:
systemctl restart httpd.service
Kiểm tra hoạt động: sử dụng trình soạn thảo vi tạo file info.php nằm trong thư mục var/www/html/info.php
vi /var/www/html/info.php
Nội dung file info.php
<?php
phpinfo();
?>

php_info.png
4. Cài đặt PHP5 modules
Để hỗ trợ MySQL trong PHP, ta có thể cài đặt gói php-mysql:
yum -y install php-mysql
Sau khi cài đặt xong php-mysql, ta khởi động lại Apache:
systemctl restart httpd.service

php_mysql.png
5. Cài đặt phpMyAdmin
PhpMyAdmin là một giao diện web thông qua đó bạn có thể quản lý cơ sở dữ liệu MySQL của bạn.
Để cài đặt PhpMyAdmin ta chạy lệnh sau:
yum install phpMyAdmin
Tiếp theo, cấu hình PhpMyAdmin để cho phép kết nối từ xa bằng cách chỉnh sửa tệp phpMyAdmin.conf , nằm trên thư mục Apache conf.d
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin

#<Directory /usr/share/phpMyAdmin/>
# <IfModule mod_authz_core.c>
# # Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
# </IfModule>
# <IfModule !mod_authz_core.c>
# # Apache 2.2
# Order Deny,Allow
# Deny from All
# Allow from 127.0.0.1
# Allow from ::1
# </IfModule>
#</Directory>

<Directory /usr/share/phpMyAdmin/>
Options none
AllowOverride Limit
Require all granted
</Directory>

[...]
Sau khi cấu hình xong PhpMyAdmin, ta khởi động lại Apache:
systemctl restart httpd.service

phpmyadmin.png






Xem chi tiết hơn vui lòng đến với: laedaily.com/huong-dan-cai-dat-lamp-tren-centos-7.html
Copyright © 2017 - Laedaily.com
 
  • Chủ đề
    apache lamp linux php phpmyadmin
  • Top