L.A.M.P
Installation Note
--- CentOS 6.5
William.L
wiliwe@gmail.com
2014-05-02
(2014-07-18 updated)
Index
CentOS Envrionment Setup...............................................................................................
PHP – How to View PHP Source Codes in Web Page...............................................................................
L.A.M.P Architecture
A kind of software bundle.
The acronym LAMP refers to first letters of the four components of a solut...
http://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/LAMPP_Architecture.png/450px-LAMPP_Architecture.png
CentOS Envrionment Setup
Check the version number of CentOS:
$ cat /etc/centos-release
Add EPEL(Extra Package for Enterpri...
Show Services be started on System Boot
$ chkconfig --list
Disable SELinux (Security-Enhanced Linux)
If SELinux makes for ...
(3) Reboot your machine
[root]# shutdown -r now
Apache 2 (2.2)
Apache2 is available as a CentOS package, therefore we can install it like this:
[root] # yum install httpd...
Apache's default document root is /var/www/html on CentOS, and the configuration file is
/etc/httpd/conf/httpd.conf. Addit...
[Root Cause]
The reason is that Apache allowing only specified http port numbers, and the one you have given is not in tha...
(3) Check installed semanage tool.
(4) Show current granted port numbers for Apach(http).
$ su
# semanage port -l|grep htt...
(6) Connect to http://localhost:8888 in web browser
Static File Access Forbidden (HTTP 403 Error)
From following example, ...
[Solution]
[root]# sudo chown -R $USER:$USER /var/www/folder-name
[root]# sudo chmod -R 755 /var/www
Apache Log Files
In directory /etc/httpd/logs which is symbolically linked to /var/log/httpd.
There have two log files:
* ...
access or error messages.
The files’path is relative to “/etc/httpd”
MySQL 5
To install MySQL, we do this:
[root] # yum install -y --enablerepo=remi,remi-test mysql mysql-server phpmyadmin
Th...
$ mysqladmin version
Show Current Databases
MySQL Configuration File
/etc/my.cnf
MySQL Log File
/var/log/mysqld.log
Verify PhpMyAdmin
In web browser, connect http://localhost:YourPortNum/phpmyadmin/
Enable phpMyAdmin Remote Access
In phpMyAdmin’s configuration file, phpMyAdmin.conf, is in folder “/etc/httpd/conf.d/”.
In...
PHP 5
Install PHP5 and the Apache PHP5 module as follows:
[root] # yum install -y --enablerepo=remi,remi-test php php-comm...
PHP Configuration Files
Configure PHP
(1) Increase PHP script memory limit
In the /etc/php.ini file replace memory_limit =...
As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If
you scro...
[root] # yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm
phpMyAdmin can...
To use error_log(), put the function as below snapshot.
After run the PHP web page including error_log() function, it coul...
Log MySQL Debugging Message
In “[mysql]” section of /etc/php.ini, set key “mysql.trace_mode” to “On”, it could.
Following ...
“Permission denied” Error when Uploading Files- PHP
move_uploaded_file()
When doing HTTP upload file operation and move th...
Error Happened When Missing “php” in Escape Mark <??>
When writing PHP codes, if it forget to add “php” in escape mark <??...
Navicat Database Administration Tool
Official Site - http://www.navicat.com/cht/download/navicat-premium?gclid=CI-c46Whlr4...
3. Right click the the opened database and select “運行運行運行運行 SQL 檔案檔案檔案檔案” and it will open file dialog.
4. In file dialog,...
5. After importing successfully, click “關閉” button.
6. Reopen the database had done import operation.
MySQL – How to Enable Remote Access?
Or say - Enable Remote MySQL connection
$ mysql -u root -p mysql
[Solution]
Insert a ...
(3) If you do NOT check “Save to /var/lib/phpMyAdmin/save” item, phpMyAdmin will just transfer the MySQL
script(.sql) file...
(5) Click “Import(匯入匯入匯入匯入)” button to show Import form.
Choose the MySQL script file you want to use for import and click...
Use MySQL Workbench(MS-Windows) to Connect
Remote MySQL Server
Click Plus sign button to show “Setup New Connection” form....
Click “OK” button and the new connected remote MySQL server will shown as below.
PHP – How to View PHP Source Codes in Web Page
(1) Open Apache(httpd) configuration file, /etc/httpd/conf/httpd.conf
(2) A...
L.A.M.P Installation Note --- CentOS 6.5
Upcoming SlideShare
Loading in …5
×

L.A.M.P Installation Note --- CentOS 6.5

3,600 views

Published on

Note of LAMP software bundle installation.
Linux distro - CentOS 6.5

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
3,600
On SlideShare
0
From Embeds
0
Number of Embeds
31
Actions
Shares
0
Downloads
86
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

L.A.M.P Installation Note --- CentOS 6.5

  1. 1. L.A.M.P Installation Note --- CentOS 6.5 William.L wiliwe@gmail.com 2014-05-02 (2014-07-18 updated)
  2. 2. Index CentOS Envrionment Setup........................................................................................................................................................ 6 Show Services be started on System Boot............................................................................................................................. 7 Disable SELinux (Security-Enhanced Linux) ........................................................................................................................... 7 Apache 2 (2.2)............................................................................................................................................................................. 9 Troubleshooting Apache(httpd)........................................................................................................................................... 10 Permission denied: make_sock: could not bind to address [::]:88 (88 is web server port number)............................. 10 Static File Access Forbidden (HTTP 403 Error)................................................................................................................. 13 Apache Log Files.................................................................................................................................................................... 15 MySQL 5 .................................................................................................................................................................................... 17 MySQL Installation Path....................................................................................................................................................... 17 Show MySQL Version............................................................................................................................................................ 17 Show Current Databases...................................................................................................................................................... 18 MySQL Configuration File..................................................................................................................................................... 18 MySQL Log File...................................................................................................................................................................... 19 Verify PhpMyAdmin ............................................................................................................................................................. 19 Enable phpMyAdmin Remote Access .................................................................................................................................. 20 PHP 5......................................................................................................................................................................................... 21 PHP Configuration Files ........................................................................................................................................................ 22 Configure PHP....................................................................................................................................................................... 22 Check PHP5 Installation........................................................................................................................................................ 22 phpMyAdmin........................................................................................................................................................................ 24 Debugging Message / Error Log ........................................................................................................................................... 25 Log MySQL Debugging Message........................................................................................................................................... 27 “Permission denied” Error when Uploading Files- PHP move_uploaded_file()................................................................. 28 Configure Maximum Size of Upload File.............................................................................................................................. 28 Error Happened When Missing “php” in Escape Mark <??>............................................................................................... 29 Datetime & Timezone........................................................................................................................................................... 29 Navicat Database Administration Tool.................................................................................................................................... 30 MySQL – How to Enable Remote Access?................................................................................................................................ 33 Use MySQL Workbench(MS-Windows) to Connect Remote MySQL Server .......................................................................... 36
  3. 3. PHP – How to View PHP Source Codes in Web Page............................................................................................................... 38
  4. 4. L.A.M.P Architecture A kind of software bundle. The acronym LAMP refers to first letters of the four components of a solution stack, composed entirely of free and open-source software, suitable for building high-availability heavy-duty dynamic web sites, and capable of serving tens of thousands of requests simultaneously. http://upload.wikimedia.org/wikipedia/commons/thumb/8/82/LAMP_software_bundle.svg/600px-LAMP_software_bundle.svg.png The meaning of the LAMP acronym depends on which specific components are used as part of the actual bundle: * Linux, the operating system (i.e. not just the Linux kernel, but also glibc and some other essential components of an operating system) * Apache HTTP Server, the web server. Its daemon/service name is “httpd”. * MySQL, MariaDB or MongoDB, the database management system * PHP, Perl, or Python, the scripting languages (respectively programming languages) used for dynamic web pages and web development. Web server (Apache) and the application (written in PHP, Perl or Python) might be in the same process, but the database is always a separate process. P.S: Web server could use PHP/Perl/Python as an integrated component(in the form of Module or Plug-in running in the same memory space of web server) or a separate program (e.g CGI-way, use it by invoking interpreter(a software)), so it says “might be in the same process”.
  5. 5. http://upload.wikimedia.org/wikipedia/commons/thumb/f/fa/LAMPP_Architecture.png/450px-LAMPP_Architecture.png
  6. 6. CentOS Envrionment Setup Check the version number of CentOS: $ cat /etc/centos-release Add EPEL(Extra Package for Enterprise Linux) [root] # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm [root] # rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm Add Remi repository. The Remi repository is a repository containing updated PHP and MySQL packages and is maintained by Remi ( http://blog.famillecollet.com/pages/Config-en ). [root] # rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm Update package repository database. [root] # yum -y update List current YUM repositories. [root] # yum repolist
  7. 7. Show Services be started on System Boot $ chkconfig --list Disable SELinux (Security-Enhanced Linux) If SELinux makes for some cryptic errors when running the LAMP stack, you could follow steps to disable SELinux. (1) Open SELinux configuration file using text editor [root]# vim /etc/selinux/config (2) Change the “SELINUX=” line to “disabled” value, like so: SELINUX= disabled
  8. 8. (3) Reboot your machine [root]# shutdown -r now
  9. 9. Apache 2 (2.2) Apache2 is available as a CentOS package, therefore we can install it like this: [root] # yum install httpd Allow Apache server default port 80(or other port number you want) through your firewall/router if you want to connect from remote systems. To do that, edit file /etc/sysconfig/iptables, [root] # vi /etc/sysconfig/iptables Add the following lines. [...] -A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT [...] Restart iptables: [root] # service iptables restart Now configure your system to start Apache at boot time... [root] # chkconfig --levels 235 httpd on ... and start Apache: [root] # /etc/init.d/httpd start or [root] # service httpd start Now direct your browser to http://192.168.0.100 (or your host’s IP address), and you should see the Apache2 placeholder page:
  10. 10. Apache's default document root is /var/www/html on CentOS, and the configuration file is /etc/httpd/conf/httpd.conf. Additional configurations are stored in the /etc/httpd/conf.d/ directory. To use command to see the version of current Apache2 server $ apachectl -v or $ httpd -v Troubleshooting Apache(httpd) Permission denied: make_sock: could not bind to address [::]:88 (88 is web server port number) In Apache, this type of error occurs at the time of starting the service after editing the /etc/httpd/conf/httpd.conf file to listen to a particular port number.
  11. 11. [Root Cause] The reason is that Apache allowing only specified http port numbers, and the one you have given is not in that list. This could check by using semanage tool ( http://linux.die.net/man/8/semanage ). [Solution] Steps: (1) Search which package contains semanage tool. $ su # yum provides /usr/sbin/semanage (2) Install policycoreutils-python package. $ su # yum -y install policycoreutils-python
  12. 12. (3) Check installed semanage tool. (4) Show current granted port numbers for Apach(http). $ su # semanage port -l|grep http (4) Add wanted port numbers into granted port list for Apach (httpd). $ su # semanage port -a -t http_port_t -p tcp 8888 (5) Start Apache(httpd) again. Use netstat tool to see if Apache(httpd) binded the port number you added before. $ netstat -n -l -t -p This command means : Please show numberic(-n) listening(-l) port number of TCP(-t) protocol and show it corresponding service/process(-p)
  13. 13. (6) Connect to http://localhost:8888 in web browser Static File Access Forbidden (HTTP 403 Error) From following example, a directory index web page, index.html, includes a JavaScript library file, b28n.js,under subdirectory “lang”, e.g. /var/www/html/lang. When accessing index.html web page, it will show HTTP 403 Forbidden error message.
  14. 14. [Solution] [root]# sudo chown -R $USER:$USER /var/www/folder-name [root]# sudo chmod -R 755 /var/www
  15. 15. Apache Log Files In directory /etc/httpd/logs which is symbolically linked to /var/log/httpd. There have two log files: * access_log * error_log In Apache configuration file, /etc/httpd/conf/httpd.conf, variable “ErrorLog” denotes the file name for logging
  16. 16. access or error messages. The files’path is relative to “/etc/httpd”
  17. 17. MySQL 5 To install MySQL, we do this: [root] # yum install -y --enablerepo=remi,remi-test mysql mysql-server phpmyadmin Then we create the system startup links for MySQL (so that MySQL starts automatically whenever the system boots): [root] # chkconfig --levels 235 mysqld on and start the MySQL server: [root] # /etc/init.d/mysqld start or [root] # service mysqld start MySQL Installation Path Show MySQL Version $ mysql or
  18. 18. $ mysqladmin version Show Current Databases MySQL Configuration File /etc/my.cnf
  19. 19. MySQL Log File /var/log/mysqld.log Verify PhpMyAdmin In web browser, connect http://localhost:YourPortNum/phpmyadmin/
  20. 20. Enable phpMyAdmin Remote Access In phpMyAdmin’s configuration file, phpMyAdmin.conf, is in folder “/etc/httpd/conf.d/”. In phpMyAdmin.conf, add allowed IP addresses to access remotely.
  21. 21. PHP 5 Install PHP5 and the Apache PHP5 module as follows: [root] # yum install -y --enablerepo=remi,remi-test php php-common php-pecl-memcache php-imap php-pecl-memcached php-gd php-mbstring php-mcrypt php-xml php-pecl-apc php-cli php-pear php-pdo php-mysql ------------------------------------------------------------------------------------------------------------------------------------------------ Note: MySQL (php-mysql) – A extension for PHP applications that use MySQL databases. Memcache (php-pecl-memcache) – Memcached caching daemon. Memcached (php-pecl-memcached) – Memcached caching daemon. GD (php-gd) – GD extension for PHP application to serve graphics. XML (php-xml) – XML Parser for PHP applications. MBString (php-mbstring) – Mbstring extension is used to handle multi-byte string in PHP applications. MCrypt (php-mcrypt) – A Mcrypt library for PHP scripts. APC (php-pecl-apc) – APC module used to optimize and cache PHP code. It is a free and open PHP opcode cacher for caching and optimizing PHP intermediate code. It's similar to other PHP opcode cachers, such as eAccelerator and Xcache. It is strongly recommended to have one of these installed to speed up your PHP page. CLI (php-cli) – Command-line interface for PHP. PEAR (php-pear) – Application Repository framework for PHP. PDO (php-pdo) – Database access module for PHP applications. ------------------------------------------------------------------------------------------------------------------------------------------------ In Apache(httpd) configureation file, /etc/httpd/conf/httpd.conf, add below section for interpreting of PHP codes as following snapshot: It must restart Apache afterwards: [root] # /etc/init.d/httpd restart or [root] # service httpd restart AddType application/x-httpd-php .php .htm .html .php3
  22. 22. PHP Configuration Files Configure PHP (1) Increase PHP script memory limit In the /etc/php.ini file replace memory_limit = 16M with memory_limit = 128M (2) Increase PHP script max execution time In the /etc/php.ini file replace max_execution_time = 30 with max_execution_time = 120 (3) Increase PHP script max upload size In the /etc/php.ini file replace post_max_size = 8M with post_max_size = 50M Check PHP5 Installation The document root of the default web site is /var/www/html. We will now create a small PHP file (info.php) in that directory and call it in a browser. The file will display lots of useful details about our PHP installation, such as the installed PHP version. $ vi /var/www/html/info.php , add Now we call that file in a browser (e.g. http://localhost/info.php): <?php phpinfo(); ?>
  23. 23. As you see, PHP5 is working, and it's working through the Apache 2.0 Handler, as shown in the Server API line. If you scroll further down, you will see all modules that are already enabled in PHP5. MySQL is not listed there which means we don't have MySQL support in PHP5 yet. To use command line to see current version of PHP $ php -v phpMyAdmin phpMyAdmin is a web interface through which you can manage your MySQL databases. First we enable the RPMforge repository on our CentOS system as phpMyAdmin is NOT available in the official CentOS 6.5 repositories. Import the RPMforge GPG key: [root] # rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt On x86_64 systems: [root] # yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm On i386 systems:
  24. 24. [root] # yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el6.rf.i686.rpm phpMyAdmin can now be installed as follows: [root] # yum -y install phpmyadmin ow we configure phpMyAdmin. We change the Apache configuration so that phpMyAdmin allows connections not just from localhost (by commenting out the <Directory "/usr/share/phpmyadmin"> stanza): [root] # vi /etc/httpd/conf.d/phpmyadmin.conf Next we change the authentication in phpMyAdmin from cookie to http: [root] # # cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php p [root] # vi /usr/share/phpmyadmin/config.inc.php Restart Apache: [root] # /etc/init.d/httpd restart Afterwards, you can access phpMyAdmin under http://192.168.0.100/phpmyadmin/. Debugging Message / Error Log Ref : http://www.w3schools.com/php/func_error_log.asp http://www.php.net/manual/en/function.error-log.php In PHP page, use “error_log(String, 0)” function to store your debugging message into Apache web server’s log file, /etc/httpd/logs/error_log. The parameter “0” means that the error is logged to web server’s error log. # # Web application to manage MySQL # #<Directory "/usr/share/phpmyadmin"> # Order Deny,Allow # Deny from all # Allow from 127.0.0.1 #</Directory> Alias /phpmyadmin /usr/share/phpmyadmin Alias /phpMyAdmin /usr/share/phpmyadmin Alias /mysqladmin /usr/share/phpmyadmin [...] /* Authentication type */ $cfg['Servers'][$i]['auth_type'] = 'http'; [...]
  25. 25. To use error_log(), put the function as below snapshot. After run the PHP web page including error_log() function, it could view messaged as below $ cat /etc/httpd/logs/error_log Other Error-Log relevant configurations in /etc/php.ini are as below:
  26. 26. Log MySQL Debugging Message In “[mysql]” section of /etc/php.ini, set key “mysql.trace_mode” to “On”, it could. Following is MySQL debugging message on PHP web page. $ cat /var/logs/httpd/logs/error_log
  27. 27. “Permission denied” Error when Uploading Files- PHP move_uploaded_file() When doing HTTP upload file operation and move the uploaded file from web server temp folder to destination folder using PHP move_uploaded_file() funtion, if it show “Permission denied” error and move_uploaded_file() will return value 0. [Solution] Change the destination folder mode to 777. For example, # chmod 777 /var/www/html/firmware Configure Maximum Size of Upload File When using PHP function move_uploaded_file() to move uploaded file to designated destination, if it return error value(-1), it might need to check the restriction of upload file’s size. In PHP configuration file /etc/php.ini, check value of variable “upload_max_filesize” and see if the size of the file to be uploaded is greater than variable’s value. Also, you could change that value to a larger one.
  28. 28. Error Happened When Missing “php” in Escape Mark <??> When writing PHP codes, if it forget to add “php” in escape mark <??> as below script(shown as below), it will generate “Unexpected token <” error as below snapshot. (This error message is shown in Google Chrome web browser’s Debugger) Datetime & Timezone Before using date() function to get formatted datetime value, it needs to set timezone for your locale. Two ways to set timezone: <Way - 1> PHP Configuration File In /etc/php.ini , find section [Date] , uncomment "date.timezone=", fill the timezone value and save file. Finally, restart Apache server by the command: $ service httpd restart < Way - 2> Use date_default_timezone_set() Function In PHP codes, before using date() function, to call function date_default_timezone_set() to set timezone. Ex: Timezones supported in PHP are list here: http://www.php.net/manual/en/timezones.php <script language=”javascript”> var id = < ? $MyID; ?> </script>
  29. 29. Navicat Database Administration Tool Official Site - http://www.navicat.com/cht/download/navicat-premium?gclid=CI-c46Whlr4CFQx9vQod774AWw Import a MySQL Database 1.Right click connected MySQL server and select “新建數據庫新建數據庫新建數據庫新建數據庫” 2.Double click new created database, here “aps_fw” for example.
  30. 30. 3. Right click the the opened database and select “運行運行運行運行 SQL 檔案檔案檔案檔案” and it will open file dialog. 4. In file dialog, navigate to the path to the MySQL file you want to run and click open
  31. 31. 5. After importing successfully, click “關閉” button. 6. Reopen the database had done import operation.
  32. 32. MySQL – How to Enable Remote Access? Or say - Enable Remote MySQL connection $ mysql -u root -p mysql [Solution] Insert a record and the value of field Host is % character which means “Any IP Address”. Steps: (1) Connect to http://localhost/phpmyadmin , select table “user“ of database “mysql” and click “Export”. (2) Click “Run(執行)” button to export.
  33. 33. (3) If you do NOT check “Save to /var/lib/phpMyAdmin/save” item, phpMyAdmin will just transfer the MySQL script(.sql) file named in table name(here is “user”) you chosen to you. (4) Open download MySQL script file with text editor and copy the SQL INSERT statement for “localhost” Host and paste to the bottom in “Export Data of Table User” section and change the value of “Host” field of the copied one to “%”.
  34. 34. (5) Click “Import(匯入匯入匯入匯入)” button to show Import form. Choose the MySQL script file you want to use for import and click “Run(執行執行執行執行)” button to import. (6) When data importing accomplished, verify the “user” table of database “mysql” that if there has a new entry/record in which “Host” value is “%”.
  35. 35. Use MySQL Workbench(MS-Windows) to Connect Remote MySQL Server Click Plus sign button to show “Setup New Connection” form. Fill in fieds: * Connection Name * Connection Method * Hostname * Port * Username * Password - click button “Store in Vault” and fill MySQL server connection password in pop-out dialog , and click “OK” button to finish. Click “Test Connection” button to check if it could connect to remote MySQL server. If it fail to connect, please verify if remote MySQL server grant remote access(as above steps) and if access accout/password are correct.
  36. 36. Click “OK” button and the new connected remote MySQL server will shown as below.
  37. 37. PHP – How to View PHP Source Codes in Web Page (1) Open Apache(httpd) configuration file, /etc/httpd/conf/httpd.conf (2) Add below section as following snapshot: (3) Do symbolic link command of a .php file to .phps as below: ln -s index.php index.phps (4) Browse the .phps web page as below snapshot. AddType application/x-httpd-php-source .phps

×