Home » Categories » VPS » VPS Linux

Hướng dẫn cài đặt LAMP (Linux, Apache, MySQL, PHP) trên CentOS 6

Do đã xuất hiện từ lâu nên LAMP (viết tắt của Linux, Apache, MySQL, và PHP) được dùng rất phổ biến trên thế giới.

Các bước cài đặt LAMP trên CentOS

Đầu tiên bạn cần chuẩn bị một server CentOS mới tinh chưa cài gì cả, ở đây mình dùng CentOS 6.4 64bit. Trước khi thao tác bạn cần phải đổi lại hostname và chỉnh sửa file host.

1. Cài đặt Apache

yum install httpd

Đường dẫn file cấu hình Apache:

/etc/httpd/conf/httpd.conf

Khởi động Apache

service httpd start

Test thử bằng cách truy cập vào http://<youraddress> bạn sẽ thấy thông báo “Apache 2 Test Page”

Lưu ý: bạn có thể cần phải stop iptables nhé

service iptables stop

kết quả:

Cấu hình Apache Virtual Hosts

– Tạo một file cấu hình ở thư mục /etc/httpd/conf.d, đặt tên ví dụ example.com.conf (thay bằng domain của bạn)

Nội dung file /etc/httpd/conf.d/example.com.conf

NameVirtualHost *:80

<VirtualHost *:80> 
     ServerAdmin webmaster@example.com
     ServerName example.com
     ServerAlias www.example.com
     DocumentRoot /var/www/example.com/public_html/
     ErrorLog /var/www/example.com/logs/error.log 
     CustomLog /var/www/example.com/logs/access.log combined
</VirtualHost>

– Tạo thư mục cho website

mkdir -p /var/www/example.com/public_html
mkdir /var/www/example.com/logs

– Nếu muốn thêm website, bạn chỉ cần tạo thêm một file .conf khác và reload lại Apache với lệnh: service httpd reload

2. Cài đặt MySQL

yum install mysql-server
service mysqld start

Tiến hành cài đặt MySQL bằng lệnh

/usr/bin/mysql_secure_installation

Do mới cài đặt nên nếu bị hỏi password bạn nhấn Enter

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Sau đó cần đặt root password bằng cách chọn y

Tiếp theo bạn sẽ phải trả lời một loạt các câu hỏi, tốt nhất cứ chọn y

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.

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, 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.

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 MySQL
installation should now be secure.

Thanks for using MySQL!

3. Cài đặt PHP

yum install php php-mysql

PHP Modules

PHP có rất nhiều thư viện module khác nhau, bạn có thể xem bằng cách gõ lệnh sau

yum search php-
php-bcmath.x86_64 : A module for PHP applications for using the bcmath library
php-cli.x86_64 : Command-line interface for PHP
php-common.x86_64 : Common files for PHP
php-dba.x86_64 : A database abstraction layer module for PHP applications
php-devel.x86_64 : Files needed for building PHP extensions
php-embedded.x86_64 : PHP library for embedding in applications
php-enchant.x86_64 : Human Language and Character Encoding Support
php-gd.x86_64 : A module for PHP applications for using the gd graphics library
php-imap.x86_64 : A module for PHP applications that use IMAP

Để cài module nào dùng lệnh sau

yum install name of the module

4. Tự động chạy service khi reboot

chkconfig httpd on
chkconfig mysqld on

Restart Apache

service httpd restart

OK vậy là quá trình cài đặt LAMP trên CentOS vậy là xong.

Xem thêm:

Cài đặt và bảo mật phpMyAdmin trên CentOS

Attachments Attachments
There are no attachments for this article.
Comments Comments
There are no comments for this article. Be the first to post a comment.
Related Articles RSS Feed
Cài đặt FTP Server đơn giản trên CentOS với ProFTPD
Xem 2751 - Đăng ngày Sat, Feb 27, 2016
Cài đặt và bảo mật phpMyAdmin trên CentOS
Xem 1495 - Đăng ngày Fri, Feb 26, 2016
Thủ thuật tối ưu LAMP server qua htaccess
Xem 690 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn cài DirectAdmin Nulled mới nhất 2020
Xem 5658 - Đăng ngày Thu, Jul 2, 2020
Kích hoạt thư viện hỗ trợ hình ảnh GD trên CentOS
Xem 1043 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn update Curl 7.29 lên bản mới nhất - Upgrade curl to latest on CentOS 7
Xem 1326 - Đăng ngày Wed, Apr 8, 2020
Thay đổi Timezone trên CentOS theo đúng múi giờ Việt Nam
Xem 797 - Đăng ngày Thu, Aug 11, 2016
Hướng dẫn kích hoạt Apache mod_rewrite trên CentOS
Xem 2378 - Đăng ngày Fri, Feb 26, 2016
Hướng dẫn kết nối sFTP bằng FileZilla
Xem 2907 - Đăng ngày Sat, Feb 27, 2016
Cài đặt EPEL và REMI Repo trên CentOS 7/6/5
Xem 1205 - Đăng ngày Sat, Feb 27, 2016