Hướng dẫn cài đặt LEMP trên CentOS 6.x
Bước 1: Cài đặt yum cho CentOS 6.x mới nhất# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*
# yum -y install epel-releaseBước 2: Cài đặt MySQL/MariaDB
- Cài đặt MySQL theo lệnh
# yum -y install mysql mysql-server- Cấu hình dịch vụ MySQL tự khởi động
# chkconfig --levels 235 mysqld on- Khởi động dịch vụ MySQL
# service mysqld start hoặc lệnh #/etc/init.d/mysqld restart- Cấu hình mật khẩu MySQL
# /usr/bin/mysql_secure_installationNhập cấu hình như sau:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
password for the root user. If you've just installed MySQL, 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...
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
root user without the proper authorisation.
Set root password? [Y/n] <-- ENTER
New password: <-- Nhập mật khẩu
Re-enter new password: <-- Nhập lại mật khẩu
Password updated successfully!
Reloading privilege tables..
... Success!
New password: <-- Nhập mật khẩu
Re-enter new password: <-- Nhập lại mật khẩu
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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.
to log into MySQL 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!
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] <-- ENTER
... Success!
... Success!
By default, MySQL 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.
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!
- 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.
will take effect immediately.
Reload privilege tables now? [Y/n] <-- ENTER
... Success!
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
installation should now be secure.
Thanks for using MySQL!
Truy cập kiểm tra# mysql -u root -pBước 3: Cài đặt Nginx, PHP
- Cài đặt Nginx theo lệnh sau:
rpm -Uvh http://rpms.remirepo.net/enterprise/remi-release-6.rpm yum -y install yum-utils yum-config-manager --enable remi-phpxxPHP 5.3
# yum install -y nginx php-fpm php-common* PHP 5.4
# yum-config-manager --enable remi-php54* PHP 5.5
# yum-config-manager --enable remi-php55* PHP 5.6
# yum-config-manager --enable remi-php56* PHP 7.0
# yum-config-manager --enable remi-php70* PHP 7.1
# yum-config-manager --enable remi-php71- Cài đặt Nginx, PHP-FPM
# yum install -y nginx php-fpm php- Tắt dịch vụ Apache
# service httpd stop # chkconfig httpd off- Khởi động dịch vụ Nginx
# service nginx start hoặc # /etc/init.d/nginx start- Cấu hình Nginx tự khởi động cùng hệ thống
# chkconfig nginx on hoặc # chkconfig --levels 235 nginx on- Cho phép Nginx chạy qua firewall và iptables
vi /etc/sysconfig/iptables
# -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT - Khởi động dịch vụ iptables/firewall# service iptables restart- Truy cập kiểm tra http://your_ip_server hoặc http://your_domain
Bước 4: Cài đặt Module PHP# yum install -y php php-opcachephp-pecl-apcu php-cli php-pear php-pdo php-mysqlnd php-pgsqlphp-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstringphp-gd php-mbstring php-mcrypt php-xml php-soap curl curl-develphp-intl php-mysqlBước 5: Cấu hình Nginx và PHP-FPM# vi /etc/php.ini- Chỉnh dòng như sau: cgi.fix_pathinfo=0 date.timezone = Asia/Ho_Chi_Minh - Cấu hình PHP-FPM#vi /etc/php-fpm.d/www.confuser = nginx group = nginx - Khởi động lại dịch vụ PHP-FPM# service php-fpm restart # chkconfig php-fpm on- Cấu hình virtual hosts Nginx# vi /etc/nginx/conf.d/default.conf# # The default server # server { listen 80; server_name localhost;# Tên server của bạn location / { root /usr/share/nginx/html; # Nơi chứa thông tin website index index.php index.html index.htm; try_files $uri $uri/ /index.php?q=$uri&$args; } error_page 404 /404.html; location = /404.html { root /usr/share/nginx/html; } error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }- Khởi động dịch vụ Nginx# service nginx restartBước 6: Kiểm tra hoạt động Khởi tạo file PHP # vi /usr/share/nginx/html/info.php<?php phpinfo(); ?>Khởi động Nginx# service nginx restartTruy cập link http://your_ip_address/info.php hoặc http://your_ip_address/info.php
- Cài đặt phpMyAdmin
PHP 5.3
# yum install -y phpMyAdmin* PHP 5.4
yum install -y phpMyAdmin* PHP 5.5
yum install -y phpMyAdmin* PHP 5.6
yum install -y phpMyAdminĐối với PHP 7.0 và PHP 7.x xem tại đây
- Cấu hình phpMyAdmin
# ln -s /usr/share/phpMyAdmin /usr/share/nginx/html/
# vi /etc/php.inisession.save_path = "/var/lib/php/session/"
# chown -R nginx:nginx /var/lib/php/session/- Khởi động dịch vụ
# service php-fpm restart # service nginx restartTruy cập link http://your_ip_address/phpmyadmin/ hoặc http://your_ip_address/phpmyadmin/
Xem thêm video
Chúc bạn thành công !
No comments: