Tulisan saya kali ini akan membahas mengenai instalasi paket
web server yaitu Apache, Mysql dan PHP di Centos 6. Cara instalasi menggunakan
terminal atau command line. Tidak sulit dan mudah untuk dimengerti namun akan
lebih baik sambil di lakukan.
Tahapan instalasi dibagi menjadi 4 bagian yaitu :
Apache2 beserta konfigurasi
Mysql
PHP
Melakukan pengetesan dari 3 point diatas
Perintah diatas akan melakukan instalasi paket http beserta
dependensinya.
Setelah instalasi selesai buka file yang berada di direktori:
/etc/httpd/conf/httpd.conf
dan cari tulisan #ServerName www.example.com:80
Sesuaikan dengan server yang kalian gunakan. Pada server development saya ubah menjadi:
ServerName localhost:80
Ingat ya! tanda pagar "#" yang ada di depan tulisan ServerName dihapus. Setelah itu simpan file dan aktifkan service nya dengan perintah:
[root@centos ~]# service httpd start
Agar selalu aktif saat server menyala tambahkan perintah:
[root@centos ~]# chkconfig httpd on
Sekarang kamu sudah selesai instalasi Apache. Untuk mengeceknya bukalah web browser dan ketikkan http://localhost maka akan tampil seperti Gambar.1 dibawah ini.
2. Instalasi MySQL
Ketik perintah berikut untuk instalasi MySQL beserta
dependesinya:
[root@centos ~]# yum install mysql-server
Setelah itu aktifkan service MySQL:
[root@centos ~]# service mysqld start
Ketik perintah berikut agar saat server menyala service
MySQL langsung aktif:
[root@centos ~]# chkconfig mysqld on
Buat root password untuk Mysql yang telah dibuat:
[root@centos ~]# mysqladmin -u root password
'ketikpasswordmudisini'
Tes masuk ke MySQL dengan login sebagai root
[root@centos ~]# mysql -u root -p ( press enter )
Enter password:(Masukkan password mu dan kemudian tekan enter)
Enter password:(Masukkan password mu dan kemudian tekan enter)
Sekarang kamu dapat menggunakan MySQL:
[root@centos ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.1.61 Source distribution
Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
3. Instalasi PHP
Install paket PHP untuk MySQL
[root@centos ~]# yum install php php-mysql
Setelah terinstall buatlah sebuah file phpinfo.php untuk
mengetahui konfigurasi php yang telah tersedia.
Menujulah ke folder /var/www/html/ buat file phpinfo.php yang
berisi:
<?php
phpinfo();
?>
Kemudian Restart Apache dengan perintah:
[root@centos ~]# service httpd restart
Lalu buka kembali web browser dan ketikkan http://localhost/phpinfo.php maka
akan tampil seperti Gambar.2 berikut :
Geser atau scroll lah ke bawa nanti akan tampil konfigurasi
dari MySQL.
4. Tes semua paket yang telah di Install
Tes yang akan kita lakukan adalah menghubungkan PHP dan
MySQL dengan cara membuat sebuah file text php yang berisi:
<?php
$con =
mysql_connect("localhost","root","masukkan password mu
disini");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
else
{
echo "Congrats! connection established
successfully";
}
mysql_close($con);
?>
Simpan dengan nama tesdb.php dan letakkan file di direktori /var/www/html/
Lalu buka web browser mu dan lihat hasilnya
Sudah berhasil !!
Jika kamu dapat error berikut:
Could not connect: Can’t connect to local MySQL server through
socket ‘/var/lib/mysql/mysql.sock’ (2)
itu artinya service MySQL tidak aktif. Aktifkan dengan
perintah:
[root@centos ~]# service mysqld start
Jika,
Could not connect: Access denied for user ‘root’@'localhost’
(using password: YES)
itu artinya ada kesalahan penulisan di tesdb.php. Coba
cek kembali user dan password yang kamu ketikkan apakah sudah sama dengan
konfigurasi yang kamu buat.
Jika sudah paham, Selamat mencoba :)



Tidak ada komentar:
Posting Komentar