A project completed two weeks ago is a website written in Python. Some problems were encountered when deploying the server to the official server, which were repeated many times, wasting some time. Today, we finally have time to sort out the process.
The server operating system is centos.
I. Preparations
1. Install GCC.
If GCC is not available, the system will prompt no acceptable compiler in $ path when compiling and installing other things later.
Run Yum install GCC on the terminal.
Yum is a command under python. Generally, Linux has Python 2.4.3, so you can use the yum command as soon as you log on to the system.
2. Install zlib-devel.
If zlib-devel is not available, the following error will be reported during Python execution: compression requires the (missing) zlib module. If zlib-devel is installed at that time, Python needs to be re-compiled, it will be a little troublesome.
Run Yum install zlib-devel on the terminal.
Ii. Compile and install Python
1, to the python official website to download the source package, such as Python-2.7.3.tgz
2. Unzip the tar-XF Python-2.7.3.tgz
3. Go to the decompressed Python-2.7.3 directory and execute./configure -- prefix =/usr/local/python27 -- enable-shared -- With-zlib =/usr/include
The prefix parameter specifies the directory to which python is installed.
Enable-shared must be written. Otherwise, an error will be prompted: Command failed with rc = 65536.
With-zlib is the zlib path used to compile python. After zlib is installed in preparation, zlib will be in the/usr/include directory.
4. Execute make
5. Execute make install
Now let's check whether the Python version is 2.4.3 after you enter python on the terminal. This is because the system points to the python originally on the machine by default. Now we need to set the environment variable to point it to the newly installed python2.7.
Exit () to exit the python environment and return to the terminal. Run again
Export pythonpath =/usr/local/python27
Then execute Python and you will see that the version has changed to 2.7.
If an error occurs: Error: Command 'gcc 'failed with exit status 1
Run Yum install GCC Python-devel to solve the problem.
If an error occurs: Python: Error while loading shared libraries: libpython2.7.so. 1.0:
Cannot open shared object file: no such file
Solve the problem as follows:
Vim/etc/lD. So. conf. d/python2.7.conf
Add the following content:/usr/local/python27/lib (the lib directory in the actual Python installation path)
Save and exit and run:
Ldconfig
You can.
3. Install setuptools
Setuptools can help us easily install the python plug-in used in the project. In addition, if mysqldb plug-in is used in the project, setuptools must be installed because mysqldb depends on it.
Download the source code package of setup tools from the official website, decompress the package, go to the decompressed directory, and run Python setup. py install on the terminal.
4. Install MySQL
Download the MySQL for Redhat compressed package from the official website. Unzip the package and there are several files in it. Install the package except test.
Tar-XF mysqlxxx.tar
Rpm-IVH Mysql-server-XXX.rpm
Rpm-IVH Mysql-devel-XXX.rpm
Rpm-IVH Mysql-client-XXX.rpm
Rpm-IVH Mysql-embedded-XXX.rpm
5. Install the python plug-in required by the project
We have installed setuptools before, so we can easily install it using the following command.
Easy_install web. py
Easy_install mysql-Python
Easy_install jinja2
Plug-ins
6. install Apache
Download the source code from the official website and execute./configure -- prefix =/usr/local/Apache, make, and make install commands in sequence.
7. Install wsgi
Similarly, download the source code from the official website and then compile and install it.
After the installation is complete, a mod_wsgi.so file will be added under the modules directory of Apache.
If the installation fails, you may need to check the README file in the wsgi Directory, which provides instructions on the parameters to be specified during compilation.
8. Configure Apache
Place the project in any location on the machine, such as project test, to/usr/local/www/test
Open the configuration file,
VI/usr/local/Apache/CONF/httpd. conf file
Search for the location of loadmodule and add
Loadmodule wsgi_module modules/mod_wsgi.so
Search for DocumentRoot and change its value to a real project path, such as/usr/local/www/test.
And add the following content
Alias/robots.txt '/usr/local/www/test/static/robots.txt'
Alias/favicon. ICO '/usr/local/www/test/static/favicon. ICO'
Alias/static/'/usr/local/www/test/static /'
Wsgiprocessgroup Test
Wsgidaemonprocess inspect processes = 20 threads = 1 inactivity-Timeout = 30 maximum-Requests = 2000 Python-Eggs =/tmp display-name = % {group}
Wsgiapplicationgroup Test
Wsgiscriptalias/'/usr/local/www/test/application. py' # change it to the actual project Startup File.
<Directory '/usr/local/www/test ">
Order deny, allow
Allow from all
</Directory>
9. Start MySQL and Apache
Service MySQL start
/Usr/local/Apache/httpd-K start
Previously, I used the following method to start Apache.
Service httpd start or (/usr/local/Apache/bin/apachectl start)
You can.