Recently, I am preparing to install roundcube. I need to build a LAMP runtime environment and search for it from the Internet. I have a lot of information. I installed it step by step and sorted out the process.
LAMP is the abbreviation of Linux, Apache, MySQL, and PHP. It is to install a website server with PHP5 and Mysql supporting Apache on a CentOS5.3 server.
1. Suppose you already have a server installed with Linux, which can enable CentOS5.3 or Ubuntu 9.04. This is an example using CentOS5.3.
2. Install Apache2
Generally, Apache2 is included in the CentOS package. You can install Apache2 by default. Of course, you can use the following command to install it easily:
Yum install httpd
The system prompts the version to be installed and automatically installs it. If any version is updated, the system displays the version to be updated.
If the installation is complete, the following information is displayed:
Package httpd-2.2.3-22.el5.centos.2.i386 already installed and latest version
Nothing to do
After installing Apache, you can start:
/Etc/init. d/httpd start
You can view the running status:
/Etc/init. d/httpd status
Httpd is running...
Now you can open http: // localhost or http: // 127.0.0.1 in the browser to see the Apache 2 Test Page.
Modify the configuration file:
Nano/etc/httpd/conf/httpd. conf
You can modify the listening port 80> 8080:
# Listen 12.34.56.78: 80
Listen 8080.
You can restart the service:
/Etc/init. d/httpd restart
Next, let's take a look at the structure of apache2, which helps us to configure the application:
/Etc/httpd/conf/httpd. conf: The main configuration file;
/Etc/httpd/conf. d /*. conf: This is a feature of CentOS. If you do not want to modify the original configuration file httpd. conf, other configurations are configured independently here. When apache is started, this file will be read into the main configuration file;
/Usr/lib/httpd/modules: apache supports many modules. The modules you want to use are stored in this directory by default;
/Var/www/html: the default "Homepage" Directory of CentOS;
/Var/www/error: the default system error message. If the host is set incorrectly or the data requested by the browser is incorrect, the error message displayed in the browser is based on the information here;
/Var/www/icons: provides some small icons of apache;
/Var/www/cgi-bin: The Directory of some executable CGI programs by default;
/Var/log/httpd: directory of log files. The files here are easy to increase and sufficient space is required;
/Usr/sbin/apachectl: This is the main execution file of Apache. The execution file is actually a shell script, which can actively detect some settings on the system, this makes Apache startup easier;
/Usr/sbin/httpd: This is the main apache binary file;
/Usr/bin/htpasswd: When you want to log on to some web pages, you need to enter your account and password. Apache itself provides the most basic password protection method. This command is used to generate the password. 3. Install MySQL5.0
At present, the official MySQL website version has reached 5.1.39, And the CentOS binding version is still 5.0. It still feels stable with a lower version.
Run the following command to install MySQl:
Yum install mysql-server
Then start the MySQL server:
/Etc/init. d/mysqld start
Run the following command to set a password for the root user (otherwise, anyone can access your MySQL database !) :
Mysqladmin-u root-p password bianjie1234
Enter password: Generally, the initial password is empty.
If the initial password is not blank or has forgotten the password, you can reset the password of the root user using the following methods:
/Etc/init. d/mysqld stop
Stopping MySQL: [OK]
Mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking &
[1] 16356
Starting mysqld daemon with databases from/var/lib/mysql
Reset the root user password:
Mysql-u root mysql
Mysql> update user set password = password (bianjie1234) where user = root;
Mysql> flush privileges;
Mysql> quit
Bye
In this way, your root user password has been successfully reset, then the security mode is stopped, and MySQL is restarted normally:
/Etc/init. d/mysqld stop
STOPPING server from pid file/var/run/mysqld. pid
091015 16:57:28 mysqld ended
Stopping MySQL: [OK]
[1] + Done mysqld_safe -- user = mysql -- skip-grant-tables -- skip-networking
/Etc/init. d/mysqld start
To set a new password for the root user, run the following command:
Mysqladmin-u root-p password bianjie1234 (new password)
Enter password: Enter the password
Operate MySQL
Mysql-u root-p
Enter password: Enter the password
Welcome to the MySQL monitor...
...
Server version: 5.0.77...
...
Mysql>
MySQL has several important directories and files:
/Etc/my. cnf: This is the Mysql configuration file, including mysql database optimization;
/Usr/lib/mysql: the directory where the MySQL database is stored. Make sure that the directory is completely backed up during Backup.
4. Install PHP5
Run the following commands to install the PHP5 and Apache PHP5 modules:
Yum install php
Then you must restart Apache:
/Etc/init. d/httpd restart
This installation is relatively simple. You can test it after installation. The default document path of the Apache website is/var/www/html. Create a simple file info in this directory. php, and call http: // localhost/info in the browser. php will display a lot of PHP5 installation information.
Nano/var/www/html/info. php
<? Php
Phpinfo ();
?>
PHP5 is working. You will see that many modules can be used in PHP5, and MySQL is not listed here, which means PHP5 does not support MySQL, you also need to install the php-mysql package.
5. Make PHP5 support MySQL
Yum search ph
Select the required installation package and run the following command to install them:
Yum install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc
Yum install php-mysql
Then restart Apache2:
/Etc/init. d/httpd restart
Reload the http: // localhost/info. php page in the browser, and you will see the newly installed MySQL module.
6. Set startup for Apache2 and MySQL
Chkconfig -- levels 3 httpd on
Chkconfig -- list httpd
Httpd 0: off 1: off 2: off 3: on 4: off 5: off 6: off
Chkconfig -- levels 3 mysqld on
Chkconfig -- list mysqld
Mysqld 0: off 1: off 2: off 3: on 4: off 5: off 6: off
Okay. a lamp server is built!